blob: fdb861eea51b63651b51e50673ba0ce639b75cb5 [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
John McCallf4b88a42012-03-10 09:33:50 +00002402 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2403 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002404 VK_LValue, BuiltinLoc));
2405 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2406 if (Callee.isInvalid())
2407 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002408
2409 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002410 unsigned NumSubExprs = SubExprs.size();
2411 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002412 ExprResult TheCall = SemaRef.Owned(
2413 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002415 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002416 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002417 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002418
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002420 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 }
John McCall43fed0d2010-11-12 08:19:04 +00002422
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002423 /// \brief Build a new template argument pack expansion.
2424 ///
2425 /// By default, performs semantic analysis to build a new pack expansion
2426 /// for a template argument. Subclasses may override this routine to provide
2427 /// different behavior.
2428 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002429 SourceLocation EllipsisLoc,
2430 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002431 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002432 case TemplateArgument::Expression: {
2433 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002434 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2435 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002436 if (Result.isInvalid())
2437 return TemplateArgumentLoc();
2438
2439 return TemplateArgumentLoc(Result.get(), Result.get());
2440 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002441
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002442 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002443 return TemplateArgumentLoc(TemplateArgument(
2444 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002445 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002446 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002447 Pattern.getTemplateNameLoc(),
2448 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002449
2450 case TemplateArgument::Null:
2451 case TemplateArgument::Integral:
2452 case TemplateArgument::Declaration:
2453 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002454 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002455 llvm_unreachable("Pack expansion pattern has no parameter packs");
2456
2457 case TemplateArgument::Type:
2458 if (TypeSourceInfo *Expansion
2459 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002460 EllipsisLoc,
2461 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002462 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2463 Expansion);
2464 break;
2465 }
2466
2467 return TemplateArgumentLoc();
2468 }
2469
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002470 /// \brief Build a new expression pack expansion.
2471 ///
2472 /// By default, performs semantic analysis to build a new pack expansion
2473 /// for an expression. Subclasses may override this routine to provide
2474 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002475 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2476 llvm::Optional<unsigned> NumExpansions) {
2477 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002478 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002479
2480 /// \brief Build a new atomic operation expression.
2481 ///
2482 /// By default, performs semantic analysis to build the new expression.
2483 /// Subclasses may override this routine to provide different behavior.
2484 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2485 MultiExprArg SubExprs,
2486 QualType RetTy,
2487 AtomicExpr::AtomicOp Op,
2488 SourceLocation RParenLoc) {
2489 // Just create the expression; there is not any interesting semantic
2490 // analysis here because we can't actually build an AtomicExpr until
2491 // we are sure it is semantically sound.
2492 unsigned NumSubExprs = SubExprs.size();
2493 Expr **Subs = (Expr **)SubExprs.release();
2494 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2495 NumSubExprs, RetTy, Op,
2496 RParenLoc);
2497 }
2498
John McCall43fed0d2010-11-12 08:19:04 +00002499private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002500 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2501 QualType ObjectType,
2502 NamedDecl *FirstQualifierInScope,
2503 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002504
2505 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2506 QualType ObjectType,
2507 NamedDecl *FirstQualifierInScope,
2508 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002509};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002510
Douglas Gregor43959a92009-08-20 07:17:43 +00002511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002512StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002513 if (!S)
2514 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002515
Douglas Gregor43959a92009-08-20 07:17:43 +00002516 switch (S->getStmtClass()) {
2517 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002518
Douglas Gregor43959a92009-08-20 07:17:43 +00002519 // Transform individual statement nodes
2520#define STMT(Node, Parent) \
2521 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002522#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002523#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002524#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002525
Douglas Gregor43959a92009-08-20 07:17:43 +00002526 // Transform expressions by calling TransformExpr.
2527#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002528#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002529#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002530#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002531 {
John McCall60d7b3a2010-08-24 06:29:42 +00002532 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002533 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002534 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002535
John McCall9ae2f072010-08-23 23:25:46 +00002536 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002537 }
Mike Stump1eb44332009-09-09 15:08:12 +00002538 }
2539
John McCall3fa5cae2010-10-26 07:05:15 +00002540 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002541}
Mike Stump1eb44332009-09-09 15:08:12 +00002542
2543
Douglas Gregor670444e2009-08-04 22:27:00 +00002544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002545ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002546 if (!E)
2547 return SemaRef.Owned(E);
2548
2549 switch (E->getStmtClass()) {
2550 case Stmt::NoStmtClass: break;
2551#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002552#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002553#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002554 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002555#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002556 }
2557
John McCall3fa5cae2010-10-26 07:05:15 +00002558 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002559}
2560
2561template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002562bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2563 unsigned NumInputs,
2564 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002565 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002566 bool *ArgChanged) {
2567 for (unsigned I = 0; I != NumInputs; ++I) {
2568 // If requested, drop call arguments that need to be dropped.
2569 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2570 if (ArgChanged)
2571 *ArgChanged = true;
2572
2573 break;
2574 }
2575
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002576 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2577 Expr *Pattern = Expansion->getPattern();
2578
Chris Lattner686775d2011-07-20 06:58:45 +00002579 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002580 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2581 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2582
2583 // Determine whether the set of unexpanded parameter packs can and should
2584 // be expanded.
2585 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002586 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002587 llvm::Optional<unsigned> OrigNumExpansions
2588 = Expansion->getNumExpansions();
2589 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002590 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2591 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002592 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002593 Expand, RetainExpansion,
2594 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002595 return true;
2596
2597 if (!Expand) {
2598 // The transform has determined that we should perform a simple
2599 // transformation on the pack expansion, producing another pack
2600 // expansion.
2601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2602 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2603 if (OutPattern.isInvalid())
2604 return true;
2605
2606 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002607 Expansion->getEllipsisLoc(),
2608 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 if (Out.isInvalid())
2610 return true;
2611
2612 if (ArgChanged)
2613 *ArgChanged = true;
2614 Outputs.push_back(Out.get());
2615 continue;
2616 }
John McCallc8fc90a2011-07-06 07:30:07 +00002617
2618 // Record right away that the argument was changed. This needs
2619 // to happen even if the array expands to nothing.
2620 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621
2622 // The transform has determined that we should perform an elementwise
2623 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002624 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002625 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2626 ExprResult Out = getDerived().TransformExpr(Pattern);
2627 if (Out.isInvalid())
2628 return true;
2629
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002630 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002631 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2632 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002633 if (Out.isInvalid())
2634 return true;
2635 }
2636
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002637 Outputs.push_back(Out.get());
2638 }
2639
2640 continue;
2641 }
2642
Douglas Gregoraa165f82011-01-03 19:04:46 +00002643 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2644 if (Result.isInvalid())
2645 return true;
2646
2647 if (Result.get() != Inputs[I] && ArgChanged)
2648 *ArgChanged = true;
2649
2650 Outputs.push_back(Result.get());
2651 }
2652
2653 return false;
2654}
2655
2656template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002657NestedNameSpecifierLoc
2658TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2659 NestedNameSpecifierLoc NNS,
2660 QualType ObjectType,
2661 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002662 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002663 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2664 Qualifier = Qualifier.getPrefix())
2665 Qualifiers.push_back(Qualifier);
2666
2667 CXXScopeSpec SS;
2668 while (!Qualifiers.empty()) {
2669 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2670 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2671
2672 switch (QNNS->getKind()) {
2673 case NestedNameSpecifier::Identifier:
2674 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2675 *QNNS->getAsIdentifier(),
2676 Q.getLocalBeginLoc(),
2677 Q.getLocalEndLoc(),
2678 ObjectType, false, SS,
2679 FirstQualifierInScope, false))
2680 return NestedNameSpecifierLoc();
2681
2682 break;
2683
2684 case NestedNameSpecifier::Namespace: {
2685 NamespaceDecl *NS
2686 = cast_or_null<NamespaceDecl>(
2687 getDerived().TransformDecl(
2688 Q.getLocalBeginLoc(),
2689 QNNS->getAsNamespace()));
2690 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2691 break;
2692 }
2693
2694 case NestedNameSpecifier::NamespaceAlias: {
2695 NamespaceAliasDecl *Alias
2696 = cast_or_null<NamespaceAliasDecl>(
2697 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2698 QNNS->getAsNamespaceAlias()));
2699 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2700 Q.getLocalEndLoc());
2701 break;
2702 }
2703
2704 case NestedNameSpecifier::Global:
2705 // There is no meaningful transformation that one could perform on the
2706 // global scope.
2707 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2708 break;
2709
2710 case NestedNameSpecifier::TypeSpecWithTemplate:
2711 case NestedNameSpecifier::TypeSpec: {
2712 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2713 FirstQualifierInScope, SS);
2714
2715 if (!TL)
2716 return NestedNameSpecifierLoc();
2717
2718 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002719 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002720 TL.getType()->isEnumeralType())) {
2721 assert(!TL.getType().hasLocalQualifiers() &&
2722 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002723 if (TL.getType()->isEnumeralType())
2724 SemaRef.Diag(TL.getBeginLoc(),
2725 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002726 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2727 Q.getLocalEndLoc());
2728 break;
2729 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002730 // If the nested-name-specifier is an invalid type def, don't emit an
2731 // error because a previous error should have already been emitted.
2732 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2733 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2734 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2735 << TL.getType() << SS.getRange();
2736 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002737 return NestedNameSpecifierLoc();
2738 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002739 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002741 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002743 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002744 }
2745
2746 // Don't rebuild the nested-name-specifier if we don't have to.
2747 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2748 !getDerived().AlwaysRebuild())
2749 return NNS;
2750
2751 // If we can re-use the source-location data from the original
2752 // nested-name-specifier, do so.
2753 if (SS.location_size() == NNS.getDataLength() &&
2754 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2755 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2756
2757 // Allocate new nested-name-specifier location information.
2758 return SS.getWithLocInContext(SemaRef.Context);
2759}
2760
2761template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002762DeclarationNameInfo
2763TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002764::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002765 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002766 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002767 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002768
2769 switch (Name.getNameKind()) {
2770 case DeclarationName::Identifier:
2771 case DeclarationName::ObjCZeroArgSelector:
2772 case DeclarationName::ObjCOneArgSelector:
2773 case DeclarationName::ObjCMultiArgSelector:
2774 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002775 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002776 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002777 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002778
Douglas Gregor81499bb2009-09-03 22:13:48 +00002779 case DeclarationName::CXXConstructorName:
2780 case DeclarationName::CXXDestructorName:
2781 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002782 TypeSourceInfo *NewTInfo;
2783 CanQualType NewCanTy;
2784 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002785 NewTInfo = getDerived().TransformType(OldTInfo);
2786 if (!NewTInfo)
2787 return DeclarationNameInfo();
2788 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002789 }
2790 else {
2791 NewTInfo = 0;
2792 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002793 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002794 if (NewT.isNull())
2795 return DeclarationNameInfo();
2796 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2797 }
Mike Stump1eb44332009-09-09 15:08:12 +00002798
Abramo Bagnara25777432010-08-11 22:01:17 +00002799 DeclarationName NewName
2800 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2801 NewCanTy);
2802 DeclarationNameInfo NewNameInfo(NameInfo);
2803 NewNameInfo.setName(NewName);
2804 NewNameInfo.setNamedTypeInfo(NewTInfo);
2805 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002806 }
Mike Stump1eb44332009-09-09 15:08:12 +00002807 }
2808
David Blaikieb219cfc2011-09-23 05:06:16 +00002809 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002810}
2811
2812template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002813TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002814TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2815 TemplateName Name,
2816 SourceLocation NameLoc,
2817 QualType ObjectType,
2818 NamedDecl *FirstQualifierInScope) {
2819 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2820 TemplateDecl *Template = QTN->getTemplateDecl();
2821 assert(Template && "qualified template name must refer to a template");
2822
2823 TemplateDecl *TransTemplate
2824 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2825 Template));
2826 if (!TransTemplate)
2827 return TemplateName();
2828
2829 if (!getDerived().AlwaysRebuild() &&
2830 SS.getScopeRep() == QTN->getQualifier() &&
2831 TransTemplate == Template)
2832 return Name;
2833
2834 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2835 TransTemplate);
2836 }
2837
2838 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2839 if (SS.getScopeRep()) {
2840 // These apply to the scope specifier, not the template.
2841 ObjectType = QualType();
2842 FirstQualifierInScope = 0;
2843 }
2844
2845 if (!getDerived().AlwaysRebuild() &&
2846 SS.getScopeRep() == DTN->getQualifier() &&
2847 ObjectType.isNull())
2848 return Name;
2849
2850 if (DTN->isIdentifier()) {
2851 return getDerived().RebuildTemplateName(SS,
2852 *DTN->getIdentifier(),
2853 NameLoc,
2854 ObjectType,
2855 FirstQualifierInScope);
2856 }
2857
2858 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2859 ObjectType);
2860 }
2861
2862 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2863 TemplateDecl *TransTemplate
2864 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2865 Template));
2866 if (!TransTemplate)
2867 return TemplateName();
2868
2869 if (!getDerived().AlwaysRebuild() &&
2870 TransTemplate == Template)
2871 return Name;
2872
2873 return TemplateName(TransTemplate);
2874 }
2875
2876 if (SubstTemplateTemplateParmPackStorage *SubstPack
2877 = Name.getAsSubstTemplateTemplateParmPack()) {
2878 TemplateTemplateParmDecl *TransParam
2879 = cast_or_null<TemplateTemplateParmDecl>(
2880 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2881 if (!TransParam)
2882 return TemplateName();
2883
2884 if (!getDerived().AlwaysRebuild() &&
2885 TransParam == SubstPack->getParameterPack())
2886 return Name;
2887
2888 return getDerived().RebuildTemplateName(TransParam,
2889 SubstPack->getArgumentPack());
2890 }
2891
2892 // These should be getting filtered out before they reach the AST.
2893 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002894}
2895
2896template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002897void TreeTransform<Derived>::InventTemplateArgumentLoc(
2898 const TemplateArgument &Arg,
2899 TemplateArgumentLoc &Output) {
2900 SourceLocation Loc = getDerived().getBaseLocation();
2901 switch (Arg.getKind()) {
2902 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002903 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002904 break;
2905
2906 case TemplateArgument::Type:
2907 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002908 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002909
John McCall833ca992009-10-29 08:12:44 +00002910 break;
2911
Douglas Gregor788cd062009-11-11 01:00:40 +00002912 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002913 case TemplateArgument::TemplateExpansion: {
2914 NestedNameSpecifierLocBuilder Builder;
2915 TemplateName Template = Arg.getAsTemplate();
2916 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2917 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2918 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2919 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2920
2921 if (Arg.getKind() == TemplateArgument::Template)
2922 Output = TemplateArgumentLoc(Arg,
2923 Builder.getWithLocInContext(SemaRef.Context),
2924 Loc);
2925 else
2926 Output = TemplateArgumentLoc(Arg,
2927 Builder.getWithLocInContext(SemaRef.Context),
2928 Loc, Loc);
2929
Douglas Gregor788cd062009-11-11 01:00:40 +00002930 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002931 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002932
John McCall833ca992009-10-29 08:12:44 +00002933 case TemplateArgument::Expression:
2934 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2935 break;
2936
2937 case TemplateArgument::Declaration:
2938 case TemplateArgument::Integral:
2939 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002940 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002941 break;
2942 }
2943}
2944
2945template<typename Derived>
2946bool TreeTransform<Derived>::TransformTemplateArgument(
2947 const TemplateArgumentLoc &Input,
2948 TemplateArgumentLoc &Output) {
2949 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002950 switch (Arg.getKind()) {
2951 case TemplateArgument::Null:
2952 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002953 Output = Input;
2954 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002955
Douglas Gregor670444e2009-08-04 22:27:00 +00002956 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002957 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002958 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002959 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002960
2961 DI = getDerived().TransformType(DI);
2962 if (!DI) return true;
2963
2964 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2965 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002966 }
Mike Stump1eb44332009-09-09 15:08:12 +00002967
Douglas Gregor670444e2009-08-04 22:27:00 +00002968 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002969 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002970 DeclarationName Name;
2971 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2972 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002973 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002974 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002975 if (!D) return true;
2976
John McCall828bff22009-10-29 18:45:58 +00002977 Expr *SourceExpr = Input.getSourceDeclExpression();
2978 if (SourceExpr) {
2979 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002980 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002981 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002982 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002983 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002984 }
2985
2986 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002987 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002988 }
Mike Stump1eb44332009-09-09 15:08:12 +00002989
Douglas Gregor788cd062009-11-11 01:00:40 +00002990 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002991 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2992 if (QualifierLoc) {
2993 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2994 if (!QualifierLoc)
2995 return true;
2996 }
2997
Douglas Gregor1d752d72011-03-02 18:46:51 +00002998 CXXScopeSpec SS;
2999 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003000 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003001 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3002 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003003 if (Template.isNull())
3004 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003005
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003006 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003007 Input.getTemplateNameLoc());
3008 return false;
3009 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003010
3011 case TemplateArgument::TemplateExpansion:
3012 llvm_unreachable("Caller should expand pack expansions");
3013
Douglas Gregor670444e2009-08-04 22:27:00 +00003014 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003015 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003016 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003017 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003018
John McCall833ca992009-10-29 08:12:44 +00003019 Expr *InputExpr = Input.getSourceExpression();
3020 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3021
Chris Lattner223de242011-04-25 20:37:58 +00003022 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003023 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003024 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003025 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003026 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003027 }
Mike Stump1eb44332009-09-09 15:08:12 +00003028
Douglas Gregor670444e2009-08-04 22:27:00 +00003029 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003030 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003031 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003032 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003033 AEnd = Arg.pack_end();
3034 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003035
John McCall833ca992009-10-29 08:12:44 +00003036 // FIXME: preserve source information here when we start
3037 // caring about parameter packs.
3038
John McCall828bff22009-10-29 18:45:58 +00003039 TemplateArgumentLoc InputArg;
3040 TemplateArgumentLoc OutputArg;
3041 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3042 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003043 return true;
3044
John McCall828bff22009-10-29 18:45:58 +00003045 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003046 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003047
3048 TemplateArgument *TransformedArgsPtr
3049 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3050 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3051 TransformedArgsPtr);
3052 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3053 TransformedArgs.size()),
3054 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003055 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 }
3057 }
Mike Stump1eb44332009-09-09 15:08:12 +00003058
Douglas Gregor670444e2009-08-04 22:27:00 +00003059 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003060 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003061}
3062
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003063/// \brief Iterator adaptor that invents template argument location information
3064/// for each of the template arguments in its underlying iterator.
3065template<typename Derived, typename InputIterator>
3066class TemplateArgumentLocInventIterator {
3067 TreeTransform<Derived> &Self;
3068 InputIterator Iter;
3069
3070public:
3071 typedef TemplateArgumentLoc value_type;
3072 typedef TemplateArgumentLoc reference;
3073 typedef typename std::iterator_traits<InputIterator>::difference_type
3074 difference_type;
3075 typedef std::input_iterator_tag iterator_category;
3076
3077 class pointer {
3078 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003079
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003080 public:
3081 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3082
3083 const TemplateArgumentLoc *operator->() const { return &Arg; }
3084 };
3085
3086 TemplateArgumentLocInventIterator() { }
3087
3088 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3089 InputIterator Iter)
3090 : Self(Self), Iter(Iter) { }
3091
3092 TemplateArgumentLocInventIterator &operator++() {
3093 ++Iter;
3094 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003095 }
3096
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003097 TemplateArgumentLocInventIterator operator++(int) {
3098 TemplateArgumentLocInventIterator Old(*this);
3099 ++(*this);
3100 return Old;
3101 }
3102
3103 reference operator*() const {
3104 TemplateArgumentLoc Result;
3105 Self.InventTemplateArgumentLoc(*Iter, Result);
3106 return Result;
3107 }
3108
3109 pointer operator->() const { return pointer(**this); }
3110
3111 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3112 const TemplateArgumentLocInventIterator &Y) {
3113 return X.Iter == Y.Iter;
3114 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3117 const TemplateArgumentLocInventIterator &Y) {
3118 return X.Iter != Y.Iter;
3119 }
3120};
3121
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003122template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003123template<typename InputIterator>
3124bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3125 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003126 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003128 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003129 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003130
3131 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3132 // Unpack argument packs, which we translate them into separate
3133 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003134 // FIXME: We could do much better if we could guarantee that the
3135 // TemplateArgumentLocInfo for the pack expansion would be usable for
3136 // all of the template arguments in the argument pack.
3137 typedef TemplateArgumentLocInventIterator<Derived,
3138 TemplateArgument::pack_iterator>
3139 PackLocIterator;
3140 if (TransformTemplateArguments(PackLocIterator(*this,
3141 In.getArgument().pack_begin()),
3142 PackLocIterator(*this,
3143 In.getArgument().pack_end()),
3144 Outputs))
3145 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003146
3147 continue;
3148 }
3149
3150 if (In.getArgument().isPackExpansion()) {
3151 // We have a pack expansion, for which we will be substituting into
3152 // the pattern.
3153 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003154 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003156 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3157 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003158
Chris Lattner686775d2011-07-20 06:58:45 +00003159 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003160 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3161 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3162
3163 // Determine whether the set of unexpanded parameter packs can and should
3164 // be expanded.
3165 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003166 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003167 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003168 if (getDerived().TryExpandParameterPacks(Ellipsis,
3169 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003170 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003171 Expand,
3172 RetainExpansion,
3173 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 return true;
3175
3176 if (!Expand) {
3177 // The transform has determined that we should perform a simple
3178 // transformation on the pack expansion, producing another pack
3179 // expansion.
3180 TemplateArgumentLoc OutPattern;
3181 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3182 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3183 return true;
3184
Douglas Gregorcded4f62011-01-14 17:04:44 +00003185 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3186 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 if (Out.getArgument().isNull())
3188 return true;
3189
3190 Outputs.addArgument(Out);
3191 continue;
3192 }
3193
3194 // The transform has determined that we should perform an elementwise
3195 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003196 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3198
3199 if (getDerived().TransformTemplateArgument(Pattern, Out))
3200 return true;
3201
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003202 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003203 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3204 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003205 if (Out.getArgument().isNull())
3206 return true;
3207 }
3208
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003209 Outputs.addArgument(Out);
3210 }
3211
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003212 // If we're supposed to retain a pack expansion, do so by temporarily
3213 // forgetting the partially-substituted parameter pack.
3214 if (RetainExpansion) {
3215 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3216
3217 if (getDerived().TransformTemplateArgument(Pattern, Out))
3218 return true;
3219
Douglas Gregorcded4f62011-01-14 17:04:44 +00003220 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3221 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003222 if (Out.getArgument().isNull())
3223 return true;
3224
3225 Outputs.addArgument(Out);
3226 }
Douglas Gregord3731192011-01-10 07:32:04 +00003227
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003228 continue;
3229 }
3230
3231 // The simple case:
3232 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003233 return true;
3234
3235 Outputs.addArgument(Out);
3236 }
3237
3238 return false;
3239
3240}
3241
Douglas Gregor577f75a2009-08-04 16:50:30 +00003242//===----------------------------------------------------------------------===//
3243// Type transformation
3244//===----------------------------------------------------------------------===//
3245
3246template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003247QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003248 if (getDerived().AlreadyTransformed(T))
3249 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003250
John McCalla2becad2009-10-21 00:40:46 +00003251 // Temporary workaround. All of these transformations should
3252 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003253 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3254 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003255
John McCall43fed0d2010-11-12 08:19:04 +00003256 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003257
John McCalla2becad2009-10-21 00:40:46 +00003258 if (!NewDI)
3259 return QualType();
3260
3261 return NewDI->getType();
3262}
3263
3264template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003265TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003266 // Refine the base location to the type's location.
3267 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3268 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003269 if (getDerived().AlreadyTransformed(DI->getType()))
3270 return DI;
3271
3272 TypeLocBuilder TLB;
3273
3274 TypeLoc TL = DI->getTypeLoc();
3275 TLB.reserve(TL.getFullDataSize());
3276
John McCall43fed0d2010-11-12 08:19:04 +00003277 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003278 if (Result.isNull())
3279 return 0;
3280
John McCalla93c9342009-12-07 02:54:59 +00003281 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003282}
3283
3284template<typename Derived>
3285QualType
John McCall43fed0d2010-11-12 08:19:04 +00003286TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003287 switch (T.getTypeLocClass()) {
3288#define ABSTRACT_TYPELOC(CLASS, PARENT)
3289#define TYPELOC(CLASS, PARENT) \
3290 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003291 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003292#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003293 }
Mike Stump1eb44332009-09-09 15:08:12 +00003294
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003295 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003296}
3297
3298/// FIXME: By default, this routine adds type qualifiers only to types
3299/// that can have qualifiers, and silently suppresses those qualifiers
3300/// that are not permitted (e.g., qualifiers on reference or function
3301/// types). This is the right thing for template instantiation, but
3302/// probably not for other clients.
3303template<typename Derived>
3304QualType
3305TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003306 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003307 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003308
John McCall43fed0d2010-11-12 08:19:04 +00003309 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003310 if (Result.isNull())
3311 return QualType();
3312
3313 // Silently suppress qualifiers if the result type can't be qualified.
3314 // FIXME: this is the right thing for template instantiation, but
3315 // probably not for other clients.
3316 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003318
John McCallf85e1932011-06-15 23:02:42 +00003319 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003320 // resulting type.
3321 if (Quals.hasObjCLifetime()) {
3322 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3323 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003324 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003325 // Objective-C ARC:
3326 // A lifetime qualifier applied to a substituted template parameter
3327 // overrides the lifetime qualifier from the template argument.
3328 if (const SubstTemplateTypeParmType *SubstTypeParam
3329 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3330 QualType Replacement = SubstTypeParam->getReplacementType();
3331 Qualifiers Qs = Replacement.getQualifiers();
3332 Qs.removeObjCLifetime();
3333 Replacement
3334 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3335 Qs);
3336 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3337 SubstTypeParam->getReplacedParameter(),
3338 Replacement);
3339 TLB.TypeWasModifiedSafely(Result);
3340 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003341 // Otherwise, complain about the addition of a qualifier to an
3342 // already-qualified type.
3343 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003344 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003345 << Result << R;
3346
Douglas Gregore559ca12011-06-17 22:11:49 +00003347 Quals.removeObjCLifetime();
3348 }
3349 }
3350 }
John McCall28654742010-06-05 06:41:15 +00003351 if (!Quals.empty()) {
3352 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3353 TLB.push<QualifiedTypeLoc>(Result);
3354 // No location information to preserve.
3355 }
John McCalla2becad2009-10-21 00:40:46 +00003356
3357 return Result;
3358}
3359
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003360template<typename Derived>
3361TypeLoc
3362TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3363 QualType ObjectType,
3364 NamedDecl *UnqualLookup,
3365 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003366 QualType T = TL.getType();
3367 if (getDerived().AlreadyTransformed(T))
3368 return TL;
3369
3370 TypeLocBuilder TLB;
3371 QualType Result;
3372
3373 if (isa<TemplateSpecializationType>(T)) {
3374 TemplateSpecializationTypeLoc SpecTL
3375 = cast<TemplateSpecializationTypeLoc>(TL);
3376
3377 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003378 getDerived().TransformTemplateName(SS,
3379 SpecTL.getTypePtr()->getTemplateName(),
3380 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003381 ObjectType, UnqualLookup);
3382 if (Template.isNull())
3383 return TypeLoc();
3384
3385 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3386 Template);
3387 } else if (isa<DependentTemplateSpecializationType>(T)) {
3388 DependentTemplateSpecializationTypeLoc SpecTL
3389 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3390
Douglas Gregora88f09f2011-02-28 17:23:35 +00003391 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003392 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003393 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003394 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003395 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003396 if (Template.isNull())
3397 return TypeLoc();
3398
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003399 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003400 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003401 Template,
3402 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003403 } else {
3404 // Nothing special needs to be done for these.
3405 Result = getDerived().TransformType(TLB, TL);
3406 }
3407
3408 if (Result.isNull())
3409 return TypeLoc();
3410
3411 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3412}
3413
Douglas Gregorb71d8212011-03-02 18:32:08 +00003414template<typename Derived>
3415TypeSourceInfo *
3416TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3417 QualType ObjectType,
3418 NamedDecl *UnqualLookup,
3419 CXXScopeSpec &SS) {
3420 // FIXME: Painfully copy-paste from the above!
3421
3422 QualType T = TSInfo->getType();
3423 if (getDerived().AlreadyTransformed(T))
3424 return TSInfo;
3425
3426 TypeLocBuilder TLB;
3427 QualType Result;
3428
3429 TypeLoc TL = TSInfo->getTypeLoc();
3430 if (isa<TemplateSpecializationType>(T)) {
3431 TemplateSpecializationTypeLoc SpecTL
3432 = cast<TemplateSpecializationTypeLoc>(TL);
3433
3434 TemplateName Template
3435 = getDerived().TransformTemplateName(SS,
3436 SpecTL.getTypePtr()->getTemplateName(),
3437 SpecTL.getTemplateNameLoc(),
3438 ObjectType, UnqualLookup);
3439 if (Template.isNull())
3440 return 0;
3441
3442 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3443 Template);
3444 } else if (isa<DependentTemplateSpecializationType>(T)) {
3445 DependentTemplateSpecializationTypeLoc SpecTL
3446 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3447
3448 TemplateName Template
3449 = getDerived().RebuildTemplateName(SS,
3450 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003451 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003452 ObjectType, UnqualLookup);
3453 if (Template.isNull())
3454 return 0;
3455
3456 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3457 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003458 Template,
3459 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003460 } else {
3461 // Nothing special needs to be done for these.
3462 Result = getDerived().TransformType(TLB, TL);
3463 }
3464
3465 if (Result.isNull())
3466 return 0;
3467
3468 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3469}
3470
John McCalla2becad2009-10-21 00:40:46 +00003471template <class TyLoc> static inline
3472QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3473 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3474 NewT.setNameLoc(T.getNameLoc());
3475 return T.getType();
3476}
3477
John McCalla2becad2009-10-21 00:40:46 +00003478template<typename Derived>
3479QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003480 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003481 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3482 NewT.setBuiltinLoc(T.getBuiltinLoc());
3483 if (T.needsExtraLocalData())
3484 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3485 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003486}
Mike Stump1eb44332009-09-09 15:08:12 +00003487
Douglas Gregor577f75a2009-08-04 16:50:30 +00003488template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003489QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003490 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003491 // FIXME: recurse?
3492 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003493}
Mike Stump1eb44332009-09-09 15:08:12 +00003494
Douglas Gregor577f75a2009-08-04 16:50:30 +00003495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003496QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003498 QualType PointeeType
3499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003500 if (PointeeType.isNull())
3501 return QualType();
3502
3503 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003504 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003505 // A dependent pointer type 'T *' has is being transformed such
3506 // that an Objective-C class type is being replaced for 'T'. The
3507 // resulting pointer type is an ObjCObjectPointerType, not a
3508 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003509 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003510
John McCallc12c5bb2010-05-15 11:32:37 +00003511 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3512 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003513 return Result;
3514 }
John McCall43fed0d2010-11-12 08:19:04 +00003515
Douglas Gregor92e986e2010-04-22 16:44:27 +00003516 if (getDerived().AlwaysRebuild() ||
3517 PointeeType != TL.getPointeeLoc().getType()) {
3518 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3519 if (Result.isNull())
3520 return QualType();
3521 }
John McCallf85e1932011-06-15 23:02:42 +00003522
3523 // Objective-C ARC can add lifetime qualifiers to the type that we're
3524 // pointing to.
3525 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3526
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3528 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003529 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003530}
Mike Stump1eb44332009-09-09 15:08:12 +00003531
3532template<typename Derived>
3533QualType
John McCalla2becad2009-10-21 00:40:46 +00003534TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003535 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003536 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003537 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3538 if (PointeeType.isNull())
3539 return QualType();
3540
3541 QualType Result = TL.getType();
3542 if (getDerived().AlwaysRebuild() ||
3543 PointeeType != TL.getPointeeLoc().getType()) {
3544 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003545 TL.getSigilLoc());
3546 if (Result.isNull())
3547 return QualType();
3548 }
3549
Douglas Gregor39968ad2010-04-22 16:50:51 +00003550 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003551 NewT.setSigilLoc(TL.getSigilLoc());
3552 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003553}
3554
John McCall85737a72009-10-30 00:06:24 +00003555/// Transforms a reference type. Note that somewhat paradoxically we
3556/// don't care whether the type itself is an l-value type or an r-value
3557/// type; we only care if the type was *written* as an l-value type
3558/// or an r-value type.
3559template<typename Derived>
3560QualType
3561TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003562 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003563 const ReferenceType *T = TL.getTypePtr();
3564
3565 // Note that this works with the pointee-as-written.
3566 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3567 if (PointeeType.isNull())
3568 return QualType();
3569
3570 QualType Result = TL.getType();
3571 if (getDerived().AlwaysRebuild() ||
3572 PointeeType != T->getPointeeTypeAsWritten()) {
3573 Result = getDerived().RebuildReferenceType(PointeeType,
3574 T->isSpelledAsLValue(),
3575 TL.getSigilLoc());
3576 if (Result.isNull())
3577 return QualType();
3578 }
3579
John McCallf85e1932011-06-15 23:02:42 +00003580 // Objective-C ARC can add lifetime qualifiers to the type that we're
3581 // referring to.
3582 TLB.TypeWasModifiedSafely(
3583 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3584
John McCall85737a72009-10-30 00:06:24 +00003585 // r-value references can be rebuilt as l-value references.
3586 ReferenceTypeLoc NewTL;
3587 if (isa<LValueReferenceType>(Result))
3588 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3589 else
3590 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3591 NewTL.setSigilLoc(TL.getSigilLoc());
3592
3593 return Result;
3594}
3595
Mike Stump1eb44332009-09-09 15:08:12 +00003596template<typename Derived>
3597QualType
John McCalla2becad2009-10-21 00:40:46 +00003598TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003599 LValueReferenceTypeLoc TL) {
3600 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003601}
3602
Mike Stump1eb44332009-09-09 15:08:12 +00003603template<typename Derived>
3604QualType
John McCalla2becad2009-10-21 00:40:46 +00003605TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003606 RValueReferenceTypeLoc TL) {
3607 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608}
Mike Stump1eb44332009-09-09 15:08:12 +00003609
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003611QualType
John McCalla2becad2009-10-21 00:40:46 +00003612TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003613 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003614 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003615 if (PointeeType.isNull())
3616 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003618 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3619 TypeSourceInfo* NewClsTInfo = 0;
3620 if (OldClsTInfo) {
3621 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3622 if (!NewClsTInfo)
3623 return QualType();
3624 }
3625
3626 const MemberPointerType *T = TL.getTypePtr();
3627 QualType OldClsType = QualType(T->getClass(), 0);
3628 QualType NewClsType;
3629 if (NewClsTInfo)
3630 NewClsType = NewClsTInfo->getType();
3631 else {
3632 NewClsType = getDerived().TransformType(OldClsType);
3633 if (NewClsType.isNull())
3634 return QualType();
3635 }
Mike Stump1eb44332009-09-09 15:08:12 +00003636
John McCalla2becad2009-10-21 00:40:46 +00003637 QualType Result = TL.getType();
3638 if (getDerived().AlwaysRebuild() ||
3639 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003640 NewClsType != OldClsType) {
3641 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003642 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003643 if (Result.isNull())
3644 return QualType();
3645 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003646
John McCalla2becad2009-10-21 00:40:46 +00003647 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3648 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003649 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003650
3651 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003652}
3653
Mike Stump1eb44332009-09-09 15:08:12 +00003654template<typename Derived>
3655QualType
John McCalla2becad2009-10-21 00:40:46 +00003656TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003657 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003658 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003659 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660 if (ElementType.isNull())
3661 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003662
John McCalla2becad2009-10-21 00:40:46 +00003663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
3665 ElementType != T->getElementType()) {
3666 Result = getDerived().RebuildConstantArrayType(ElementType,
3667 T->getSizeModifier(),
3668 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003669 T->getIndexTypeCVRQualifiers(),
3670 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003671 if (Result.isNull())
3672 return QualType();
3673 }
Eli Friedman457a3772012-01-25 22:19:07 +00003674
3675 // We might have either a ConstantArrayType or a VariableArrayType now:
3676 // a ConstantArrayType is allowed to have an element type which is a
3677 // VariableArrayType if the type is dependent. Fortunately, all array
3678 // types have the same location layout.
3679 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003680 NewTL.setLBracketLoc(TL.getLBracketLoc());
3681 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003682
John McCalla2becad2009-10-21 00:40:46 +00003683 Expr *Size = TL.getSizeExpr();
3684 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003685 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3686 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003687 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003688 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003689 }
3690 NewTL.setSizeExpr(Size);
3691
3692 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003693}
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003696QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003697 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003698 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003699 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003701 if (ElementType.isNull())
3702 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003703
John McCalla2becad2009-10-21 00:40:46 +00003704 QualType Result = TL.getType();
3705 if (getDerived().AlwaysRebuild() ||
3706 ElementType != T->getElementType()) {
3707 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003708 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003709 T->getIndexTypeCVRQualifiers(),
3710 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003711 if (Result.isNull())
3712 return QualType();
3713 }
Sean Huntc3021132010-05-05 15:23:54 +00003714
John McCalla2becad2009-10-21 00:40:46 +00003715 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3716 NewTL.setLBracketLoc(TL.getLBracketLoc());
3717 NewTL.setRBracketLoc(TL.getRBracketLoc());
3718 NewTL.setSizeExpr(0);
3719
3720 return Result;
3721}
3722
3723template<typename Derived>
3724QualType
3725TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003726 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003727 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3729 if (ElementType.isNull())
3730 return QualType();
3731
John McCall60d7b3a2010-08-24 06:29:42 +00003732 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003733 = getDerived().TransformExpr(T->getSizeExpr());
3734 if (SizeResult.isInvalid())
3735 return QualType();
3736
John McCall9ae2f072010-08-23 23:25:46 +00003737 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003738
3739 QualType Result = TL.getType();
3740 if (getDerived().AlwaysRebuild() ||
3741 ElementType != T->getElementType() ||
3742 Size != T->getSizeExpr()) {
3743 Result = getDerived().RebuildVariableArrayType(ElementType,
3744 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003745 Size,
John McCalla2becad2009-10-21 00:40:46 +00003746 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003747 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003748 if (Result.isNull())
3749 return QualType();
3750 }
Sean Huntc3021132010-05-05 15:23:54 +00003751
John McCalla2becad2009-10-21 00:40:46 +00003752 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3753 NewTL.setLBracketLoc(TL.getLBracketLoc());
3754 NewTL.setRBracketLoc(TL.getRBracketLoc());
3755 NewTL.setSizeExpr(Size);
3756
3757 return Result;
3758}
3759
3760template<typename Derived>
3761QualType
3762TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003763 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003764 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003765 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3766 if (ElementType.isNull())
3767 return QualType();
3768
Richard Smithf6702a32011-12-20 02:08:33 +00003769 // Array bounds are constant expressions.
3770 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3771 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003772
John McCall3b657512011-01-19 10:06:00 +00003773 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3774 Expr *origSize = TL.getSizeExpr();
3775 if (!origSize) origSize = T->getSizeExpr();
3776
3777 ExprResult sizeResult
3778 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003779 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003780 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003781 return QualType();
3782
John McCall3b657512011-01-19 10:06:00 +00003783 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003784
3785 QualType Result = TL.getType();
3786 if (getDerived().AlwaysRebuild() ||
3787 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003788 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003789 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3790 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003791 size,
John McCalla2becad2009-10-21 00:40:46 +00003792 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003793 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003794 if (Result.isNull())
3795 return QualType();
3796 }
John McCalla2becad2009-10-21 00:40:46 +00003797
3798 // We might have any sort of array type now, but fortunately they
3799 // all have the same location layout.
3800 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3801 NewTL.setLBracketLoc(TL.getLBracketLoc());
3802 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003803 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003804
3805 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003806}
Mike Stump1eb44332009-09-09 15:08:12 +00003807
3808template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003809QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003810 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003811 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003812 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003813
3814 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003815 QualType ElementType = getDerived().TransformType(T->getElementType());
3816 if (ElementType.isNull())
3817 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003818
Richard Smithf6702a32011-12-20 02:08:33 +00003819 // Vector sizes are constant expressions.
3820 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3821 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003822
John McCall60d7b3a2010-08-24 06:29:42 +00003823 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003824 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003825 if (Size.isInvalid())
3826 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003827
John McCalla2becad2009-10-21 00:40:46 +00003828 QualType Result = TL.getType();
3829 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003830 ElementType != T->getElementType() ||
3831 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003832 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003833 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003835 if (Result.isNull())
3836 return QualType();
3837 }
John McCalla2becad2009-10-21 00:40:46 +00003838
3839 // Result might be dependent or not.
3840 if (isa<DependentSizedExtVectorType>(Result)) {
3841 DependentSizedExtVectorTypeLoc NewTL
3842 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3843 NewTL.setNameLoc(TL.getNameLoc());
3844 } else {
3845 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3846 NewTL.setNameLoc(TL.getNameLoc());
3847 }
3848
3849 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003850}
Mike Stump1eb44332009-09-09 15:08:12 +00003851
3852template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003853QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003854 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003855 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003856 QualType ElementType = getDerived().TransformType(T->getElementType());
3857 if (ElementType.isNull())
3858 return QualType();
3859
John McCalla2becad2009-10-21 00:40:46 +00003860 QualType Result = TL.getType();
3861 if (getDerived().AlwaysRebuild() ||
3862 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003863 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003864 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003865 if (Result.isNull())
3866 return QualType();
3867 }
Sean Huntc3021132010-05-05 15:23:54 +00003868
John McCalla2becad2009-10-21 00:40:46 +00003869 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003871
John McCalla2becad2009-10-21 00:40:46 +00003872 return Result;
3873}
3874
3875template<typename Derived>
3876QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003877 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003878 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003879 QualType ElementType = getDerived().TransformType(T->getElementType());
3880 if (ElementType.isNull())
3881 return QualType();
3882
3883 QualType Result = TL.getType();
3884 if (getDerived().AlwaysRebuild() ||
3885 ElementType != T->getElementType()) {
3886 Result = getDerived().RebuildExtVectorType(ElementType,
3887 T->getNumElements(),
3888 /*FIXME*/ SourceLocation());
3889 if (Result.isNull())
3890 return QualType();
3891 }
Sean Huntc3021132010-05-05 15:23:54 +00003892
John McCalla2becad2009-10-21 00:40:46 +00003893 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3894 NewTL.setNameLoc(TL.getNameLoc());
3895
3896 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003897}
Mike Stump1eb44332009-09-09 15:08:12 +00003898
3899template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003900ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003901TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003902 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003903 llvm::Optional<unsigned> NumExpansions,
3904 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003905 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003906 TypeSourceInfo *NewDI = 0;
3907
3908 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3909 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003910 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003911 TypeLoc OldTL = OldDI->getTypeLoc();
3912 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3913
3914 TypeLocBuilder TLB;
3915 TypeLoc NewTL = OldDI->getTypeLoc();
3916 TLB.reserve(NewTL.getFullDataSize());
3917
3918 QualType Result = getDerived().TransformType(TLB,
3919 OldExpansionTL.getPatternLoc());
3920 if (Result.isNull())
3921 return 0;
3922
3923 Result = RebuildPackExpansionType(Result,
3924 OldExpansionTL.getPatternLoc().getSourceRange(),
3925 OldExpansionTL.getEllipsisLoc(),
3926 NumExpansions);
3927 if (Result.isNull())
3928 return 0;
3929
3930 PackExpansionTypeLoc NewExpansionTL
3931 = TLB.push<PackExpansionTypeLoc>(Result);
3932 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3933 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3934 } else
3935 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003936 if (!NewDI)
3937 return 0;
3938
John McCallfb44de92011-05-01 22:35:37 +00003939 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003940 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003941
3942 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3943 OldParm->getDeclContext(),
3944 OldParm->getInnerLocStart(),
3945 OldParm->getLocation(),
3946 OldParm->getIdentifier(),
3947 NewDI->getType(),
3948 NewDI,
3949 OldParm->getStorageClass(),
3950 OldParm->getStorageClassAsWritten(),
3951 /* DefArg */ NULL);
3952 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3953 OldParm->getFunctionScopeIndex() + indexAdjustment);
3954 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003955}
3956
3957template<typename Derived>
3958bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003959 TransformFunctionTypeParams(SourceLocation Loc,
3960 ParmVarDecl **Params, unsigned NumParams,
3961 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003962 SmallVectorImpl<QualType> &OutParamTypes,
3963 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003964 int indexAdjustment = 0;
3965
Douglas Gregora009b592011-01-07 00:20:55 +00003966 for (unsigned i = 0; i != NumParams; ++i) {
3967 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003968 assert(OldParm->getFunctionScopeIndex() == i);
3969
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003970 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003971 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003972 if (OldParm->isParameterPack()) {
3973 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003974 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003975
Douglas Gregor603cfb42011-01-05 23:12:31 +00003976 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003977 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3978 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3979 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3980 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003981 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3982
Douglas Gregor603cfb42011-01-05 23:12:31 +00003983 // Determine whether we should expand the parameter packs.
3984 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003985 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003986 llvm::Optional<unsigned> OrigNumExpansions
3987 = ExpansionTL.getTypePtr()->getNumExpansions();
3988 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003989 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3990 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003991 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003992 ShouldExpand,
3993 RetainExpansion,
3994 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003995 return true;
3996 }
3997
3998 if (ShouldExpand) {
3999 // Expand the function parameter pack into multiple, separate
4000 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004001 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004002 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004003 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4004 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004005 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004006 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004007 OrigNumExpansions,
4008 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004009 if (!NewParm)
4010 return true;
4011
Douglas Gregora009b592011-01-07 00:20:55 +00004012 OutParamTypes.push_back(NewParm->getType());
4013 if (PVars)
4014 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004015 }
Douglas Gregord3731192011-01-10 07:32:04 +00004016
4017 // If we're supposed to retain a pack expansion, do so by temporarily
4018 // forgetting the partially-substituted parameter pack.
4019 if (RetainExpansion) {
4020 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4021 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004022 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004023 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004024 OrigNumExpansions,
4025 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004026 if (!NewParm)
4027 return true;
4028
4029 OutParamTypes.push_back(NewParm->getType());
4030 if (PVars)
4031 PVars->push_back(NewParm);
4032 }
4033
John McCallfb44de92011-05-01 22:35:37 +00004034 // The next parameter should have the same adjustment as the
4035 // last thing we pushed, but we post-incremented indexAdjustment
4036 // on every push. Also, if we push nothing, the adjustment should
4037 // go down by one.
4038 indexAdjustment--;
4039
Douglas Gregor603cfb42011-01-05 23:12:31 +00004040 // We're done with the pack expansion.
4041 continue;
4042 }
4043
4044 // We'll substitute the parameter now without expanding the pack
4045 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004046 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4047 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004048 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004049 NumExpansions,
4050 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004051 } else {
4052 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004053 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004054 llvm::Optional<unsigned>(),
4055 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004056 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004057
John McCall21ef0fa2010-03-11 09:03:00 +00004058 if (!NewParm)
4059 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004060
Douglas Gregora009b592011-01-07 00:20:55 +00004061 OutParamTypes.push_back(NewParm->getType());
4062 if (PVars)
4063 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 continue;
4065 }
John McCall21ef0fa2010-03-11 09:03:00 +00004066
4067 // Deal with the possibility that we don't have a parameter
4068 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004069 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004071 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004072 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 if (const PackExpansionType *Expansion
4074 = dyn_cast<PackExpansionType>(OldType)) {
4075 // We have a function parameter pack that may need to be expanded.
4076 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004077 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4079
4080 // Determine whether we should expand the parameter packs.
4081 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004082 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004083 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004084 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004085 ShouldExpand,
4086 RetainExpansion,
4087 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004088 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 }
4090
4091 if (ShouldExpand) {
4092 // Expand the function parameter pack into multiple, separate
4093 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004094 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004095 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4096 QualType NewType = getDerived().TransformType(Pattern);
4097 if (NewType.isNull())
4098 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004099
Douglas Gregora009b592011-01-07 00:20:55 +00004100 OutParamTypes.push_back(NewType);
4101 if (PVars)
4102 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 }
4104
4105 // We're done with the pack expansion.
4106 continue;
4107 }
4108
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004109 // If we're supposed to retain a pack expansion, do so by temporarily
4110 // forgetting the partially-substituted parameter pack.
4111 if (RetainExpansion) {
4112 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4113 QualType NewType = getDerived().TransformType(Pattern);
4114 if (NewType.isNull())
4115 return true;
4116
4117 OutParamTypes.push_back(NewType);
4118 if (PVars)
4119 PVars->push_back(0);
4120 }
Douglas Gregord3731192011-01-10 07:32:04 +00004121
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 // We'll substitute the parameter now without expanding the pack
4123 // expansion.
4124 OldType = Expansion->getPattern();
4125 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004126 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4127 NewType = getDerived().TransformType(OldType);
4128 } else {
4129 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004130 }
4131
Douglas Gregor603cfb42011-01-05 23:12:31 +00004132 if (NewType.isNull())
4133 return true;
4134
4135 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004136 NewType = getSema().Context.getPackExpansionType(NewType,
4137 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004138
Douglas Gregora009b592011-01-07 00:20:55 +00004139 OutParamTypes.push_back(NewType);
4140 if (PVars)
4141 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004142 }
4143
John McCallfb44de92011-05-01 22:35:37 +00004144#ifndef NDEBUG
4145 if (PVars) {
4146 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4147 if (ParmVarDecl *parm = (*PVars)[i])
4148 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 }
John McCallfb44de92011-05-01 22:35:37 +00004150#endif
4151
4152 return false;
4153}
John McCall21ef0fa2010-03-11 09:03:00 +00004154
4155template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004156QualType
John McCalla2becad2009-10-21 00:40:46 +00004157TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004158 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004159 // Transform the parameters and return type.
4160 //
4161 // We instantiate in source order, with the return type first followed by
4162 // the parameters, because users tend to expect this (even if they shouldn't
4163 // rely on it!).
4164 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004165 // When the function has a trailing return type, we instantiate the
4166 // parameters before the return type, since the return type can then refer
4167 // to the parameters themselves (via decltype, sizeof, etc.).
4168 //
Chris Lattner686775d2011-07-20 06:58:45 +00004169 SmallVector<QualType, 4> ParamTypes;
4170 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004171 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004172
Douglas Gregordab60ad2010-10-01 18:44:50 +00004173 QualType ResultType;
4174
4175 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004176 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4177 TL.getParmArray(),
4178 TL.getNumArgs(),
4179 TL.getTypePtr()->arg_type_begin(),
4180 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004181 return QualType();
4182
4183 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4184 if (ResultType.isNull())
4185 return QualType();
4186 }
4187 else {
4188 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4189 if (ResultType.isNull())
4190 return QualType();
4191
Douglas Gregora009b592011-01-07 00:20:55 +00004192 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4193 TL.getParmArray(),
4194 TL.getNumArgs(),
4195 TL.getTypePtr()->arg_type_begin(),
4196 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004197 return QualType();
4198 }
4199
John McCalla2becad2009-10-21 00:40:46 +00004200 QualType Result = TL.getType();
4201 if (getDerived().AlwaysRebuild() ||
4202 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004203 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004204 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4205 Result = getDerived().RebuildFunctionProtoType(ResultType,
4206 ParamTypes.data(),
4207 ParamTypes.size(),
4208 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004209 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004210 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004211 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004212 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004213 if (Result.isNull())
4214 return QualType();
4215 }
Mike Stump1eb44332009-09-09 15:08:12 +00004216
John McCalla2becad2009-10-21 00:40:46 +00004217 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004218 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4219 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004220 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004221 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4222 NewTL.setArg(i, ParamDecls[i]);
4223
4224 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004225}
Mike Stump1eb44332009-09-09 15:08:12 +00004226
Douglas Gregor577f75a2009-08-04 16:50:30 +00004227template<typename Derived>
4228QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004229 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004230 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004231 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004232 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4233 if (ResultType.isNull())
4234 return QualType();
4235
4236 QualType Result = TL.getType();
4237 if (getDerived().AlwaysRebuild() ||
4238 ResultType != T->getResultType())
4239 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4240
4241 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004242 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4243 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004244 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004245
4246 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004247}
Mike Stump1eb44332009-09-09 15:08:12 +00004248
John McCalled976492009-12-04 22:46:56 +00004249template<typename Derived> QualType
4250TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004251 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004252 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004253 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004254 if (!D)
4255 return QualType();
4256
4257 QualType Result = TL.getType();
4258 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4259 Result = getDerived().RebuildUnresolvedUsingType(D);
4260 if (Result.isNull())
4261 return QualType();
4262 }
4263
4264 // We might get an arbitrary type spec type back. We should at
4265 // least always get a type spec type, though.
4266 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4267 NewTL.setNameLoc(TL.getNameLoc());
4268
4269 return Result;
4270}
4271
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004273QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004274 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004275 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004276 TypedefNameDecl *Typedef
4277 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4278 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004279 if (!Typedef)
4280 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004281
John McCalla2becad2009-10-21 00:40:46 +00004282 QualType Result = TL.getType();
4283 if (getDerived().AlwaysRebuild() ||
4284 Typedef != T->getDecl()) {
4285 Result = getDerived().RebuildTypedefType(Typedef);
4286 if (Result.isNull())
4287 return QualType();
4288 }
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalla2becad2009-10-21 00:40:46 +00004290 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4291 NewTL.setNameLoc(TL.getNameLoc());
4292
4293 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004294}
Mike Stump1eb44332009-09-09 15:08:12 +00004295
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004297QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004298 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004299 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004300 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004301
John McCall60d7b3a2010-08-24 06:29:42 +00004302 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303 if (E.isInvalid())
4304 return QualType();
4305
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004306 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4307 if (E.isInvalid())
4308 return QualType();
4309
John McCalla2becad2009-10-21 00:40:46 +00004310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004312 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004313 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004314 if (Result.isNull())
4315 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004316 }
John McCalla2becad2009-10-21 00:40:46 +00004317 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004318
John McCalla2becad2009-10-21 00:40:46 +00004319 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004320 NewTL.setTypeofLoc(TL.getTypeofLoc());
4321 NewTL.setLParenLoc(TL.getLParenLoc());
4322 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004323
4324 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004325}
Mike Stump1eb44332009-09-09 15:08:12 +00004326
4327template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004328QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004329 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004330 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4331 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4332 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004333 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004334
John McCalla2becad2009-10-21 00:40:46 +00004335 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004336 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4337 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004338 if (Result.isNull())
4339 return QualType();
4340 }
Mike Stump1eb44332009-09-09 15:08:12 +00004341
John McCalla2becad2009-10-21 00:40:46 +00004342 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004343 NewTL.setTypeofLoc(TL.getTypeofLoc());
4344 NewTL.setLParenLoc(TL.getLParenLoc());
4345 NewTL.setRParenLoc(TL.getRParenLoc());
4346 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004347
4348 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004349}
Mike Stump1eb44332009-09-09 15:08:12 +00004350
4351template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004352QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004353 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004354 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004355
Douglas Gregor670444e2009-08-04 22:27:00 +00004356 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004357 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4358 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004359
John McCall60d7b3a2010-08-24 06:29:42 +00004360 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361 if (E.isInvalid())
4362 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004363
Richard Smith76f3f692012-02-22 02:04:18 +00004364 E = getSema().ActOnDecltypeExpression(E.take());
4365 if (E.isInvalid())
4366 return QualType();
4367
John McCalla2becad2009-10-21 00:40:46 +00004368 QualType Result = TL.getType();
4369 if (getDerived().AlwaysRebuild() ||
4370 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004371 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004372 if (Result.isNull())
4373 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374 }
John McCalla2becad2009-10-21 00:40:46 +00004375 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004376
John McCalla2becad2009-10-21 00:40:46 +00004377 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4378 NewTL.setNameLoc(TL.getNameLoc());
4379
4380 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381}
4382
4383template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004384QualType TreeTransform<Derived>::TransformUnaryTransformType(
4385 TypeLocBuilder &TLB,
4386 UnaryTransformTypeLoc TL) {
4387 QualType Result = TL.getType();
4388 if (Result->isDependentType()) {
4389 const UnaryTransformType *T = TL.getTypePtr();
4390 QualType NewBase =
4391 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4392 Result = getDerived().RebuildUnaryTransformType(NewBase,
4393 T->getUTTKind(),
4394 TL.getKWLoc());
4395 if (Result.isNull())
4396 return QualType();
4397 }
4398
4399 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4400 NewTL.setKWLoc(TL.getKWLoc());
4401 NewTL.setParensRange(TL.getParensRange());
4402 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4403 return Result;
4404}
4405
4406template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004407QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4408 AutoTypeLoc TL) {
4409 const AutoType *T = TL.getTypePtr();
4410 QualType OldDeduced = T->getDeducedType();
4411 QualType NewDeduced;
4412 if (!OldDeduced.isNull()) {
4413 NewDeduced = getDerived().TransformType(OldDeduced);
4414 if (NewDeduced.isNull())
4415 return QualType();
4416 }
4417
4418 QualType Result = TL.getType();
4419 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4420 Result = getDerived().RebuildAutoType(NewDeduced);
4421 if (Result.isNull())
4422 return QualType();
4423 }
4424
4425 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4426 NewTL.setNameLoc(TL.getNameLoc());
4427
4428 return Result;
4429}
4430
4431template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004432QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004433 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004434 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004435 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004436 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4437 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004438 if (!Record)
4439 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004440
John McCalla2becad2009-10-21 00:40:46 +00004441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 Record != T->getDecl()) {
4444 Result = getDerived().RebuildRecordType(Record);
4445 if (Result.isNull())
4446 return QualType();
4447 }
Mike Stump1eb44332009-09-09 15:08:12 +00004448
John McCalla2becad2009-10-21 00:40:46 +00004449 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4450 NewTL.setNameLoc(TL.getNameLoc());
4451
4452 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004453}
Mike Stump1eb44332009-09-09 15:08:12 +00004454
4455template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004456QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004457 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004458 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004459 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004460 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4461 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462 if (!Enum)
4463 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004464
John McCalla2becad2009-10-21 00:40:46 +00004465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() ||
4467 Enum != T->getDecl()) {
4468 Result = getDerived().RebuildEnumType(Enum);
4469 if (Result.isNull())
4470 return QualType();
4471 }
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCalla2becad2009-10-21 00:40:46 +00004473 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4474 NewTL.setNameLoc(TL.getNameLoc());
4475
4476 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477}
John McCall7da24312009-09-05 00:15:47 +00004478
John McCall3cb0ebd2010-03-10 03:28:59 +00004479template<typename Derived>
4480QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4481 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004482 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004483 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4484 TL.getTypePtr()->getDecl());
4485 if (!D) return QualType();
4486
4487 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4488 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4489 return T;
4490}
4491
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492template<typename Derived>
4493QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004494 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004495 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004496 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004497}
4498
Mike Stump1eb44332009-09-09 15:08:12 +00004499template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004500QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004501 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004502 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004503 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4504
4505 // Substitute into the replacement type, which itself might involve something
4506 // that needs to be transformed. This only tends to occur with default
4507 // template arguments of template template parameters.
4508 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4509 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4510 if (Replacement.isNull())
4511 return QualType();
4512
4513 // Always canonicalize the replacement type.
4514 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4515 QualType Result
4516 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4517 Replacement);
4518
4519 // Propagate type-source information.
4520 SubstTemplateTypeParmTypeLoc NewTL
4521 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4522 NewTL.setNameLoc(TL.getNameLoc());
4523 return Result;
4524
John McCall49a832b2009-10-18 09:09:24 +00004525}
4526
4527template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004528QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4529 TypeLocBuilder &TLB,
4530 SubstTemplateTypeParmPackTypeLoc TL) {
4531 return TransformTypeSpecType(TLB, TL);
4532}
4533
4534template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004535QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004536 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004537 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004538 const TemplateSpecializationType *T = TL.getTypePtr();
4539
Douglas Gregor1d752d72011-03-02 18:46:51 +00004540 // The nested-name-specifier never matters in a TemplateSpecializationType,
4541 // because we can't have a dependent nested-name-specifier anyway.
4542 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004543 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004544 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4545 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004546 if (Template.isNull())
4547 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004548
John McCall43fed0d2010-11-12 08:19:04 +00004549 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4550}
4551
Eli Friedmanb001de72011-10-06 23:00:33 +00004552template<typename Derived>
4553QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4554 AtomicTypeLoc TL) {
4555 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4556 if (ValueType.isNull())
4557 return QualType();
4558
4559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() ||
4561 ValueType != TL.getValueLoc().getType()) {
4562 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4563 if (Result.isNull())
4564 return QualType();
4565 }
4566
4567 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4568 NewTL.setKWLoc(TL.getKWLoc());
4569 NewTL.setLParenLoc(TL.getLParenLoc());
4570 NewTL.setRParenLoc(TL.getRParenLoc());
4571
4572 return Result;
4573}
4574
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004575namespace {
4576 /// \brief Simple iterator that traverses the template arguments in a
4577 /// container that provides a \c getArgLoc() member function.
4578 ///
4579 /// This iterator is intended to be used with the iterator form of
4580 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4581 template<typename ArgLocContainer>
4582 class TemplateArgumentLocContainerIterator {
4583 ArgLocContainer *Container;
4584 unsigned Index;
4585
4586 public:
4587 typedef TemplateArgumentLoc value_type;
4588 typedef TemplateArgumentLoc reference;
4589 typedef int difference_type;
4590 typedef std::input_iterator_tag iterator_category;
4591
4592 class pointer {
4593 TemplateArgumentLoc Arg;
4594
4595 public:
4596 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4597
4598 const TemplateArgumentLoc *operator->() const {
4599 return &Arg;
4600 }
4601 };
4602
4603
4604 TemplateArgumentLocContainerIterator() {}
4605
4606 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4607 unsigned Index)
4608 : Container(&Container), Index(Index) { }
4609
4610 TemplateArgumentLocContainerIterator &operator++() {
4611 ++Index;
4612 return *this;
4613 }
4614
4615 TemplateArgumentLocContainerIterator operator++(int) {
4616 TemplateArgumentLocContainerIterator Old(*this);
4617 ++(*this);
4618 return Old;
4619 }
4620
4621 TemplateArgumentLoc operator*() const {
4622 return Container->getArgLoc(Index);
4623 }
4624
4625 pointer operator->() const {
4626 return pointer(Container->getArgLoc(Index));
4627 }
4628
4629 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004630 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004631 return X.Container == Y.Container && X.Index == Y.Index;
4632 }
4633
4634 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004635 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004636 return !(X == Y);
4637 }
4638 };
4639}
4640
4641
John McCall43fed0d2010-11-12 08:19:04 +00004642template <typename Derived>
4643QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4644 TypeLocBuilder &TLB,
4645 TemplateSpecializationTypeLoc TL,
4646 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004647 TemplateArgumentListInfo NewTemplateArgs;
4648 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4649 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004650 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4651 ArgIterator;
4652 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4653 ArgIterator(TL, TL.getNumArgs()),
4654 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004655 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004656
John McCall833ca992009-10-29 08:12:44 +00004657 // FIXME: maybe don't rebuild if all the template arguments are the same.
4658
4659 QualType Result =
4660 getDerived().RebuildTemplateSpecializationType(Template,
4661 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004662 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004663
4664 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004665 // Specializations of template template parameters are represented as
4666 // TemplateSpecializationTypes, and substitution of type alias templates
4667 // within a dependent context can transform them into
4668 // DependentTemplateSpecializationTypes.
4669 if (isa<DependentTemplateSpecializationType>(Result)) {
4670 DependentTemplateSpecializationTypeLoc NewTL
4671 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004672 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004673 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004674 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004675 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004676 NewTL.setLAngleLoc(TL.getLAngleLoc());
4677 NewTL.setRAngleLoc(TL.getRAngleLoc());
4678 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4679 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4680 return Result;
4681 }
4682
John McCall833ca992009-10-29 08:12:44 +00004683 TemplateSpecializationTypeLoc NewTL
4684 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004685 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004686 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4687 NewTL.setLAngleLoc(TL.getLAngleLoc());
4688 NewTL.setRAngleLoc(TL.getRAngleLoc());
4689 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4690 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004691 }
Mike Stump1eb44332009-09-09 15:08:12 +00004692
John McCall833ca992009-10-29 08:12:44 +00004693 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694}
Mike Stump1eb44332009-09-09 15:08:12 +00004695
Douglas Gregora88f09f2011-02-28 17:23:35 +00004696template <typename Derived>
4697QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4698 TypeLocBuilder &TLB,
4699 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004700 TemplateName Template,
4701 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004702 TemplateArgumentListInfo NewTemplateArgs;
4703 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4704 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4705 typedef TemplateArgumentLocContainerIterator<
4706 DependentTemplateSpecializationTypeLoc> ArgIterator;
4707 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4708 ArgIterator(TL, TL.getNumArgs()),
4709 NewTemplateArgs))
4710 return QualType();
4711
4712 // FIXME: maybe don't rebuild if all the template arguments are the same.
4713
4714 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4715 QualType Result
4716 = getSema().Context.getDependentTemplateSpecializationType(
4717 TL.getTypePtr()->getKeyword(),
4718 DTN->getQualifier(),
4719 DTN->getIdentifier(),
4720 NewTemplateArgs);
4721
4722 DependentTemplateSpecializationTypeLoc NewTL
4723 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004724 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004725 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004726 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004727 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004728 NewTL.setLAngleLoc(TL.getLAngleLoc());
4729 NewTL.setRAngleLoc(TL.getRAngleLoc());
4730 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4731 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4732 return Result;
4733 }
4734
4735 QualType Result
4736 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004737 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004738 NewTemplateArgs);
4739
4740 if (!Result.isNull()) {
4741 /// FIXME: Wrap this in an elaborated-type-specifier?
4742 TemplateSpecializationTypeLoc NewTL
4743 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004744 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004745 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004746 NewTL.setLAngleLoc(TL.getLAngleLoc());
4747 NewTL.setRAngleLoc(TL.getRAngleLoc());
4748 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4749 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4750 }
4751
4752 return Result;
4753}
4754
Mike Stump1eb44332009-09-09 15:08:12 +00004755template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004756QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004757TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004758 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004759 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004760
Douglas Gregor9e876872011-03-01 18:12:44 +00004761 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004762 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004763 if (TL.getQualifierLoc()) {
4764 QualifierLoc
4765 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4766 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004767 return QualType();
4768 }
Mike Stump1eb44332009-09-09 15:08:12 +00004769
John McCall43fed0d2010-11-12 08:19:04 +00004770 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4771 if (NamedT.isNull())
4772 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004773
Richard Smith3e4c6c42011-05-05 21:57:07 +00004774 // C++0x [dcl.type.elab]p2:
4775 // If the identifier resolves to a typedef-name or the simple-template-id
4776 // resolves to an alias template specialization, the
4777 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004778 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4779 if (const TemplateSpecializationType *TST =
4780 NamedT->getAs<TemplateSpecializationType>()) {
4781 TemplateName Template = TST->getTemplateName();
4782 if (TypeAliasTemplateDecl *TAT =
4783 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4784 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4785 diag::err_tag_reference_non_tag) << 4;
4786 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4787 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004788 }
4789 }
4790
John McCalla2becad2009-10-21 00:40:46 +00004791 QualType Result = TL.getType();
4792 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004793 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004794 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004795 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004796 T->getKeyword(),
4797 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004798 if (Result.isNull())
4799 return QualType();
4800 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004801
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004803 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004804 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004805 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004806}
Mike Stump1eb44332009-09-09 15:08:12 +00004807
4808template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004809QualType TreeTransform<Derived>::TransformAttributedType(
4810 TypeLocBuilder &TLB,
4811 AttributedTypeLoc TL) {
4812 const AttributedType *oldType = TL.getTypePtr();
4813 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4814 if (modifiedType.isNull())
4815 return QualType();
4816
4817 QualType result = TL.getType();
4818
4819 // FIXME: dependent operand expressions?
4820 if (getDerived().AlwaysRebuild() ||
4821 modifiedType != oldType->getModifiedType()) {
4822 // TODO: this is really lame; we should really be rebuilding the
4823 // equivalent type from first principles.
4824 QualType equivalentType
4825 = getDerived().TransformType(oldType->getEquivalentType());
4826 if (equivalentType.isNull())
4827 return QualType();
4828 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4829 modifiedType,
4830 equivalentType);
4831 }
4832
4833 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4834 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4835 if (TL.hasAttrOperand())
4836 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4837 if (TL.hasAttrExprOperand())
4838 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4839 else if (TL.hasAttrEnumOperand())
4840 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4841
4842 return result;
4843}
4844
4845template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004846QualType
4847TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4848 ParenTypeLoc TL) {
4849 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4850 if (Inner.isNull())
4851 return QualType();
4852
4853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() ||
4855 Inner != TL.getInnerLoc().getType()) {
4856 Result = getDerived().RebuildParenType(Inner);
4857 if (Result.isNull())
4858 return QualType();
4859 }
4860
4861 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4862 NewTL.setLParenLoc(TL.getLParenLoc());
4863 NewTL.setRParenLoc(TL.getRParenLoc());
4864 return Result;
4865}
4866
4867template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004868QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004869 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004870 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004871
Douglas Gregor2494dd02011-03-01 01:34:45 +00004872 NestedNameSpecifierLoc QualifierLoc
4873 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4874 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004875 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004876
John McCall33500952010-06-11 00:33:02 +00004877 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004878 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004879 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004880 QualifierLoc,
4881 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004882 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004883 if (Result.isNull())
4884 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004885
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004886 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4887 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004888 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4889
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004890 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004891 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004892 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004893 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004894 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004895 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004896 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004897 NewTL.setNameLoc(TL.getNameLoc());
4898 }
John McCalla2becad2009-10-21 00:40:46 +00004899 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004900}
Mike Stump1eb44332009-09-09 15:08:12 +00004901
Douglas Gregor577f75a2009-08-04 16:50:30 +00004902template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004903QualType TreeTransform<Derived>::
4904 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004905 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004906 NestedNameSpecifierLoc QualifierLoc;
4907 if (TL.getQualifierLoc()) {
4908 QualifierLoc
4909 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4910 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004911 return QualType();
4912 }
4913
John McCall43fed0d2010-11-12 08:19:04 +00004914 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004915 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004916}
4917
4918template<typename Derived>
4919QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004920TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4921 DependentTemplateSpecializationTypeLoc TL,
4922 NestedNameSpecifierLoc QualifierLoc) {
4923 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4924
4925 TemplateArgumentListInfo NewTemplateArgs;
4926 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4927 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4928
4929 typedef TemplateArgumentLocContainerIterator<
4930 DependentTemplateSpecializationTypeLoc> ArgIterator;
4931 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4932 ArgIterator(TL, TL.getNumArgs()),
4933 NewTemplateArgs))
4934 return QualType();
4935
4936 QualType Result
4937 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4938 QualifierLoc,
4939 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004940 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004941 NewTemplateArgs);
4942 if (Result.isNull())
4943 return QualType();
4944
4945 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4946 QualType NamedT = ElabT->getNamedType();
4947
4948 // Copy information relevant to the template specialization.
4949 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004950 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004951 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004952 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004953 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4954 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004955 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004956 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004957
4958 // Copy information relevant to the elaborated type.
4959 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004960 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004962 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4963 DependentTemplateSpecializationTypeLoc SpecTL
4964 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004965 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004966 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004967 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004968 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004969 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4970 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004971 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004972 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004973 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004974 TemplateSpecializationTypeLoc SpecTL
4975 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004976 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004977 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004978 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4979 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004980 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004981 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 }
4983 return Result;
4984}
4985
4986template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004987QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4988 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004989 QualType Pattern
4990 = getDerived().TransformType(TLB, TL.getPatternLoc());
4991 if (Pattern.isNull())
4992 return QualType();
4993
4994 QualType Result = TL.getType();
4995 if (getDerived().AlwaysRebuild() ||
4996 Pattern != TL.getPatternLoc().getType()) {
4997 Result = getDerived().RebuildPackExpansionType(Pattern,
4998 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004999 TL.getEllipsisLoc(),
5000 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005001 if (Result.isNull())
5002 return QualType();
5003 }
5004
5005 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5006 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5007 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005008}
5009
5010template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005011QualType
5012TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005013 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005014 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005015 TLB.pushFullCopy(TL);
5016 return TL.getType();
5017}
5018
5019template<typename Derived>
5020QualType
5021TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005022 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005023 // ObjCObjectType is never dependent.
5024 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005025 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005026}
Mike Stump1eb44332009-09-09 15:08:12 +00005027
5028template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005029QualType
5030TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005031 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005032 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005033 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005034 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005035}
5036
Douglas Gregor577f75a2009-08-04 16:50:30 +00005037//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005038// Statement transformation
5039//===----------------------------------------------------------------------===//
5040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005041StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005042TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005043 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005044}
5045
5046template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005047StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005048TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5049 return getDerived().TransformCompoundStmt(S, false);
5050}
5051
5052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005053StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005054TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005055 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005056 Sema::CompoundScopeRAII CompoundScope(getSema());
5057
John McCall7114cba2010-08-27 19:56:05 +00005058 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005059 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005060 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005061 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5062 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005063 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005064 if (Result.isInvalid()) {
5065 // Immediately fail if this was a DeclStmt, since it's very
5066 // likely that this will cause problems for future statements.
5067 if (isa<DeclStmt>(*B))
5068 return StmtError();
5069
5070 // Otherwise, just keep processing substatements and fail later.
5071 SubStmtInvalid = true;
5072 continue;
5073 }
Mike Stump1eb44332009-09-09 15:08:12 +00005074
Douglas Gregor43959a92009-08-20 07:17:43 +00005075 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5076 Statements.push_back(Result.takeAs<Stmt>());
5077 }
Mike Stump1eb44332009-09-09 15:08:12 +00005078
John McCall7114cba2010-08-27 19:56:05 +00005079 if (SubStmtInvalid)
5080 return StmtError();
5081
Douglas Gregor43959a92009-08-20 07:17:43 +00005082 if (!getDerived().AlwaysRebuild() &&
5083 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005084 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005085
5086 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5087 move_arg(Statements),
5088 S->getRBracLoc(),
5089 IsStmtExpr);
5090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregor43959a92009-08-20 07:17:43 +00005092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005095 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005096 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005097 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5098 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Eli Friedman264c1f82009-11-19 03:14:00 +00005100 // Transform the left-hand case value.
5101 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005102 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005103 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005104 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005105
Eli Friedman264c1f82009-11-19 03:14:00 +00005106 // Transform the right-hand case value (for the GNU case-range extension).
5107 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005108 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005109 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005111 }
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 // Build the case statement.
5114 // Case statements are always rebuilt so that they will attached to their
5115 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005116 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005117 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005119 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 S->getColonLoc());
5121 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005125 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005127 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005130 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005131}
5132
5133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005135TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005136 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005137 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005138 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005139 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 // Default statements are always rebuilt
5142 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005143 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005144}
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregor43959a92009-08-20 07:17:43 +00005146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005147StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005148TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005149 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Chris Lattner57ad3782011-02-17 20:34:02 +00005153 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5154 S->getDecl());
5155 if (!LD)
5156 return StmtError();
5157
5158
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005160 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005161 cast<LabelDecl>(LD), SourceLocation(),
5162 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005163}
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor43959a92009-08-20 07:17:43 +00005165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005166StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005167TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005169 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005170 VarDecl *ConditionVar = 0;
5171 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005172 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005173 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005174 getDerived().TransformDefinition(
5175 S->getConditionVariable()->getLocation(),
5176 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005177 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005178 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005179 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005180 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005181
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005182 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005183 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005184
5185 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005186 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005187 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5188 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005189 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005190 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005191
John McCall9ae2f072010-08-23 23:25:46 +00005192 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005193 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005194 }
Sean Huntc3021132010-05-05 15:23:54 +00005195
John McCall9ae2f072010-08-23 23:25:46 +00005196 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5197 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005198 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005201 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005203 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005206 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005211 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005212 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 Then.get() == S->getThen() &&
5214 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005215 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005217 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005218 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005219 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005220}
5221
5222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005223StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005224TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005226 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005227 VarDecl *ConditionVar = 0;
5228 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005229 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005230 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005231 getDerived().TransformDefinition(
5232 S->getConditionVariable()->getLocation(),
5233 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005234 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005235 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005236 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005237 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005238
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005239 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005241 }
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregor43959a92009-08-20 07:17:43 +00005243 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005244 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005245 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005246 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005251 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005254
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005256 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5257 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258}
Mike Stump1eb44332009-09-09 15:08:12 +00005259
Douglas Gregor43959a92009-08-20 07:17:43 +00005260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005261StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005262TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005264 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005265 VarDecl *ConditionVar = 0;
5266 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005267 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005268 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005269 getDerived().TransformDefinition(
5270 S->getConditionVariable()->getLocation(),
5271 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005272 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005273 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005274 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005275 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005276
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005277 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005278 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005279
5280 if (S->getCond()) {
5281 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005282 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5283 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005284 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005285 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005286 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005287 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005288 }
Mike Stump1eb44332009-09-09 15:08:12 +00005289
John McCall9ae2f072010-08-23 23:25:46 +00005290 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5291 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005292 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005293
Douglas Gregor43959a92009-08-20 07:17:43 +00005294 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005295 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005300 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005301 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005303 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005305 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005306 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005307}
Mike Stump1eb44332009-09-09 15:08:12 +00005308
Douglas Gregor43959a92009-08-20 07:17:43 +00005309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005310StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005311TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005313 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005315 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005317 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005318 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005319 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005321
Douglas Gregor43959a92009-08-20 07:17:43 +00005322 if (!getDerived().AlwaysRebuild() &&
5323 Cond.get() == S->getCond() &&
5324 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005325 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005326
John McCall9ae2f072010-08-23 23:25:46 +00005327 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5328 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 S->getRParenLoc());
5330}
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005333StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005334TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005336 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005341 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005342 VarDecl *ConditionVar = 0;
5343 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005344 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005345 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005346 getDerived().TransformDefinition(
5347 S->getConditionVariable()->getLocation(),
5348 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005351 } else {
5352 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005353
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005356
5357 if (S->getCond()) {
5358 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005359 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5360 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005361 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005362 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005363
John McCall9ae2f072010-08-23 23:25:46 +00005364 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005365 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005366 }
Mike Stump1eb44332009-09-09 15:08:12 +00005367
John McCall9ae2f072010-08-23 23:25:46 +00005368 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5369 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005370 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005371
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005373 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005376
John McCall9ae2f072010-08-23 23:25:46 +00005377 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5378 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005382 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (!getDerived().AlwaysRebuild() &&
5387 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005388 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 Inc.get() == S->getInc() &&
5390 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005391 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005394 Init.get(), FullCond, ConditionVar,
5395 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005396}
5397
5398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005399StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005400TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005401 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5402 S->getLabel());
5403 if (!LD)
5404 return StmtError();
5405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005407 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005408 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005409}
5410
5411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005412StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005413TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005414 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005415 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005417 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 if (!getDerived().AlwaysRebuild() &&
5420 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005421 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005422
5423 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005424 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005425}
5426
5427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005428StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005429TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005430 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005431}
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005434StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005435TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005436 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005437}
Mike Stump1eb44332009-09-09 15:08:12 +00005438
Douglas Gregor43959a92009-08-20 07:17:43 +00005439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005440StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005441TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005442 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005445
Mike Stump1eb44332009-09-09 15:08:12 +00005446 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005448 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005449}
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregor43959a92009-08-20 07:17:43 +00005451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005452StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005453TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005455 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5457 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005458 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5459 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005461 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005462
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 if (Transformed != *D)
5464 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor43959a92009-08-20 07:17:43 +00005466 Decls.push_back(Transformed);
5467 }
Mike Stump1eb44332009-09-09 15:08:12 +00005468
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005471
5472 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 S->getStartLoc(), S->getEndLoc());
5474}
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregor43959a92009-08-20 07:17:43 +00005476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005478TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005479
John McCallca0408f2010-08-23 06:44:23 +00005480 ASTOwningVector<Expr*> Constraints(getSema());
5481 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005482 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005483
John McCall60d7b3a2010-08-24 06:29:42 +00005484 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005485 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005486
5487 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005488
Anders Carlsson703e3942010-01-24 05:50:09 +00005489 // Go through the outputs.
5490 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005491 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005492
Anders Carlsson703e3942010-01-24 05:50:09 +00005493 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005494 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005495
Anders Carlsson703e3942010-01-24 05:50:09 +00005496 // Transform the output expr.
5497 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005498 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005499 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005501
Anders Carlsson703e3942010-01-24 05:50:09 +00005502 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005503
John McCall9ae2f072010-08-23 23:25:46 +00005504 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005505 }
Sean Huntc3021132010-05-05 15:23:54 +00005506
Anders Carlsson703e3942010-01-24 05:50:09 +00005507 // Go through the inputs.
5508 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005509 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005510
Anders Carlsson703e3942010-01-24 05:50:09 +00005511 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005512 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005513
Anders Carlsson703e3942010-01-24 05:50:09 +00005514 // Transform the input expr.
5515 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005516 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005517 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005519
Anders Carlsson703e3942010-01-24 05:50:09 +00005520 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005521
John McCall9ae2f072010-08-23 23:25:46 +00005522 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005523 }
Sean Huntc3021132010-05-05 15:23:54 +00005524
Anders Carlsson703e3942010-01-24 05:50:09 +00005525 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005527
5528 // Go through the clobbers.
5529 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005530 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005531
5532 // No need to transform the asm string literal.
5533 AsmString = SemaRef.Owned(S->getAsmString());
5534
5535 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5536 S->isSimple(),
5537 S->isVolatile(),
5538 S->getNumOutputs(),
5539 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005540 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005541 move_arg(Constraints),
5542 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005543 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005544 move_arg(Clobbers),
5545 S->getRParenLoc(),
5546 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005547}
5548
5549
5550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005551StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005552TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005553 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005554 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005555 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005557
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005558 // Transform the @catch statements (if present).
5559 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005560 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005561 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005562 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005563 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005564 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005565 if (Catch.get() != S->getCatchStmt(I))
5566 AnyCatchChanged = true;
5567 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005568 }
Sean Huntc3021132010-05-05 15:23:54 +00005569
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005570 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005571 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005572 if (S->getFinallyStmt()) {
5573 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5574 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005575 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005576 }
5577
5578 // If nothing changed, just retain this statement.
5579 if (!getDerived().AlwaysRebuild() &&
5580 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005581 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005582 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005583 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005584
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005585 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005586 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5587 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005588}
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregor43959a92009-08-20 07:17:43 +00005590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005591StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005592TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005593 // Transform the @catch parameter, if there is one.
5594 VarDecl *Var = 0;
5595 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5596 TypeSourceInfo *TSInfo = 0;
5597 if (FromVar->getTypeSourceInfo()) {
5598 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5599 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005600 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005601 }
Sean Huntc3021132010-05-05 15:23:54 +00005602
Douglas Gregorbe270a02010-04-26 17:57:08 +00005603 QualType T;
5604 if (TSInfo)
5605 T = TSInfo->getType();
5606 else {
5607 T = getDerived().TransformType(FromVar->getType());
5608 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005609 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005610 }
Sean Huntc3021132010-05-05 15:23:54 +00005611
Douglas Gregorbe270a02010-04-26 17:57:08 +00005612 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5613 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005614 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005615 }
Sean Huntc3021132010-05-05 15:23:54 +00005616
John McCall60d7b3a2010-08-24 06:29:42 +00005617 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005618 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005619 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005620
5621 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005622 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005623 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005624}
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregor43959a92009-08-20 07:17:43 +00005626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005627StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005628TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005629 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005630 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005631 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005632 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005633
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // If nothing changed, just retain this statement.
5635 if (!getDerived().AlwaysRebuild() &&
5636 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638
5639 // Build a new statement.
5640 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005641 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005642}
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregor43959a92009-08-20 07:17:43 +00005644template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005645StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005646TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005647 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005648 if (S->getThrowExpr()) {
5649 Operand = getDerived().TransformExpr(S->getThrowExpr());
5650 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005651 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005652 }
Sean Huntc3021132010-05-05 15:23:54 +00005653
Douglas Gregord1377b22010-04-22 21:44:01 +00005654 if (!getDerived().AlwaysRebuild() &&
5655 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005656 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005657
John McCall9ae2f072010-08-23 23:25:46 +00005658 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005659}
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005662StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005663TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005664 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005665 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005666 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005667 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005668 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005669 Object =
5670 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5671 Object.get());
5672 if (Object.isInvalid())
5673 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005674
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005675 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005676 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005677 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005679
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005680 // If nothing change, just retain the current statement.
5681 if (!getDerived().AlwaysRebuild() &&
5682 Object.get() == S->getSynchExpr() &&
5683 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005684 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005685
5686 // Build a new statement.
5687 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005688 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005689}
5690
5691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005693TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5694 ObjCAutoreleasePoolStmt *S) {
5695 // Transform the body.
5696 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5697 if (Body.isInvalid())
5698 return StmtError();
5699
5700 // If nothing changed, just retain this statement.
5701 if (!getDerived().AlwaysRebuild() &&
5702 Body.get() == S->getSubStmt())
5703 return SemaRef.Owned(S);
5704
5705 // Build a new statement.
5706 return getDerived().RebuildObjCAutoreleasePoolStmt(
5707 S->getAtLoc(), Body.get());
5708}
5709
5710template<typename Derived>
5711StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005712TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005713 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005714 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005715 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005716 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005717 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005718
Douglas Gregorc3203e72010-04-22 23:10:45 +00005719 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005720 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005721 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005723 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5724 Collection.take());
5725 if (Collection.isInvalid())
5726 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005727
Douglas Gregorc3203e72010-04-22 23:10:45 +00005728 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005729 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005730 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005732
Douglas Gregorc3203e72010-04-22 23:10:45 +00005733 // If nothing changed, just retain this statement.
5734 if (!getDerived().AlwaysRebuild() &&
5735 Element.get() == S->getElement() &&
5736 Collection.get() == S->getCollection() &&
5737 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005738 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005739
Douglas Gregorc3203e72010-04-22 23:10:45 +00005740 // Build a new statement.
5741 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5742 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005743 Element.get(),
5744 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005745 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005746 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005747}
5748
5749
5750template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005751StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005752TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5753 // Transform the exception declaration, if any.
5754 VarDecl *Var = 0;
5755 if (S->getExceptionDecl()) {
5756 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005757 TypeSourceInfo *T = getDerived().TransformType(
5758 ExceptionDecl->getTypeSourceInfo());
5759 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005760 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005761
Douglas Gregor83cb9422010-09-09 17:09:21 +00005762 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005763 ExceptionDecl->getInnerLocStart(),
5764 ExceptionDecl->getLocation(),
5765 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005766 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005767 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005768 }
Mike Stump1eb44332009-09-09 15:08:12 +00005769
Douglas Gregor43959a92009-08-20 07:17:43 +00005770 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005771 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005772 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005773 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005774
Douglas Gregor43959a92009-08-20 07:17:43 +00005775 if (!getDerived().AlwaysRebuild() &&
5776 !Var &&
5777 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005778 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005779
5780 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5781 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005782 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005783}
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregor43959a92009-08-20 07:17:43 +00005785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005786StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005787TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5788 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005790 = getDerived().TransformCompoundStmt(S->getTryBlock());
5791 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregor43959a92009-08-20 07:17:43 +00005794 // Transform the handlers.
5795 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005796 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005797 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005799 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5800 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005801 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005802
Douglas Gregor43959a92009-08-20 07:17:43 +00005803 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5804 Handlers.push_back(Handler.takeAs<Stmt>());
5805 }
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregor43959a92009-08-20 07:17:43 +00005807 if (!getDerived().AlwaysRebuild() &&
5808 TryBlock.get() == S->getTryBlock() &&
5809 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005810 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005811
John McCall9ae2f072010-08-23 23:25:46 +00005812 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005813 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005814}
Mike Stump1eb44332009-09-09 15:08:12 +00005815
Richard Smithad762fc2011-04-14 22:09:26 +00005816template<typename Derived>
5817StmtResult
5818TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5819 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5820 if (Range.isInvalid())
5821 return StmtError();
5822
5823 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5824 if (BeginEnd.isInvalid())
5825 return StmtError();
5826
5827 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5828 if (Cond.isInvalid())
5829 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005830 if (Cond.get())
5831 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5832 if (Cond.isInvalid())
5833 return StmtError();
5834 if (Cond.get())
5835 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005836
5837 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5838 if (Inc.isInvalid())
5839 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005840 if (Inc.get())
5841 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005842
5843 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5844 if (LoopVar.isInvalid())
5845 return StmtError();
5846
5847 StmtResult NewStmt = S;
5848 if (getDerived().AlwaysRebuild() ||
5849 Range.get() != S->getRangeStmt() ||
5850 BeginEnd.get() != S->getBeginEndStmt() ||
5851 Cond.get() != S->getCond() ||
5852 Inc.get() != S->getInc() ||
5853 LoopVar.get() != S->getLoopVarStmt())
5854 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5855 S->getColonLoc(), Range.get(),
5856 BeginEnd.get(), Cond.get(),
5857 Inc.get(), LoopVar.get(),
5858 S->getRParenLoc());
5859
5860 StmtResult Body = getDerived().TransformStmt(S->getBody());
5861 if (Body.isInvalid())
5862 return StmtError();
5863
5864 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5865 // it now so we have a new statement to attach the body to.
5866 if (Body.get() != S->getBody() && NewStmt.get() == S)
5867 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5868 S->getColonLoc(), Range.get(),
5869 BeginEnd.get(), Cond.get(),
5870 Inc.get(), LoopVar.get(),
5871 S->getRParenLoc());
5872
5873 if (NewStmt.get() == S)
5874 return SemaRef.Owned(S);
5875
5876 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5877}
5878
John Wiegley28bbe4b2011-04-28 01:08:34 +00005879template<typename Derived>
5880StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005881TreeTransform<Derived>::TransformMSDependentExistsStmt(
5882 MSDependentExistsStmt *S) {
5883 // Transform the nested-name-specifier, if any.
5884 NestedNameSpecifierLoc QualifierLoc;
5885 if (S->getQualifierLoc()) {
5886 QualifierLoc
5887 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5888 if (!QualifierLoc)
5889 return StmtError();
5890 }
5891
5892 // Transform the declaration name.
5893 DeclarationNameInfo NameInfo = S->getNameInfo();
5894 if (NameInfo.getName()) {
5895 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5896 if (!NameInfo.getName())
5897 return StmtError();
5898 }
5899
5900 // Check whether anything changed.
5901 if (!getDerived().AlwaysRebuild() &&
5902 QualifierLoc == S->getQualifierLoc() &&
5903 NameInfo.getName() == S->getNameInfo().getName())
5904 return S;
5905
5906 // Determine whether this name exists, if we can.
5907 CXXScopeSpec SS;
5908 SS.Adopt(QualifierLoc);
5909 bool Dependent = false;
5910 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5911 case Sema::IER_Exists:
5912 if (S->isIfExists())
5913 break;
5914
5915 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5916
5917 case Sema::IER_DoesNotExist:
5918 if (S->isIfNotExists())
5919 break;
5920
5921 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5922
5923 case Sema::IER_Dependent:
5924 Dependent = true;
5925 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005926
5927 case Sema::IER_Error:
5928 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005929 }
5930
5931 // We need to continue with the instantiation, so do so now.
5932 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5933 if (SubStmt.isInvalid())
5934 return StmtError();
5935
5936 // If we have resolved the name, just transform to the substatement.
5937 if (!Dependent)
5938 return SubStmt;
5939
5940 // The name is still dependent, so build a dependent expression again.
5941 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5942 S->isIfExists(),
5943 QualifierLoc,
5944 NameInfo,
5945 SubStmt.get());
5946}
5947
5948template<typename Derived>
5949StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005950TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5951 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5952 if(TryBlock.isInvalid()) return StmtError();
5953
5954 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5955 if(!getDerived().AlwaysRebuild() &&
5956 TryBlock.get() == S->getTryBlock() &&
5957 Handler.get() == S->getHandler())
5958 return SemaRef.Owned(S);
5959
5960 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5961 S->getTryLoc(),
5962 TryBlock.take(),
5963 Handler.take());
5964}
5965
5966template<typename Derived>
5967StmtResult
5968TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5969 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5970 if(Block.isInvalid()) return StmtError();
5971
5972 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5973 Block.take());
5974}
5975
5976template<typename Derived>
5977StmtResult
5978TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5979 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5980 if(FilterExpr.isInvalid()) return StmtError();
5981
5982 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5983 if(Block.isInvalid()) return StmtError();
5984
5985 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5986 FilterExpr.take(),
5987 Block.take());
5988}
5989
5990template<typename Derived>
5991StmtResult
5992TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5993 if(isa<SEHFinallyStmt>(Handler))
5994 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5995 else
5996 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5997}
5998
Douglas Gregor43959a92009-08-20 07:17:43 +00005999//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000// Expression transformation
6001//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006003ExprResult
John McCall454feb92009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006005 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006}
Mike Stump1eb44332009-09-09 15:08:12 +00006007
6008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009ExprResult
John McCall454feb92009-12-08 09:21:05 +00006010TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006011 NestedNameSpecifierLoc QualifierLoc;
6012 if (E->getQualifierLoc()) {
6013 QualifierLoc
6014 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6015 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006016 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006017 }
John McCalldbd872f2009-12-08 09:08:17 +00006018
6019 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006020 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6021 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006024
John McCallec8045d2010-08-17 21:27:17 +00006025 DeclarationNameInfo NameInfo = E->getNameInfo();
6026 if (NameInfo.getName()) {
6027 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6028 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006029 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006030 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006031
6032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006033 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006034 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006035 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006036 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006037
6038 // Mark it referenced in the new context regardless.
6039 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006040 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006041
John McCall3fa5cae2010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006043 }
John McCalldbd872f2009-12-08 09:08:17 +00006044
6045 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006046 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006047 TemplateArgs = &TransArgs;
6048 TransArgs.setLAngleLoc(E->getLAngleLoc());
6049 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006050 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6051 E->getNumTemplateArgs(),
6052 TransArgs))
6053 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006054 }
6055
Douglas Gregor40d96a62011-02-28 21:54:11 +00006056 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6057 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058}
Mike Stump1eb44332009-09-09 15:08:12 +00006059
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006061ExprResult
John McCall454feb92009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006063 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064}
Mike Stump1eb44332009-09-09 15:08:12 +00006065
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006067ExprResult
John McCall454feb92009-12-08 09:21:05 +00006068TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006069 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070}
Mike Stump1eb44332009-09-09 15:08:12 +00006071
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006073ExprResult
John McCall454feb92009-12-08 09:21:05 +00006074TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006075 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076}
Mike Stump1eb44332009-09-09 15:08:12 +00006077
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006079ExprResult
John McCall454feb92009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006081 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006082}
Mike Stump1eb44332009-09-09 15:08:12 +00006083
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006085ExprResult
John McCall454feb92009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006087 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006088}
6089
6090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006091ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006092TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6093 return SemaRef.MaybeBindToTemporary(E);
6094}
6095
6096template<typename Derived>
6097ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006098TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6099 ExprResult ControllingExpr =
6100 getDerived().TransformExpr(E->getControllingExpr());
6101 if (ControllingExpr.isInvalid())
6102 return ExprError();
6103
Chris Lattner686775d2011-07-20 06:58:45 +00006104 SmallVector<Expr *, 4> AssocExprs;
6105 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006106 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6107 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6108 if (TS) {
6109 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6110 if (!AssocType)
6111 return ExprError();
6112 AssocTypes.push_back(AssocType);
6113 } else {
6114 AssocTypes.push_back(0);
6115 }
6116
6117 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6118 if (AssocExpr.isInvalid())
6119 return ExprError();
6120 AssocExprs.push_back(AssocExpr.release());
6121 }
6122
6123 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6124 E->getDefaultLoc(),
6125 E->getRParenLoc(),
6126 ControllingExpr.release(),
6127 AssocTypes.data(),
6128 AssocExprs.data(),
6129 E->getNumAssocs());
6130}
6131
6132template<typename Derived>
6133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006135 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006137 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006140 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006141
John McCall9ae2f072010-08-23 23:25:46 +00006142 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 E->getRParen());
6144}
6145
Mike Stump1eb44332009-09-09 15:08:12 +00006146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
John McCall454feb92009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006149 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006151 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6157 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006158 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159}
Mike Stump1eb44332009-09-09 15:08:12 +00006160
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006162ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006163TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6164 // Transform the type.
6165 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6166 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006167 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006168
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006169 // Transform all of the components into components similar to what the
6170 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006171 // FIXME: It would be slightly more efficient in the non-dependent case to
6172 // just map FieldDecls, rather than requiring the rebuilder to look for
6173 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006174 // template code that we don't care.
6175 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006176 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006177 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006178 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006179 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6180 const Node &ON = E->getComponent(I);
6181 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006182 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006183 Comp.LocStart = ON.getSourceRange().getBegin();
6184 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006185 switch (ON.getKind()) {
6186 case Node::Array: {
6187 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006188 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006189 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006190 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006191
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006192 ExprChanged = ExprChanged || Index.get() != FromIndex;
6193 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006194 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006195 break;
6196 }
Sean Huntc3021132010-05-05 15:23:54 +00006197
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006198 case Node::Field:
6199 case Node::Identifier:
6200 Comp.isBrackets = false;
6201 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006202 if (!Comp.U.IdentInfo)
6203 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006204
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006205 break;
Sean Huntc3021132010-05-05 15:23:54 +00006206
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006207 case Node::Base:
6208 // Will be recomputed during the rebuild.
6209 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006210 }
Sean Huntc3021132010-05-05 15:23:54 +00006211
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006212 Components.push_back(Comp);
6213 }
Sean Huntc3021132010-05-05 15:23:54 +00006214
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006215 // If nothing changed, retain the existing expression.
6216 if (!getDerived().AlwaysRebuild() &&
6217 Type == E->getTypeSourceInfo() &&
6218 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006219 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006220
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006221 // Build a new offsetof expression.
6222 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6223 Components.data(), Components.size(),
6224 E->getRParenLoc());
6225}
6226
6227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006228ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006229TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6230 assert(getDerived().AlreadyTransformed(E->getType()) &&
6231 "opaque value expression requires transformation");
6232 return SemaRef.Owned(E);
6233}
6234
6235template<typename Derived>
6236ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006237TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006238 // Rebuild the syntactic form. The original syntactic form has
6239 // opaque-value expressions in it, so strip those away and rebuild
6240 // the result. This is a really awful way of doing this, but the
6241 // better solution (rebuilding the semantic expressions and
6242 // rebinding OVEs as necessary) doesn't work; we'd need
6243 // TreeTransform to not strip away implicit conversions.
6244 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6245 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006246 if (result.isInvalid()) return ExprError();
6247
6248 // If that gives us a pseudo-object result back, the pseudo-object
6249 // expression must have been an lvalue-to-rvalue conversion which we
6250 // should reapply.
6251 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6252 result = SemaRef.checkPseudoObjectRValue(result.take());
6253
6254 return result;
6255}
6256
6257template<typename Derived>
6258ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006259TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6260 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006261 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006262 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006263
John McCalla93c9342009-12-07 02:54:59 +00006264 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006265 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006267
John McCall5ab75172009-11-04 07:28:41 +00006268 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006269 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006270
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006271 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6272 E->getKind(),
6273 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274 }
Mike Stump1eb44332009-09-09 15:08:12 +00006275
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006276 // C++0x [expr.sizeof]p1:
6277 // The operand is either an expression, which is an unevaluated operand
6278 // [...]
6279 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006280
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006281 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6282 if (SubExpr.isInvalid())
6283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006284
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006285 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6286 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006287
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006288 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6289 E->getOperatorLoc(),
6290 E->getKind(),
6291 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292}
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006295ExprResult
John McCall454feb92009-12-08 09:21:05 +00006296TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006297 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006300
John McCall60d7b3a2010-08-24 06:29:42 +00006301 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006303 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006304
6305
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306 if (!getDerived().AlwaysRebuild() &&
6307 LHS.get() == E->getLHS() &&
6308 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006309 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006310
John McCall9ae2f072010-08-23 23:25:46 +00006311 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006313 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 E->getRBracketLoc());
6315}
Mike Stump1eb44332009-09-09 15:08:12 +00006316
6317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006318ExprResult
John McCall454feb92009-12-08 09:21:05 +00006319TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006321 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006323 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324
6325 // Transform arguments.
6326 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006327 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006328 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6329 &ArgChanged))
6330 return ExprError();
6331
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332 if (!getDerived().AlwaysRebuild() &&
6333 Callee.get() == E->getCallee() &&
6334 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006335 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006338 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006340 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 E->getRParenLoc());
6343}
Mike Stump1eb44332009-09-09 15:08:12 +00006344
6345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006346ExprResult
John McCall454feb92009-12-08 09:21:05 +00006347TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006348 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Douglas Gregor40d96a62011-02-28 21:54:11 +00006352 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006353 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006354 QualifierLoc
6355 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6356
6357 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006358 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006359 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006360 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Eli Friedmanf595cc42009-12-04 06:40:45 +00006362 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006363 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6364 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006367
John McCall6bb80172010-03-30 21:47:33 +00006368 NamedDecl *FoundDecl = E->getFoundDecl();
6369 if (FoundDecl == E->getMemberDecl()) {
6370 FoundDecl = Member;
6371 } else {
6372 FoundDecl = cast_or_null<NamedDecl>(
6373 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6374 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006375 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006376 }
6377
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 if (!getDerived().AlwaysRebuild() &&
6379 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006380 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006381 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006382 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006383 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006384
Anders Carlsson1f240322009-12-22 05:24:09 +00006385 // Mark it referenced in the new context regardless.
6386 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006387 SemaRef.MarkMemberReferenced(E);
6388
John McCall3fa5cae2010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006390 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391
John McCalld5532b62009-11-23 01:53:49 +00006392 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006393 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006394 TransArgs.setLAngleLoc(E->getLAngleLoc());
6395 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006396 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6397 E->getNumTemplateArgs(),
6398 TransArgs))
6399 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006400 }
Sean Huntc3021132010-05-05 15:23:54 +00006401
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 // FIXME: Bogus source location for the operator
6403 SourceLocation FakeOperatorLoc
6404 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6405
John McCallc2233c52010-01-15 08:34:02 +00006406 // FIXME: to do this check properly, we will need to preserve the
6407 // first-qualifier-in-scope here, just in case we had a dependent
6408 // base (and therefore couldn't do the check) and a
6409 // nested-name-qualifier (and therefore could do the lookup).
6410 NamedDecl *FirstQualifierInScope = 0;
6411
John McCall9ae2f072010-08-23 23:25:46 +00006412 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006414 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006415 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006416 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006417 Member,
John McCall6bb80172010-03-30 21:47:33 +00006418 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006419 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006420 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006421 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422}
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006425ExprResult
John McCall454feb92009-12-08 09:21:05 +00006426TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006427 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006430
John McCall60d7b3a2010-08-24 06:29:42 +00006431 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006434
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (!getDerived().AlwaysRebuild() &&
6436 LHS.get() == E->getLHS() &&
6437 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006438 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006441 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442}
6443
Mike Stump1eb44332009-09-09 15:08:12 +00006444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006445ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006447 CompoundAssignOperator *E) {
6448 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449}
Mike Stump1eb44332009-09-09 15:08:12 +00006450
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006452ExprResult TreeTransform<Derived>::
6453TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6454 // Just rebuild the common and RHS expressions and see whether we
6455 // get any changes.
6456
6457 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6458 if (commonExpr.isInvalid())
6459 return ExprError();
6460
6461 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6462 if (rhs.isInvalid())
6463 return ExprError();
6464
6465 if (!getDerived().AlwaysRebuild() &&
6466 commonExpr.get() == e->getCommon() &&
6467 rhs.get() == e->getFalseExpr())
6468 return SemaRef.Owned(e);
6469
6470 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6471 e->getQuestionLoc(),
6472 0,
6473 e->getColonLoc(),
6474 rhs.get());
6475}
6476
6477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
John McCall454feb92009-12-08 09:21:05 +00006479TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006480 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006483
John McCall60d7b3a2010-08-24 06:29:42 +00006484 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006487
John McCall60d7b3a2010-08-24 06:29:42 +00006488 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 if (!getDerived().AlwaysRebuild() &&
6493 Cond.get() == E->getCond() &&
6494 LHS.get() == E->getLHS() &&
6495 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006496 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006497
John McCall9ae2f072010-08-23 23:25:46 +00006498 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006499 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006500 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006501 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006502 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503}
Mike Stump1eb44332009-09-09 15:08:12 +00006504
6505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006506ExprResult
John McCall454feb92009-12-08 09:21:05 +00006507TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006508 // Implicit casts are eliminated during transformation, since they
6509 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006510 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511}
Mike Stump1eb44332009-09-09 15:08:12 +00006512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006514ExprResult
John McCall454feb92009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006516 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6517 if (!Type)
6518 return ExprError();
6519
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006521 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006526 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006529
John McCall9d125032010-01-15 18:39:57 +00006530 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006531 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006533 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534}
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006537ExprResult
John McCall454feb92009-12-08 09:21:05 +00006538TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006539 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6540 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6541 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006543
John McCall60d7b3a2010-08-24 06:29:42 +00006544 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006549 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006551 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552
John McCall1d7d8d62010-01-19 22:33:45 +00006553 // Note: the expression type doesn't necessarily match the
6554 // type-as-written, but that's okay, because it should always be
6555 // derivable from the initializer.
6556
John McCall42f56b52010-01-18 19:35:47 +00006557 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006559 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560}
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006565 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 if (!getDerived().AlwaysRebuild() &&
6570 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006571 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006574 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006576 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 E->getAccessorLoc(),
6578 E->getAccessor());
6579}
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006582ExprResult
John McCall454feb92009-12-08 09:21:05 +00006583TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006585
John McCallca0408f2010-08-23 06:44:23 +00006586 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006587 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6588 Inits, &InitChanged))
6589 return ExprError();
6590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006592 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006595 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006602
Douglas Gregor43959a92009-08-20 07:17:43 +00006603 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006604 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregor43959a92009-08-20 07:17:43 +00006608 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006609 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 bool ExprChanged = false;
6611 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6612 DEnd = E->designators_end();
6613 D != DEnd; ++D) {
6614 if (D->isFieldDesignator()) {
6615 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6616 D->getDotLoc(),
6617 D->getFieldLoc()));
6618 continue;
6619 }
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006622 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006625
6626 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6630 ArrayExprs.push_back(Index.release());
6631 continue;
6632 }
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006635 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6637 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
John McCall60d7b3a2010-08-24 06:29:42 +00006640 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006642 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006643
6644 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 End.get(),
6646 D->getLBracketLoc(),
6647 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6650 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 ArrayExprs.push_back(Start.release());
6653 ArrayExprs.push_back(End.release());
6654 }
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 if (!getDerived().AlwaysRebuild() &&
6657 Init.get() == E->getInit() &&
6658 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006659 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6662 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006663 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664}
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006667ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006669 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006670 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006671
Douglas Gregor5557b252009-10-28 00:29:27 +00006672 // FIXME: Will we ever have proper type location here? Will we actually
6673 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 QualType T = getDerived().TransformType(E->getType());
6675 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006676 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (!getDerived().AlwaysRebuild() &&
6679 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006680 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 return getDerived().RebuildImplicitValueInitExpr(T);
6683}
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006686ExprResult
John McCall454feb92009-12-08 09:21:05 +00006687TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006688 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6689 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006691
John McCall60d7b3a2010-08-24 06:29:42 +00006692 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006697 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006699 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006700
John McCall9ae2f072010-08-23 23:25:46 +00006701 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006702 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703}
6704
6705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006706ExprResult
John McCall454feb92009-12-08 09:21:05 +00006707TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006709 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006710 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6711 &ArgumentChanged))
6712 return ExprError();
6713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6715 move_arg(Inits),
6716 E->getRParenLoc());
6717}
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719/// \brief Transform an address-of-label expression.
6720///
6721/// By default, the transformation of an address-of-label expression always
6722/// rebuilds the expression, so that the label identifier can be resolved to
6723/// the corresponding label statement by semantic analysis.
6724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006725ExprResult
John McCall454feb92009-12-08 09:21:05 +00006726TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006727 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6728 E->getLabel());
6729 if (!LD)
6730 return ExprError();
6731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006733 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734}
Mike Stump1eb44332009-09-09 15:08:12 +00006735
6736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006737ExprResult
John McCall454feb92009-12-08 09:21:05 +00006738TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006739 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006740 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006742 if (SubStmt.isInvalid()) {
6743 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006744 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006745 }
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006748 SubStmt.get() == E->getSubStmt()) {
6749 // Calling this an 'error' is unintuitive, but it does the right thing.
6750 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006751 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006752 }
Mike Stump1eb44332009-09-09 15:08:12 +00006753
6754 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006755 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 E->getRParenLoc());
6757}
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006760ExprResult
John McCall454feb92009-12-08 09:21:05 +00006761TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006762 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006764 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006765
John McCall60d7b3a2010-08-24 06:29:42 +00006766 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006769
John McCall60d7b3a2010-08-24 06:29:42 +00006770 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006772 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 if (!getDerived().AlwaysRebuild() &&
6775 Cond.get() == E->getCond() &&
6776 LHS.get() == E->getLHS() &&
6777 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006778 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006781 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 E->getRParenLoc());
6783}
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006786ExprResult
John McCall454feb92009-12-08 09:21:05 +00006787TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006788 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789}
6790
6791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006792ExprResult
John McCall454feb92009-12-08 09:21:05 +00006793TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006794 switch (E->getOperator()) {
6795 case OO_New:
6796 case OO_Delete:
6797 case OO_Array_New:
6798 case OO_Array_Delete:
6799 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006800
Douglas Gregor668d6d92009-12-13 20:44:55 +00006801 case OO_Call: {
6802 // This is a call to an object's operator().
6803 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6804
6805 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006806 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006807 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006808 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006809
6810 // FIXME: Poor location information
6811 SourceLocation FakeLParenLoc
6812 = SemaRef.PP.getLocForEndOfToken(
6813 static_cast<Expr *>(Object.get())->getLocEnd());
6814
6815 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006816 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006817 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6818 Args))
6819 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006820
John McCall9ae2f072010-08-23 23:25:46 +00006821 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006822 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006823 E->getLocEnd());
6824 }
6825
6826#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6827 case OO_##Name:
6828#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6829#include "clang/Basic/OperatorKinds.def"
6830 case OO_Subscript:
6831 // Handled below.
6832 break;
6833
6834 case OO_Conditional:
6835 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006836
6837 case OO_None:
6838 case NUM_OVERLOADED_OPERATORS:
6839 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006840 }
6841
John McCall60d7b3a2010-08-24 06:29:42 +00006842 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006844 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006845
John McCall60d7b3a2010-08-24 06:29:42 +00006846 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006848 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849
John McCall60d7b3a2010-08-24 06:29:42 +00006850 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 if (E->getNumArgs() == 2) {
6852 Second = getDerived().TransformExpr(E->getArg(1));
6853 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006854 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 }
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (!getDerived().AlwaysRebuild() &&
6858 Callee.get() == E->getCallee() &&
6859 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006860 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006861 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6864 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006865 Callee.get(),
6866 First.get(),
6867 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868}
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006871ExprResult
John McCall454feb92009-12-08 09:21:05 +00006872TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6873 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874}
Mike Stump1eb44332009-09-09 15:08:12 +00006875
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006877ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006878TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6879 // Transform the callee.
6880 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6881 if (Callee.isInvalid())
6882 return ExprError();
6883
6884 // Transform exec config.
6885 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6886 if (EC.isInvalid())
6887 return ExprError();
6888
6889 // Transform arguments.
6890 bool ArgChanged = false;
6891 ASTOwningVector<Expr*> Args(SemaRef);
6892 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6893 &ArgChanged))
6894 return ExprError();
6895
6896 if (!getDerived().AlwaysRebuild() &&
6897 Callee.get() == E->getCallee() &&
6898 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006899 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006900
6901 // FIXME: Wrong source location information for the '('.
6902 SourceLocation FakeLParenLoc
6903 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6904 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6905 move_arg(Args),
6906 E->getRParenLoc(), EC.get());
6907}
6908
6909template<typename Derived>
6910ExprResult
John McCall454feb92009-12-08 09:21:05 +00006911TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006912 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6913 if (!Type)
6914 return ExprError();
6915
John McCall60d7b3a2010-08-24 06:29:42 +00006916 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006917 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006919 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006922 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006924 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006925
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006927 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6929 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6930 SourceLocation FakeRParenLoc
6931 = SemaRef.PP.getLocForEndOfToken(
6932 E->getSubExpr()->getSourceRange().getEnd());
6933 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006934 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006936 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 FakeRAngleLoc,
6938 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006939 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 FakeRParenLoc);
6941}
Mike Stump1eb44332009-09-09 15:08:12 +00006942
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006944ExprResult
John McCall454feb92009-12-08 09:21:05 +00006945TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6946 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947}
Mike Stump1eb44332009-09-09 15:08:12 +00006948
6949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006950ExprResult
John McCall454feb92009-12-08 09:21:05 +00006951TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6952 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006953}
6954
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>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006958 CXXReinterpretCastExpr *E) {
6959 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960}
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006963ExprResult
John McCall454feb92009-12-08 09:21:05 +00006964TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6965 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966}
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006969ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006971 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006972 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6973 if (!Type)
6974 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006975
John McCall60d7b3a2010-08-24 06:29:42 +00006976 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006977 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006980
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006982 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006986 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006988 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 E->getRParenLoc());
6990}
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006993ExprResult
John McCall454feb92009-12-08 09:21:05 +00006994TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006996 TypeSourceInfo *TInfo
6997 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6998 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007000
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007002 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007003 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007005 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7006 E->getLocStart(),
7007 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 E->getLocEnd());
7009 }
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Eli Friedmanef331b72012-01-20 01:26:23 +00007011 // We don't know whether the subexpression is potentially evaluated until
7012 // after we perform semantic analysis. We speculatively assume it is
7013 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007015 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007016
John McCall60d7b3a2010-08-24 06:29:42 +00007017 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007019 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 if (!getDerived().AlwaysRebuild() &&
7022 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007023 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007024
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007025 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7026 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007027 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 E->getLocEnd());
7029}
7030
7031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007032ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007033TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7034 if (E->isTypeOperand()) {
7035 TypeSourceInfo *TInfo
7036 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7037 if (!TInfo)
7038 return ExprError();
7039
7040 if (!getDerived().AlwaysRebuild() &&
7041 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007042 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007043
Douglas Gregor3c52a212011-03-06 17:40:41 +00007044 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007045 E->getLocStart(),
7046 TInfo,
7047 E->getLocEnd());
7048 }
7049
Francois Pichet01b7c302010-09-08 12:20:18 +00007050 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7051
7052 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7053 if (SubExpr.isInvalid())
7054 return ExprError();
7055
7056 if (!getDerived().AlwaysRebuild() &&
7057 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007058 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007059
7060 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7061 E->getLocStart(),
7062 SubExpr.get(),
7063 E->getLocEnd());
7064}
7065
7066template<typename Derived>
7067ExprResult
John McCall454feb92009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070}
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007073ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007075 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007076 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077}
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007080ExprResult
John McCall454feb92009-12-08 09:21:05 +00007081TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007082 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007083 QualType T;
7084 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7085 T = MD->getThisType(getSema().Context);
7086 else
7087 T = getSema().Context.getPointerType(
7088 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorec79d872012-02-24 17:41:38 +00007090 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7091 // Make sure that we capture 'this'.
7092 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007093 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007094 }
7095
Douglas Gregor828a1972010-01-07 23:12:05 +00007096 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097}
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007100ExprResult
John McCall454feb92009-12-08 09:21:05 +00007101TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007102 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007104 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (!getDerived().AlwaysRebuild() &&
7107 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007108 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109
Douglas Gregorbca01b42011-07-06 22:04:06 +00007110 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7111 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112}
Mike Stump1eb44332009-09-09 15:08:12 +00007113
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007115ExprResult
John McCall454feb92009-12-08 09:21:05 +00007116TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007117 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007118 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7119 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregor036aed12009-12-23 23:03:06 +00007127 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128}
Mike Stump1eb44332009-09-09 15:08:12 +00007129
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007131ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007132TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7133 CXXScalarValueInitExpr *E) {
7134 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7135 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007136 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007137
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007139 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007140 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007141
Douglas Gregorab6677e2010-09-08 00:15:04 +00007142 return getDerived().RebuildCXXScalarValueInitExpr(T,
7143 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007144 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145}
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007148ExprResult
John McCall454feb92009-12-08 09:21:05 +00007149TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007151 TypeSourceInfo *AllocTypeInfo
7152 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7153 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007155
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007157 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007159 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007160
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 // Transform the placement arguments (if any).
7162 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007163 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007164 if (getDerived().TransformExprs(E->getPlacementArgs(),
7165 E->getNumPlacementArgs(), true,
7166 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007168
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007169 // Transform the initializer (if any).
7170 Expr *OldInit = E->getInitializer();
7171 ExprResult NewInit;
7172 if (OldInit)
7173 NewInit = getDerived().TransformExpr(OldInit);
7174 if (NewInit.isInvalid())
7175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007177 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007178 FunctionDecl *OperatorNew = 0;
7179 if (E->getOperatorNew()) {
7180 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007181 getDerived().TransformDecl(E->getLocStart(),
7182 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007183 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007185 }
7186
7187 FunctionDecl *OperatorDelete = 0;
7188 if (E->getOperatorDelete()) {
7189 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007190 getDerived().TransformDecl(E->getLocStart(),
7191 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007192 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007193 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007194 }
Sean Huntc3021132010-05-05 15:23:54 +00007195
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007197 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007199 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007200 OperatorNew == E->getOperatorNew() &&
7201 OperatorDelete == E->getOperatorDelete() &&
7202 !ArgumentChanged) {
7203 // Mark any declarations we need as referenced.
7204 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007205 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007206 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007207 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007208 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007209
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007210 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007211 QualType ElementType
7212 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7213 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7214 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7215 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007216 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007217 }
7218 }
7219 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007220
John McCall3fa5cae2010-10-26 07:05:15 +00007221 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007222 }
Mike Stump1eb44332009-09-09 15:08:12 +00007223
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007224 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007225 if (!ArraySize.get()) {
7226 // If no array size was specified, but the new expression was
7227 // instantiated with an array type (e.g., "new T" where T is
7228 // instantiated with "int[4]"), extract the outer bound from the
7229 // array type as our array size. We do this with constant and
7230 // dependently-sized array types.
7231 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7232 if (!ArrayT) {
7233 // Do nothing
7234 } else if (const ConstantArrayType *ConsArrayT
7235 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007236 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007237 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7238 ConsArrayT->getSize(),
7239 SemaRef.Context.getSizeType(),
7240 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007241 AllocType = ConsArrayT->getElementType();
7242 } else if (const DependentSizedArrayType *DepArrayT
7243 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7244 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007245 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007246 AllocType = DepArrayT->getElementType();
7247 }
7248 }
7249 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007250
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7252 E->isGlobalNew(),
7253 /*FIXME:*/E->getLocStart(),
7254 move_arg(PlacementArgs),
7255 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007256 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007258 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007259 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007260 E->getDirectInitRange(),
7261 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262}
Mike Stump1eb44332009-09-09 15:08:12 +00007263
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007265ExprResult
John McCall454feb92009-12-08 09:21:05 +00007266TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007267 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007269 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Douglas Gregor1af74512010-02-26 00:38:10 +00007271 // Transform the delete operator, if known.
7272 FunctionDecl *OperatorDelete = 0;
7273 if (E->getOperatorDelete()) {
7274 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007275 getDerived().TransformDecl(E->getLocStart(),
7276 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007277 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007279 }
Sean Huntc3021132010-05-05 15:23:54 +00007280
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 Operand.get() == E->getArgument() &&
7283 OperatorDelete == E->getOperatorDelete()) {
7284 // Mark any declarations we need as referenced.
7285 // FIXME: instantiation-specific.
7286 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007287 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007288
7289 if (!E->getArgument()->isTypeDependent()) {
7290 QualType Destroyed = SemaRef.Context.getBaseElementType(
7291 E->getDestroyedType());
7292 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7293 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007294 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7295 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007296 }
7297 }
7298
John McCall3fa5cae2010-10-26 07:05:15 +00007299 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007300 }
Mike Stump1eb44332009-09-09 15:08:12 +00007301
Douglas Gregorb98b1992009-08-11 05:31:07 +00007302 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7303 E->isGlobalDelete(),
7304 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007305 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306}
Mike Stump1eb44332009-09-09 15:08:12 +00007307
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007309ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007310TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007311 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007312 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007313 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007314 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007315
John McCallb3d87482010-08-24 05:47:05 +00007316 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007317 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007318 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007319 E->getOperatorLoc(),
7320 E->isArrow()? tok::arrow : tok::period,
7321 ObjectTypePtr,
7322 MayBePseudoDestructor);
7323 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007324 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007325
John McCallb3d87482010-08-24 05:47:05 +00007326 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007327 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7328 if (QualifierLoc) {
7329 QualifierLoc
7330 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7331 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007332 return ExprError();
7333 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007334 CXXScopeSpec SS;
7335 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007336
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007337 PseudoDestructorTypeStorage Destroyed;
7338 if (E->getDestroyedTypeInfo()) {
7339 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007340 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007341 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007342 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007343 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007344 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007345 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007346 // We aren't likely to be able to resolve the identifier down to a type
7347 // now anyway, so just retain the identifier.
7348 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7349 E->getDestroyedTypeLoc());
7350 } else {
7351 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007352 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007353 *E->getDestroyedTypeIdentifier(),
7354 E->getDestroyedTypeLoc(),
7355 /*Scope=*/0,
7356 SS, ObjectTypePtr,
7357 false);
7358 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007359 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007360
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007361 Destroyed
7362 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7363 E->getDestroyedTypeLoc());
7364 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007365
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007366 TypeSourceInfo *ScopeTypeInfo = 0;
7367 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007368 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007369 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007370 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007371 }
Sean Huntc3021132010-05-05 15:23:54 +00007372
John McCall9ae2f072010-08-23 23:25:46 +00007373 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007374 E->getOperatorLoc(),
7375 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007376 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007377 ScopeTypeInfo,
7378 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007379 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007380 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007381}
Mike Stump1eb44332009-09-09 15:08:12 +00007382
Douglas Gregora71d8192009-09-04 17:36:40 +00007383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007384ExprResult
John McCallba135432009-11-21 08:51:07 +00007385TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007386 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007387 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7388 Sema::LookupOrdinaryName);
7389
7390 // Transform all the decls.
7391 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7392 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007393 NamedDecl *InstD = static_cast<NamedDecl*>(
7394 getDerived().TransformDecl(Old->getNameLoc(),
7395 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007396 if (!InstD) {
7397 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7398 // This can happen because of dependent hiding.
7399 if (isa<UsingShadowDecl>(*I))
7400 continue;
7401 else
John McCallf312b1e2010-08-26 23:41:50 +00007402 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007403 }
John McCallf7a1a742009-11-24 19:00:30 +00007404
7405 // Expand using declarations.
7406 if (isa<UsingDecl>(InstD)) {
7407 UsingDecl *UD = cast<UsingDecl>(InstD);
7408 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7409 E = UD->shadow_end(); I != E; ++I)
7410 R.addDecl(*I);
7411 continue;
7412 }
7413
7414 R.addDecl(InstD);
7415 }
7416
7417 // Resolve a kind, but don't do any further analysis. If it's
7418 // ambiguous, the callee needs to deal with it.
7419 R.resolveKind();
7420
7421 // Rebuild the nested-name qualifier, if present.
7422 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007423 if (Old->getQualifierLoc()) {
7424 NestedNameSpecifierLoc QualifierLoc
7425 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7426 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007427 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007428
Douglas Gregor4c9be892011-02-28 20:01:57 +00007429 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007430 }
7431
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007432 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007433 CXXRecordDecl *NamingClass
7434 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7435 Old->getNameLoc(),
7436 Old->getNamingClass()));
7437 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007438 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007439
Douglas Gregor66c45152010-04-27 16:10:10 +00007440 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007441 }
7442
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007443 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7444
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007445 // If we have neither explicit template arguments, nor the template keyword,
7446 // it's a normal declaration name.
7447 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007448 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7449
7450 // If we have template arguments, rebuild them, then rebuild the
7451 // templateid expression.
7452 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007453 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7454 Old->getNumTemplateArgs(),
7455 TransArgs))
7456 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007457
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007458 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007459 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007460}
Mike Stump1eb44332009-09-09 15:08:12 +00007461
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007463ExprResult
John McCall454feb92009-12-08 09:21:05 +00007464TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007465 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7466 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007467 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007468
Douglas Gregorb98b1992009-08-11 05:31:07 +00007469 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007470 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007471 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007472
Mike Stump1eb44332009-09-09 15:08:12 +00007473 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007474 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007475 T,
7476 E->getLocEnd());
7477}
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007480ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007481TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7482 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7483 if (!LhsT)
7484 return ExprError();
7485
7486 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7487 if (!RhsT)
7488 return ExprError();
7489
7490 if (!getDerived().AlwaysRebuild() &&
7491 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7492 return SemaRef.Owned(E);
7493
7494 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7495 E->getLocStart(),
7496 LhsT, RhsT,
7497 E->getLocEnd());
7498}
7499
7500template<typename Derived>
7501ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007502TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7503 bool ArgChanged = false;
7504 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7505 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7506 TypeSourceInfo *From = E->getArg(I);
7507 TypeLoc FromTL = From->getTypeLoc();
7508 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7509 TypeLocBuilder TLB;
7510 TLB.reserve(FromTL.getFullDataSize());
7511 QualType To = getDerived().TransformType(TLB, FromTL);
7512 if (To.isNull())
7513 return ExprError();
7514
7515 if (To == From->getType())
7516 Args.push_back(From);
7517 else {
7518 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7519 ArgChanged = true;
7520 }
7521 continue;
7522 }
7523
7524 ArgChanged = true;
7525
7526 // We have a pack expansion. Instantiate it.
7527 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7528 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7529 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7530 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7531
7532 // Determine whether the set of unexpanded parameter packs can and should
7533 // be expanded.
7534 bool Expand = true;
7535 bool RetainExpansion = false;
7536 llvm::Optional<unsigned> OrigNumExpansions
7537 = ExpansionTL.getTypePtr()->getNumExpansions();
7538 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7539 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7540 PatternTL.getSourceRange(),
7541 Unexpanded,
7542 Expand, RetainExpansion,
7543 NumExpansions))
7544 return ExprError();
7545
7546 if (!Expand) {
7547 // The transform has determined that we should perform a simple
7548 // transformation on the pack expansion, producing another pack
7549 // expansion.
7550 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7551
7552 TypeLocBuilder TLB;
7553 TLB.reserve(From->getTypeLoc().getFullDataSize());
7554
7555 QualType To = getDerived().TransformType(TLB, PatternTL);
7556 if (To.isNull())
7557 return ExprError();
7558
7559 To = getDerived().RebuildPackExpansionType(To,
7560 PatternTL.getSourceRange(),
7561 ExpansionTL.getEllipsisLoc(),
7562 NumExpansions);
7563 if (To.isNull())
7564 return ExprError();
7565
7566 PackExpansionTypeLoc ToExpansionTL
7567 = TLB.push<PackExpansionTypeLoc>(To);
7568 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7569 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7570 continue;
7571 }
7572
7573 // Expand the pack expansion by substituting for each argument in the
7574 // pack(s).
7575 for (unsigned I = 0; I != *NumExpansions; ++I) {
7576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7577 TypeLocBuilder TLB;
7578 TLB.reserve(PatternTL.getFullDataSize());
7579 QualType To = getDerived().TransformType(TLB, PatternTL);
7580 if (To.isNull())
7581 return ExprError();
7582
7583 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7584 }
7585
7586 if (!RetainExpansion)
7587 continue;
7588
7589 // If we're supposed to retain a pack expansion, do so by temporarily
7590 // forgetting the partially-substituted parameter pack.
7591 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7592
7593 TypeLocBuilder TLB;
7594 TLB.reserve(From->getTypeLoc().getFullDataSize());
7595
7596 QualType To = getDerived().TransformType(TLB, PatternTL);
7597 if (To.isNull())
7598 return ExprError();
7599
7600 To = getDerived().RebuildPackExpansionType(To,
7601 PatternTL.getSourceRange(),
7602 ExpansionTL.getEllipsisLoc(),
7603 NumExpansions);
7604 if (To.isNull())
7605 return ExprError();
7606
7607 PackExpansionTypeLoc ToExpansionTL
7608 = TLB.push<PackExpansionTypeLoc>(To);
7609 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7610 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7611 }
7612
7613 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7614 return SemaRef.Owned(E);
7615
7616 return getDerived().RebuildTypeTrait(E->getTrait(),
7617 E->getLocStart(),
7618 Args,
7619 E->getLocEnd());
7620}
7621
7622template<typename Derived>
7623ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007624TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7625 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7626 if (!T)
7627 return ExprError();
7628
7629 if (!getDerived().AlwaysRebuild() &&
7630 T == E->getQueriedTypeSourceInfo())
7631 return SemaRef.Owned(E);
7632
7633 ExprResult SubExpr;
7634 {
7635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7636 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7637 if (SubExpr.isInvalid())
7638 return ExprError();
7639
7640 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7641 return SemaRef.Owned(E);
7642 }
7643
7644 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7645 E->getLocStart(),
7646 T,
7647 SubExpr.get(),
7648 E->getLocEnd());
7649}
7650
7651template<typename Derived>
7652ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007653TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7654 ExprResult SubExpr;
7655 {
7656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7657 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7658 if (SubExpr.isInvalid())
7659 return ExprError();
7660
7661 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7662 return SemaRef.Owned(E);
7663 }
7664
7665 return getDerived().RebuildExpressionTrait(
7666 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7667}
7668
7669template<typename Derived>
7670ExprResult
John McCall865d4472009-11-19 22:55:06 +00007671TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007672 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007673 NestedNameSpecifierLoc QualifierLoc
7674 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7675 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007676 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007677 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007678
John McCall43fed0d2010-11-12 08:19:04 +00007679 // TODO: If this is a conversion-function-id, verify that the
7680 // destination type name (if present) resolves the same way after
7681 // instantiation as it did in the local scope.
7682
Abramo Bagnara25777432010-08-11 22:01:17 +00007683 DeclarationNameInfo NameInfo
7684 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7685 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007687
John McCallf7a1a742009-11-24 19:00:30 +00007688 if (!E->hasExplicitTemplateArgs()) {
7689 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007690 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007691 // Note: it is sufficient to compare the Name component of NameInfo:
7692 // if name has not changed, DNLoc has not changed either.
7693 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007694 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007695
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007696 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007697 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007698 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007699 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007700 }
John McCalld5532b62009-11-23 01:53:49 +00007701
7702 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007703 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7704 E->getNumTemplateArgs(),
7705 TransArgs))
7706 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007707
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007708 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007709 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007710 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007711 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007712}
7713
7714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007715ExprResult
John McCall454feb92009-12-08 09:21:05 +00007716TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007717 // CXXConstructExprs are always implicit, so when we have a
7718 // 1-argument construction we just transform that argument.
7719 if (E->getNumArgs() == 1 ||
7720 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7721 return getDerived().TransformExpr(E->getArg(0));
7722
Douglas Gregorb98b1992009-08-11 05:31:07 +00007723 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7724
7725 QualType T = getDerived().TransformType(E->getType());
7726 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007727 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007728
7729 CXXConstructorDecl *Constructor
7730 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007731 getDerived().TransformDecl(E->getLocStart(),
7732 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007733 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007735
Douglas Gregorb98b1992009-08-11 05:31:07 +00007736 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007737 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007738 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7739 &ArgumentChanged))
7740 return ExprError();
7741
Douglas Gregorb98b1992009-08-11 05:31:07 +00007742 if (!getDerived().AlwaysRebuild() &&
7743 T == E->getType() &&
7744 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007745 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007746 // Mark the constructor as referenced.
7747 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007748 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007749 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007750 }
Mike Stump1eb44332009-09-09 15:08:12 +00007751
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007752 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7753 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007754 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007755 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007756 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007757 E->getConstructionKind(),
7758 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007759}
Mike Stump1eb44332009-09-09 15:08:12 +00007760
Douglas Gregorb98b1992009-08-11 05:31:07 +00007761/// \brief Transform a C++ temporary-binding expression.
7762///
Douglas Gregor51326552009-12-24 18:51:59 +00007763/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7764/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007766ExprResult
John McCall454feb92009-12-08 09:21:05 +00007767TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007768 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007769}
Mike Stump1eb44332009-09-09 15:08:12 +00007770
John McCall4765fa02010-12-06 08:20:24 +00007771/// \brief Transform a C++ expression that contains cleanups that should
7772/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773///
John McCall4765fa02010-12-06 08:20:24 +00007774/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007775/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007777ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007778TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007779 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007780}
Mike Stump1eb44332009-09-09 15:08:12 +00007781
Douglas Gregorb98b1992009-08-11 05:31:07 +00007782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007783ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007785 CXXTemporaryObjectExpr *E) {
7786 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7787 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007789
Douglas Gregorb98b1992009-08-11 05:31:07 +00007790 CXXConstructorDecl *Constructor
7791 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007792 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007793 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007794 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007796
Douglas Gregorb98b1992009-08-11 05:31:07 +00007797 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007798 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007800 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7801 &ArgumentChanged))
7802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007803
Douglas Gregorb98b1992009-08-11 05:31:07 +00007804 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007805 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007807 !ArgumentChanged) {
7808 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007809 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007810 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007811 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007812
7813 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7814 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007815 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816 E->getLocEnd());
7817}
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007820ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007821TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007822 // Create the local class that will describe the lambda.
7823 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007824 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7825 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007826 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7827
7828 // Transform the type of the lambda parameters and start the definition of
7829 // the lambda itself.
7830 TypeSourceInfo *MethodTy
7831 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7832 if (!MethodTy)
7833 return ExprError();
7834
Douglas Gregorc6889e72012-02-14 22:28:59 +00007835 // Transform lambda parameters.
7836 bool Invalid = false;
7837 llvm::SmallVector<QualType, 4> ParamTypes;
7838 llvm::SmallVector<ParmVarDecl *, 4> Params;
7839 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7840 E->getCallOperator()->param_begin(),
7841 E->getCallOperator()->param_size(),
7842 0, ParamTypes, &Params))
7843 Invalid = true;
7844
Douglas Gregordfca6f52012-02-13 22:00:16 +00007845 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007846 // Note: Once a lambda mangling number and context declaration have been
7847 // assigned, they never change.
7848 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7849 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007850 CXXMethodDecl *CallOperator
7851 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7852 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007853 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007854 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007855 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7856
Douglas Gregord5387e82012-02-14 00:00:48 +00007857 // FIXME: Instantiation-specific.
7858 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7859 TSK_ImplicitInstantiation);
7860
7861 // Introduce the context of the call operator.
7862 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7863
Douglas Gregordfca6f52012-02-13 22:00:16 +00007864 // Enter the scope of the lambda.
7865 sema::LambdaScopeInfo *LSI
7866 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7867 E->getCaptureDefault(),
7868 E->hasExplicitParameters(),
7869 E->hasExplicitResultType(),
7870 E->isMutable());
7871
7872 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007873 bool FinishedExplicitCaptures = false;
7874 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7875 CEnd = E->capture_end();
7876 C != CEnd; ++C) {
7877 // When we hit the first implicit capture, tell Sema that we've finished
7878 // the list of explicit captures.
7879 if (!FinishedExplicitCaptures && C->isImplicit()) {
7880 getSema().finishLambdaExplicitCaptures(LSI);
7881 FinishedExplicitCaptures = true;
7882 }
7883
7884 // Capturing 'this' is trivial.
7885 if (C->capturesThis()) {
7886 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7887 continue;
7888 }
7889
Douglas Gregora7365242012-02-14 19:27:52 +00007890 // Determine the capture kind for Sema.
7891 Sema::TryCaptureKind Kind
7892 = C->isImplicit()? Sema::TryCapture_Implicit
7893 : C->getCaptureKind() == LCK_ByCopy
7894 ? Sema::TryCapture_ExplicitByVal
7895 : Sema::TryCapture_ExplicitByRef;
7896 SourceLocation EllipsisLoc;
7897 if (C->isPackExpansion()) {
7898 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7899 bool ShouldExpand = false;
7900 bool RetainExpansion = false;
7901 llvm::Optional<unsigned> NumExpansions;
7902 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7903 C->getLocation(),
7904 Unexpanded,
7905 ShouldExpand, RetainExpansion,
7906 NumExpansions))
7907 return ExprError();
7908
7909 if (ShouldExpand) {
7910 // The transform has determined that we should perform an expansion;
7911 // transform and capture each of the arguments.
7912 // expansion of the pattern. Do so.
7913 VarDecl *Pack = C->getCapturedVar();
7914 for (unsigned I = 0; I != *NumExpansions; ++I) {
7915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7916 VarDecl *CapturedVar
7917 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7918 Pack));
7919 if (!CapturedVar) {
7920 Invalid = true;
7921 continue;
7922 }
7923
7924 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007925 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007926 }
7927 continue;
7928 }
7929
7930 EllipsisLoc = C->getEllipsisLoc();
7931 }
7932
Douglas Gregordfca6f52012-02-13 22:00:16 +00007933 // Transform the captured variable.
7934 VarDecl *CapturedVar
7935 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7936 C->getCapturedVar()));
7937 if (!CapturedVar) {
7938 Invalid = true;
7939 continue;
7940 }
Douglas Gregora7365242012-02-14 19:27:52 +00007941
Douglas Gregordfca6f52012-02-13 22:00:16 +00007942 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007943 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007944 }
7945 if (!FinishedExplicitCaptures)
7946 getSema().finishLambdaExplicitCaptures(LSI);
7947
Douglas Gregordfca6f52012-02-13 22:00:16 +00007948
7949 // Enter a new evaluation context to insulate the lambda from any
7950 // cleanups from the enclosing full-expression.
7951 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7952
7953 if (Invalid) {
7954 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7955 /*IsInstantiation=*/true);
7956 return ExprError();
7957 }
7958
7959 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007960 StmtResult Body = getDerived().TransformStmt(E->getBody());
7961 if (Body.isInvalid()) {
7962 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7963 /*IsInstantiation=*/true);
7964 return ExprError();
7965 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007966
Douglas Gregordfca6f52012-02-13 22:00:16 +00007967 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007968 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007969}
7970
7971template<typename Derived>
7972ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007974 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007975 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7976 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007978
Douglas Gregorb98b1992009-08-11 05:31:07 +00007979 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007980 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007981 Args.reserve(E->arg_size());
7982 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7983 &ArgumentChanged))
7984 return ExprError();
7985
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007987 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007988 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007989 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007990
Douglas Gregorb98b1992009-08-11 05:31:07 +00007991 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007992 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 E->getLParenLoc(),
7994 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007995 E->getRParenLoc());
7996}
Mike Stump1eb44332009-09-09 15:08:12 +00007997
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007999ExprResult
John McCall865d4472009-11-19 22:55:06 +00008000TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008001 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008002 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008003 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008004 Expr *OldBase;
8005 QualType BaseType;
8006 QualType ObjectType;
8007 if (!E->isImplicitAccess()) {
8008 OldBase = E->getBase();
8009 Base = getDerived().TransformExpr(OldBase);
8010 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008012
John McCallaa81e162009-12-01 22:10:20 +00008013 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008014 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008015 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008016 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008017 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008018 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008019 ObjectTy,
8020 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008021 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008022 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008023
John McCallb3d87482010-08-24 05:47:05 +00008024 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008025 BaseType = ((Expr*) Base.get())->getType();
8026 } else {
8027 OldBase = 0;
8028 BaseType = getDerived().TransformType(E->getBaseType());
8029 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8030 }
Mike Stump1eb44332009-09-09 15:08:12 +00008031
Douglas Gregor6cd21982009-10-20 05:58:46 +00008032 // Transform the first part of the nested-name-specifier that qualifies
8033 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008034 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008035 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008036 E->getFirstQualifierFoundInScope(),
8037 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008038
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008039 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008040 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008041 QualifierLoc
8042 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8043 ObjectType,
8044 FirstQualifierInScope);
8045 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008046 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008047 }
Mike Stump1eb44332009-09-09 15:08:12 +00008048
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008049 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8050
John McCall43fed0d2010-11-12 08:19:04 +00008051 // TODO: If this is a conversion-function-id, verify that the
8052 // destination type name (if present) resolves the same way after
8053 // instantiation as it did in the local scope.
8054
Abramo Bagnara25777432010-08-11 22:01:17 +00008055 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008056 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008057 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008058 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008059
John McCallaa81e162009-12-01 22:10:20 +00008060 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008061 // This is a reference to a member without an explicitly-specified
8062 // template argument list. Optimize for this common case.
8063 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008064 Base.get() == OldBase &&
8065 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008066 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008067 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008068 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008069 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008070
John McCall9ae2f072010-08-23 23:25:46 +00008071 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008072 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008073 E->isArrow(),
8074 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008075 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008076 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008077 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008078 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008079 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008080 }
8081
John McCalld5532b62009-11-23 01:53:49 +00008082 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008083 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8084 E->getNumTemplateArgs(),
8085 TransArgs))
8086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008087
John McCall9ae2f072010-08-23 23:25:46 +00008088 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008089 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008090 E->isArrow(),
8091 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008092 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008093 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008094 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008095 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008096 &TransArgs);
8097}
8098
8099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008100ExprResult
John McCall454feb92009-12-08 09:21:05 +00008101TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008102 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008103 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008104 QualType BaseType;
8105 if (!Old->isImplicitAccess()) {
8106 Base = getDerived().TransformExpr(Old->getBase());
8107 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008108 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008109 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8110 Old->isArrow());
8111 if (Base.isInvalid())
8112 return ExprError();
8113 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008114 } else {
8115 BaseType = getDerived().TransformType(Old->getBaseType());
8116 }
John McCall129e2df2009-11-30 22:42:35 +00008117
Douglas Gregor4c9be892011-02-28 20:01:57 +00008118 NestedNameSpecifierLoc QualifierLoc;
8119 if (Old->getQualifierLoc()) {
8120 QualifierLoc
8121 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8122 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008123 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008124 }
8125
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008126 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8127
Abramo Bagnara25777432010-08-11 22:01:17 +00008128 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008129 Sema::LookupOrdinaryName);
8130
8131 // Transform all the decls.
8132 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8133 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008134 NamedDecl *InstD = static_cast<NamedDecl*>(
8135 getDerived().TransformDecl(Old->getMemberLoc(),
8136 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008137 if (!InstD) {
8138 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8139 // This can happen because of dependent hiding.
8140 if (isa<UsingShadowDecl>(*I))
8141 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008142 else {
8143 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008144 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008145 }
John McCall9f54ad42009-12-10 09:41:52 +00008146 }
John McCall129e2df2009-11-30 22:42:35 +00008147
8148 // Expand using declarations.
8149 if (isa<UsingDecl>(InstD)) {
8150 UsingDecl *UD = cast<UsingDecl>(InstD);
8151 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8152 E = UD->shadow_end(); I != E; ++I)
8153 R.addDecl(*I);
8154 continue;
8155 }
8156
8157 R.addDecl(InstD);
8158 }
8159
8160 R.resolveKind();
8161
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008162 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008163 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008164 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008165 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008166 Old->getMemberLoc(),
8167 Old->getNamingClass()));
8168 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008169 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008170
Douglas Gregor66c45152010-04-27 16:10:10 +00008171 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008172 }
Sean Huntc3021132010-05-05 15:23:54 +00008173
John McCall129e2df2009-11-30 22:42:35 +00008174 TemplateArgumentListInfo TransArgs;
8175 if (Old->hasExplicitTemplateArgs()) {
8176 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8177 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008178 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8179 Old->getNumTemplateArgs(),
8180 TransArgs))
8181 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008182 }
John McCallc2233c52010-01-15 08:34:02 +00008183
8184 // FIXME: to do this check properly, we will need to preserve the
8185 // first-qualifier-in-scope here, just in case we had a dependent
8186 // base (and therefore couldn't do the check) and a
8187 // nested-name-qualifier (and therefore could do the lookup).
8188 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008189
John McCall9ae2f072010-08-23 23:25:46 +00008190 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008191 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008192 Old->getOperatorLoc(),
8193 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008194 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008195 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008196 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008197 R,
8198 (Old->hasExplicitTemplateArgs()
8199 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200}
8201
8202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008203ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008204TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008205 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008206 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8207 if (SubExpr.isInvalid())
8208 return ExprError();
8209
8210 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008211 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008212
8213 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8214}
8215
8216template<typename Derived>
8217ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008218TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008219 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8220 if (Pattern.isInvalid())
8221 return ExprError();
8222
8223 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8224 return SemaRef.Owned(E);
8225
Douglas Gregor67fd1252011-01-14 21:20:45 +00008226 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8227 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008228}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008229
8230template<typename Derived>
8231ExprResult
8232TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8233 // If E is not value-dependent, then nothing will change when we transform it.
8234 // Note: This is an instantiation-centric view.
8235 if (!E->isValueDependent())
8236 return SemaRef.Owned(E);
8237
8238 // Note: None of the implementations of TryExpandParameterPacks can ever
8239 // produce a diagnostic when given only a single unexpanded parameter pack,
8240 // so
8241 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8242 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008243 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008244 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008245 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008246 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008247 ShouldExpand, RetainExpansion,
8248 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008249 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008250
Douglas Gregor089e8932011-10-10 18:59:29 +00008251 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008252 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008253
8254 NamedDecl *Pack = E->getPack();
8255 if (!ShouldExpand) {
8256 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8257 Pack));
8258 if (!Pack)
8259 return ExprError();
8260 }
8261
Douglas Gregoree8aff02011-01-04 17:33:58 +00008262
8263 // We now know the length of the parameter pack, so build a new expression
8264 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008265 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008266 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008267 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008268}
8269
Douglas Gregorbe230c32011-01-03 17:17:50 +00008270template<typename Derived>
8271ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008272TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8273 SubstNonTypeTemplateParmPackExpr *E) {
8274 // Default behavior is to do nothing with this transformation.
8275 return SemaRef.Owned(E);
8276}
8277
8278template<typename Derived>
8279ExprResult
John McCall91a57552011-07-15 05:09:51 +00008280TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8281 SubstNonTypeTemplateParmExpr *E) {
8282 // Default behavior is to do nothing with this transformation.
8283 return SemaRef.Owned(E);
8284}
8285
8286template<typename Derived>
8287ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008288TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8289 MaterializeTemporaryExpr *E) {
8290 return getDerived().TransformExpr(E->GetTemporaryExpr());
8291}
8292
8293template<typename Derived>
8294ExprResult
John McCall454feb92009-12-08 09:21:05 +00008295TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008296 return SemaRef.MaybeBindToTemporary(E);
8297}
8298
8299template<typename Derived>
8300ExprResult
8301TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008302 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008303}
8304
8305template<typename Derived>
8306ExprResult
8307TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8308 return SemaRef.MaybeBindToTemporary(E);
8309}
8310
8311template<typename Derived>
8312ExprResult
8313TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8314 // Transform each of the elements.
8315 llvm::SmallVector<Expr *, 8> Elements;
8316 bool ArgChanged = false;
8317 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8318 /*IsCall=*/false, Elements, &ArgChanged))
8319 return ExprError();
8320
8321 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8322 return SemaRef.MaybeBindToTemporary(E);
8323
8324 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8325 Elements.data(),
8326 Elements.size());
8327}
8328
8329template<typename Derived>
8330ExprResult
8331TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8332 ObjCDictionaryLiteral *E) {
8333 // Transform each of the elements.
8334 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8335 bool ArgChanged = false;
8336 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8337 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8338
8339 if (OrigElement.isPackExpansion()) {
8340 // This key/value element is a pack expansion.
8341 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8342 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8343 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8344 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8345
8346 // Determine whether the set of unexpanded parameter packs can
8347 // and should be expanded.
8348 bool Expand = true;
8349 bool RetainExpansion = false;
8350 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8351 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8352 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8353 OrigElement.Value->getLocEnd());
8354 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8355 PatternRange,
8356 Unexpanded,
8357 Expand, RetainExpansion,
8358 NumExpansions))
8359 return ExprError();
8360
8361 if (!Expand) {
8362 // The transform has determined that we should perform a simple
8363 // transformation on the pack expansion, producing another pack
8364 // expansion.
8365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8366 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8367 if (Key.isInvalid())
8368 return ExprError();
8369
8370 if (Key.get() != OrigElement.Key)
8371 ArgChanged = true;
8372
8373 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8374 if (Value.isInvalid())
8375 return ExprError();
8376
8377 if (Value.get() != OrigElement.Value)
8378 ArgChanged = true;
8379
8380 ObjCDictionaryElement Expansion = {
8381 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8382 };
8383 Elements.push_back(Expansion);
8384 continue;
8385 }
8386
8387 // Record right away that the argument was changed. This needs
8388 // to happen even if the array expands to nothing.
8389 ArgChanged = true;
8390
8391 // The transform has determined that we should perform an elementwise
8392 // expansion of the pattern. Do so.
8393 for (unsigned I = 0; I != *NumExpansions; ++I) {
8394 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8395 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8396 if (Key.isInvalid())
8397 return ExprError();
8398
8399 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8400 if (Value.isInvalid())
8401 return ExprError();
8402
8403 ObjCDictionaryElement Element = {
8404 Key.get(), Value.get(), SourceLocation(), NumExpansions
8405 };
8406
8407 // If any unexpanded parameter packs remain, we still have a
8408 // pack expansion.
8409 if (Key.get()->containsUnexpandedParameterPack() ||
8410 Value.get()->containsUnexpandedParameterPack())
8411 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8412
8413 Elements.push_back(Element);
8414 }
8415
8416 // We've finished with this pack expansion.
8417 continue;
8418 }
8419
8420 // Transform and check key.
8421 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8422 if (Key.isInvalid())
8423 return ExprError();
8424
8425 if (Key.get() != OrigElement.Key)
8426 ArgChanged = true;
8427
8428 // Transform and check value.
8429 ExprResult Value
8430 = getDerived().TransformExpr(OrigElement.Value);
8431 if (Value.isInvalid())
8432 return ExprError();
8433
8434 if (Value.get() != OrigElement.Value)
8435 ArgChanged = true;
8436
8437 ObjCDictionaryElement Element = {
8438 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8439 };
8440 Elements.push_back(Element);
8441 }
8442
8443 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8444 return SemaRef.MaybeBindToTemporary(E);
8445
8446 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8447 Elements.data(),
8448 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008449}
8450
Mike Stump1eb44332009-09-09 15:08:12 +00008451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008452ExprResult
John McCall454feb92009-12-08 09:21:05 +00008453TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008454 TypeSourceInfo *EncodedTypeInfo
8455 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8456 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008458
Douglas Gregorb98b1992009-08-11 05:31:07 +00008459 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008460 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008461 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008462
8463 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008464 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008465 E->getRParenLoc());
8466}
Mike Stump1eb44332009-09-09 15:08:12 +00008467
Douglas Gregorb98b1992009-08-11 05:31:07 +00008468template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008469ExprResult TreeTransform<Derived>::
8470TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8471 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8472 if (result.isInvalid()) return ExprError();
8473 Expr *subExpr = result.take();
8474
8475 if (!getDerived().AlwaysRebuild() &&
8476 subExpr == E->getSubExpr())
8477 return SemaRef.Owned(E);
8478
8479 return SemaRef.Owned(new(SemaRef.Context)
8480 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8481}
8482
8483template<typename Derived>
8484ExprResult TreeTransform<Derived>::
8485TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8486 TypeSourceInfo *TSInfo
8487 = getDerived().TransformType(E->getTypeInfoAsWritten());
8488 if (!TSInfo)
8489 return ExprError();
8490
8491 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8492 if (Result.isInvalid())
8493 return ExprError();
8494
8495 if (!getDerived().AlwaysRebuild() &&
8496 TSInfo == E->getTypeInfoAsWritten() &&
8497 Result.get() == E->getSubExpr())
8498 return SemaRef.Owned(E);
8499
8500 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8501 E->getBridgeKeywordLoc(), TSInfo,
8502 Result.get());
8503}
8504
8505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008506ExprResult
John McCall454feb92009-12-08 09:21:05 +00008507TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008508 // Transform arguments.
8509 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008510 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008511 Args.reserve(E->getNumArgs());
8512 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8513 &ArgChanged))
8514 return ExprError();
8515
Douglas Gregor92e986e2010-04-22 16:44:27 +00008516 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8517 // Class message: transform the receiver type.
8518 TypeSourceInfo *ReceiverTypeInfo
8519 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8520 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008521 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008522
Douglas Gregor92e986e2010-04-22 16:44:27 +00008523 // If nothing changed, just retain the existing message send.
8524 if (!getDerived().AlwaysRebuild() &&
8525 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008526 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008527
8528 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008529 SmallVector<SourceLocation, 16> SelLocs;
8530 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008531 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8532 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008533 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008534 E->getMethodDecl(),
8535 E->getLeftLoc(),
8536 move_arg(Args),
8537 E->getRightLoc());
8538 }
8539
8540 // Instance message: transform the receiver
8541 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8542 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008543 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008544 = getDerived().TransformExpr(E->getInstanceReceiver());
8545 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008546 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008547
8548 // If nothing changed, just retain the existing message send.
8549 if (!getDerived().AlwaysRebuild() &&
8550 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008551 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008552
Douglas Gregor92e986e2010-04-22 16:44:27 +00008553 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008554 SmallVector<SourceLocation, 16> SelLocs;
8555 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008556 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008557 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008558 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008559 E->getMethodDecl(),
8560 E->getLeftLoc(),
8561 move_arg(Args),
8562 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008568 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008569}
8570
Mike Stump1eb44332009-09-09 15:08:12 +00008571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008572ExprResult
John McCall454feb92009-12-08 09:21:05 +00008573TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008574 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008575}
8576
Mike Stump1eb44332009-09-09 15:08:12 +00008577template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008578ExprResult
John McCall454feb92009-12-08 09:21:05 +00008579TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008580 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008581 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008582 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008583 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008584
8585 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008586
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008587 // If nothing changed, just retain the existing expression.
8588 if (!getDerived().AlwaysRebuild() &&
8589 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008590 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008591
John McCall9ae2f072010-08-23 23:25:46 +00008592 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008593 E->getLocation(),
8594 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008595}
8596
Mike Stump1eb44332009-09-09 15:08:12 +00008597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008598ExprResult
John McCall454feb92009-12-08 09:21:05 +00008599TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008600 // 'super' and types never change. Property never changes. Just
8601 // retain the existing expression.
8602 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008603 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008604
Douglas Gregore3303542010-04-26 20:47:02 +00008605 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008606 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008607 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008608 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008609
Douglas Gregore3303542010-04-26 20:47:02 +00008610 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008611
Douglas Gregore3303542010-04-26 20:47:02 +00008612 // If nothing changed, just retain the existing expression.
8613 if (!getDerived().AlwaysRebuild() &&
8614 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008615 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008616
John McCall12f78a62010-12-02 01:19:52 +00008617 if (E->isExplicitProperty())
8618 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8619 E->getExplicitProperty(),
8620 E->getLocation());
8621
8622 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008623 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008624 E->getImplicitPropertyGetter(),
8625 E->getImplicitPropertySetter(),
8626 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008627}
8628
Mike Stump1eb44332009-09-09 15:08:12 +00008629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008631TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8632 // Transform the base expression.
8633 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8634 if (Base.isInvalid())
8635 return ExprError();
8636
8637 // Transform the key expression.
8638 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8639 if (Key.isInvalid())
8640 return ExprError();
8641
8642 // If nothing changed, just retain the existing expression.
8643 if (!getDerived().AlwaysRebuild() &&
8644 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8645 return SemaRef.Owned(E);
8646
8647 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8648 Base.get(), Key.get(),
8649 E->getAtIndexMethodDecl(),
8650 E->setAtIndexMethodDecl());
8651}
8652
8653template<typename Derived>
8654ExprResult
John McCall454feb92009-12-08 09:21:05 +00008655TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008656 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008658 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008659 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008660
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008661 // If nothing changed, just retain the existing expression.
8662 if (!getDerived().AlwaysRebuild() &&
8663 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008664 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008665
John McCall9ae2f072010-08-23 23:25:46 +00008666 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008667 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008668}
8669
Mike Stump1eb44332009-09-09 15:08:12 +00008670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008671ExprResult
John McCall454feb92009-12-08 09:21:05 +00008672TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008673 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008674 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008675 SubExprs.reserve(E->getNumSubExprs());
8676 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8677 SubExprs, &ArgumentChanged))
8678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008679
Douglas Gregorb98b1992009-08-11 05:31:07 +00008680 if (!getDerived().AlwaysRebuild() &&
8681 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008682 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008683
Douglas Gregorb98b1992009-08-11 05:31:07 +00008684 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8685 move_arg(SubExprs),
8686 E->getRParenLoc());
8687}
8688
Mike Stump1eb44332009-09-09 15:08:12 +00008689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008690ExprResult
John McCall454feb92009-12-08 09:21:05 +00008691TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008692 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008693
John McCallc6ac9c32011-02-04 18:33:18 +00008694 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8695 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8696
8697 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008698 blockScope->TheDecl->setBlockMissingReturnType(
8699 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008700
Chris Lattner686775d2011-07-20 06:58:45 +00008701 SmallVector<ParmVarDecl*, 4> params;
8702 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008703
8704 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008705 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8706 oldBlock->param_begin(),
8707 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008708 0, paramTypes, &params)) {
8709 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008710 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008711 }
John McCallc6ac9c32011-02-04 18:33:18 +00008712
8713 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008714 QualType exprResultType =
8715 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008716
8717 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008718 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008719 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008720 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008721 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008722 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008723 return ExprError();
8724 }
John McCall711c52b2011-01-05 12:14:39 +00008725
John McCallc6ac9c32011-02-04 18:33:18 +00008726 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008727 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008728 paramTypes.data(),
8729 paramTypes.size(),
8730 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008731 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008732 exprFunctionType->getExtInfo());
8733 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008734
8735 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008736 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008737 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008738
8739 if (!oldBlock->blockMissingReturnType()) {
8740 blockScope->HasImplicitReturnType = false;
8741 blockScope->ReturnType = exprResultType;
8742 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008743
John McCall711c52b2011-01-05 12:14:39 +00008744 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008745 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008746 if (body.isInvalid()) {
8747 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008748 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008749 }
John McCall711c52b2011-01-05 12:14:39 +00008750
John McCallc6ac9c32011-02-04 18:33:18 +00008751#ifndef NDEBUG
8752 // In builds with assertions, make sure that we captured everything we
8753 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008754 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8755 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8756 e = oldBlock->capture_end(); i != e; ++i) {
8757 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008758
Douglas Gregorfc921372011-05-20 15:32:55 +00008759 // Ignore parameter packs.
8760 if (isa<ParmVarDecl>(oldCapture) &&
8761 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8762 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008763
Douglas Gregorfc921372011-05-20 15:32:55 +00008764 VarDecl *newCapture =
8765 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8766 oldCapture));
8767 assert(blockScope->CaptureMap.count(newCapture));
8768 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008769 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008770 }
8771#endif
8772
8773 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8774 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008775}
8776
Mike Stump1eb44332009-09-09 15:08:12 +00008777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008778ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008779TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008780 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008781}
Eli Friedman276b0612011-10-11 02:20:01 +00008782
8783template<typename Derived>
8784ExprResult
8785TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008786 QualType RetTy = getDerived().TransformType(E->getType());
8787 bool ArgumentChanged = false;
8788 ASTOwningVector<Expr*> SubExprs(SemaRef);
8789 SubExprs.reserve(E->getNumSubExprs());
8790 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8791 SubExprs, &ArgumentChanged))
8792 return ExprError();
8793
8794 if (!getDerived().AlwaysRebuild() &&
8795 !ArgumentChanged)
8796 return SemaRef.Owned(E);
8797
8798 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8799 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008800}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008801
Douglas Gregorb98b1992009-08-11 05:31:07 +00008802//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008803// Type reconstruction
8804//===----------------------------------------------------------------------===//
8805
Mike Stump1eb44332009-09-09 15:08:12 +00008806template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008807QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8808 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008809 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008810 getDerived().getBaseEntity());
8811}
8812
Mike Stump1eb44332009-09-09 15:08:12 +00008813template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008814QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8815 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008816 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008817 getDerived().getBaseEntity());
8818}
8819
Mike Stump1eb44332009-09-09 15:08:12 +00008820template<typename Derived>
8821QualType
John McCall85737a72009-10-30 00:06:24 +00008822TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8823 bool WrittenAsLValue,
8824 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008825 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008826 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008827}
8828
8829template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008830QualType
John McCall85737a72009-10-30 00:06:24 +00008831TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8832 QualType ClassType,
8833 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008834 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008835 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008836}
8837
8838template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008839QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008840TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8841 ArrayType::ArraySizeModifier SizeMod,
8842 const llvm::APInt *Size,
8843 Expr *SizeExpr,
8844 unsigned IndexTypeQuals,
8845 SourceRange BracketsRange) {
8846 if (SizeExpr || !Size)
8847 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8848 IndexTypeQuals, BracketsRange,
8849 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008850
8851 QualType Types[] = {
8852 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8853 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8854 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008855 };
8856 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8857 QualType SizeType;
8858 for (unsigned I = 0; I != NumTypes; ++I)
8859 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8860 SizeType = Types[I];
8861 break;
8862 }
Mike Stump1eb44332009-09-09 15:08:12 +00008863
Eli Friedman01f276d2012-01-25 23:20:27 +00008864 // Note that we can return a VariableArrayType here in the case where
8865 // the element type was a dependent VariableArrayType.
8866 IntegerLiteral *ArraySize
8867 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8868 /*FIXME*/BracketsRange.getBegin());
8869 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008870 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008871 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008872}
Mike Stump1eb44332009-09-09 15:08:12 +00008873
Douglas Gregor577f75a2009-08-04 16:50:30 +00008874template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008875QualType
8876TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008877 ArrayType::ArraySizeModifier SizeMod,
8878 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008879 unsigned IndexTypeQuals,
8880 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008881 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008882 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008883}
8884
8885template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008886QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008887TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008888 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008889 unsigned IndexTypeQuals,
8890 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008891 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008892 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008893}
Mike Stump1eb44332009-09-09 15:08:12 +00008894
Douglas Gregor577f75a2009-08-04 16:50:30 +00008895template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008896QualType
8897TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008898 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008899 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008900 unsigned IndexTypeQuals,
8901 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008902 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008903 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008904 IndexTypeQuals, BracketsRange);
8905}
8906
8907template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008908QualType
8909TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008910 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008911 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008912 unsigned IndexTypeQuals,
8913 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008914 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008915 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008916 IndexTypeQuals, BracketsRange);
8917}
8918
8919template<typename Derived>
8920QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008921 unsigned NumElements,
8922 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008924 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008925}
Mike Stump1eb44332009-09-09 15:08:12 +00008926
Douglas Gregor577f75a2009-08-04 16:50:30 +00008927template<typename Derived>
8928QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8929 unsigned NumElements,
8930 SourceLocation AttributeLoc) {
8931 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8932 NumElements, true);
8933 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008934 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8935 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008936 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008937}
Mike Stump1eb44332009-09-09 15:08:12 +00008938
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008940QualType
8941TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008942 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008943 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008944 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008945}
Mike Stump1eb44332009-09-09 15:08:12 +00008946
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947template<typename Derived>
8948QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008949 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008951 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008952 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008953 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008954 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008955 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008956 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008957 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008959 getDerived().getBaseEntity(),
8960 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961}
Mike Stump1eb44332009-09-09 15:08:12 +00008962
Douglas Gregor577f75a2009-08-04 16:50:30 +00008963template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008964QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8965 return SemaRef.Context.getFunctionNoProtoType(T);
8966}
8967
8968template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008969QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8970 assert(D && "no decl found");
8971 if (D->isInvalidDecl()) return QualType();
8972
Douglas Gregor92e986e2010-04-22 16:44:27 +00008973 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008974 TypeDecl *Ty;
8975 if (isa<UsingDecl>(D)) {
8976 UsingDecl *Using = cast<UsingDecl>(D);
8977 assert(Using->isTypeName() &&
8978 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8979
8980 // A valid resolved using typename decl points to exactly one type decl.
8981 assert(++Using->shadow_begin() == Using->shadow_end());
8982 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008983
John McCalled976492009-12-04 22:46:56 +00008984 } else {
8985 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8986 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8987 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8988 }
8989
8990 return SemaRef.Context.getTypeDeclType(Ty);
8991}
8992
8993template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008994QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8995 SourceLocation Loc) {
8996 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008997}
8998
8999template<typename Derived>
9000QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9001 return SemaRef.Context.getTypeOfType(Underlying);
9002}
9003
9004template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009005QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9006 SourceLocation Loc) {
9007 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008}
9009
9010template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009011QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9012 UnaryTransformType::UTTKind UKind,
9013 SourceLocation Loc) {
9014 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9015}
9016
9017template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009019 TemplateName Template,
9020 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009021 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009022 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023}
Mike Stump1eb44332009-09-09 15:08:12 +00009024
Douglas Gregordcee1a12009-08-06 05:28:30 +00009025template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009026QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9027 SourceLocation KWLoc) {
9028 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9029}
9030
9031template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009032TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009033TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009034 bool TemplateKW,
9035 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009036 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009037 Template);
9038}
9039
9040template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009041TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009042TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9043 const IdentifierInfo &Name,
9044 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009045 QualType ObjectType,
9046 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009047 UnqualifiedId TemplateName;
9048 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009049 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009050 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009051 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009052 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009053 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009054 /*EnteringContext=*/false,
9055 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009056 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009057}
Mike Stump1eb44332009-09-09 15:08:12 +00009058
Douglas Gregorb98b1992009-08-11 05:31:07 +00009059template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009060TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009061TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009062 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009063 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009064 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009065 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009066 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009067 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009068 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009069 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009070 Sema::TemplateTy Template;
9071 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009072 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009073 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009074 /*EnteringContext=*/false,
9075 Template);
9076 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009077}
Sean Huntc3021132010-05-05 15:23:54 +00009078
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009080ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009081TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9082 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009083 Expr *OrigCallee,
9084 Expr *First,
9085 Expr *Second) {
9086 Expr *Callee = OrigCallee->IgnoreParenCasts();
9087 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009088
Douglas Gregorb98b1992009-08-11 05:31:07 +00009089 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009090 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009091 if (!First->getType()->isOverloadableType() &&
9092 !Second->getType()->isOverloadableType())
9093 return getSema().CreateBuiltinArraySubscriptExpr(First,
9094 Callee->getLocStart(),
9095 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009096 } else if (Op == OO_Arrow) {
9097 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009098 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9099 } else if (Second == 0 || isPostIncDec) {
9100 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009101 // The argument is not of overloadable type, so try to create a
9102 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009103 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009104 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009105
John McCall9ae2f072010-08-23 23:25:46 +00009106 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009107 }
9108 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009109 if (!First->getType()->isOverloadableType() &&
9110 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009111 // Neither of the arguments is an overloadable type, so try to
9112 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009113 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009114 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009115 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009116 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009118
Douglas Gregorb98b1992009-08-11 05:31:07 +00009119 return move(Result);
9120 }
9121 }
Mike Stump1eb44332009-09-09 15:08:12 +00009122
9123 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009124 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009125 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009126
John McCall9ae2f072010-08-23 23:25:46 +00009127 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009128 assert(ULE->requiresADL());
9129
9130 // FIXME: Do we have to check
9131 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009132 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009133 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009134 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009135 }
Mike Stump1eb44332009-09-09 15:08:12 +00009136
Douglas Gregorb98b1992009-08-11 05:31:07 +00009137 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009138 Expr *Args[2] = { First, Second };
9139 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009140
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141 // Create the overloaded operator invocation for unary operators.
9142 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009143 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009144 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009145 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009146 }
Mike Stump1eb44332009-09-09 15:08:12 +00009147
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009148 if (Op == OO_Subscript) {
9149 SourceLocation LBrace;
9150 SourceLocation RBrace;
9151
9152 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9153 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9154 LBrace = SourceLocation::getFromRawEncoding(
9155 NameLoc.CXXOperatorName.BeginOpNameLoc);
9156 RBrace = SourceLocation::getFromRawEncoding(
9157 NameLoc.CXXOperatorName.EndOpNameLoc);
9158 } else {
9159 LBrace = Callee->getLocStart();
9160 RBrace = OpLoc;
9161 }
9162
9163 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9164 First, Second);
9165 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009166
Douglas Gregorb98b1992009-08-11 05:31:07 +00009167 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009168 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009169 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9171 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009172 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009173
Mike Stump1eb44332009-09-09 15:08:12 +00009174 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009175}
Mike Stump1eb44332009-09-09 15:08:12 +00009176
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009178ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009179TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009180 SourceLocation OperatorLoc,
9181 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009182 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009183 TypeSourceInfo *ScopeType,
9184 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009185 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009186 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009187 QualType BaseType = Base->getType();
9188 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009189 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009190 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009191 !BaseType->getAs<PointerType>()->getPointeeType()
9192 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009193 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009194 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009195 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009196 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009197 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009198 /*FIXME?*/true);
9199 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009200
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009201 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009202 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9203 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9204 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9205 NameInfo.setNamedTypeInfo(DestroyedType);
9206
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009207 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009208
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009209 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009210 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009211 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009212 SS, TemplateKWLoc,
9213 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009214 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009215 /*TemplateArgs*/ 0);
9216}
9217
Douglas Gregor577f75a2009-08-04 16:50:30 +00009218} // end namespace clang
9219
9220#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H