blob: 8d4d934402b479e75cf8366220c358b9c1706c62 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000180
181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Sean Huntc3021132010-05-05 15:23:54 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
224 /// \param Unexpanded The set of unexpanded parameter packs within the
225 /// pattern.
226 ///
227 /// \param NumUnexpanded The number of unexpanded parameter packs in
228 /// \p Unexpanded.
229 ///
230 /// \param ShouldExpand Will be set to \c true if the transformer should
231 /// expand the corresponding pack expansions into separate arguments. When
232 /// set, \c NumExpansions must also be set.
233 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000234 /// \param RetainExpansion Whether the caller should add an unexpanded
235 /// pack expansion after all of the expanded arguments. This is used
236 /// when extending explicitly-specified template argument packs per
237 /// C++0x [temp.arg.explicit]p9.
238 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000240 /// the expanded form of the corresponding pack expansion. This is both an
241 /// input and an output parameter, which can be set by the caller if the
242 /// number of expansions is known a priori (e.g., due to a prior substitution)
243 /// and will be set by the callee when the number of expansions is known.
244 /// The callee must set this value when \c ShouldExpand is \c true; it may
245 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000246 ///
247 /// \returns true if an error occurred (e.g., because the parameter packs
248 /// are to be instantiated with arguments of different lengths), false
249 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
250 /// must be set.
251 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
252 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000253 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000255 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000256 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000257 ShouldExpand = false;
258 return false;
259 }
260
Douglas Gregord3731192011-01-10 07:32:04 +0000261 /// \brief "Forget" about the partially-substituted pack template argument,
262 /// when performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 TemplateArgument ForgetPartiallySubstitutedPack() {
267 return TemplateArgument();
268 }
269
270 /// \brief "Remember" the partially-substituted pack template argument
271 /// after performing an instantiation that must preserve the parameter pack
272 /// use.
273 ///
274 /// This routine is meant to be overridden by the template instantiator.
275 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
276
Douglas Gregor12c9c002011-01-07 16:43:16 +0000277 /// \brief Note to the derived class when a function parameter pack is
278 /// being expanded.
279 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
280
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 /// \brief Transforms the given type into another type.
282 ///
John McCalla2becad2009-10-21 00:40:46 +0000283 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000284 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000285 /// function. This is expensive, but we don't mind, because
286 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000287 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
289 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000290 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000291
John McCalla2becad2009-10-21 00:40:46 +0000292 /// \brief Transforms the given type-with-location into a new
293 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000294 ///
John McCalla2becad2009-10-21 00:40:46 +0000295 /// By default, this routine transforms a type by delegating to the
296 /// appropriate TransformXXXType to build a new type. Subclasses
297 /// may override this function (to take over all type
298 /// transformations) or some set of the TransformXXXType functions
299 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000300 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000301
302 /// \brief Transform the given type-with-location into a new
303 /// type, collecting location information in the given builder
304 /// as necessary.
305 ///
John McCall43fed0d2010-11-12 08:19:04 +0000306 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000307
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000308 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000309 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000310 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000311 /// appropriate TransformXXXStmt function to transform a specific kind of
312 /// statement or the TransformExpr() function to transform an expression.
313 /// Subclasses may override this function to transform statements using some
314 /// other mechanism.
315 ///
316 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000317 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000319 /// \brief Transform the given expression.
320 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000321 /// By default, this routine transforms an expression by delegating to the
322 /// appropriate TransformXXXExpr function to build a new expression.
323 /// Subclasses may override this function to transform expressions using some
324 /// other mechanism.
325 ///
326 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000327 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Douglas Gregoraa165f82011-01-03 19:04:46 +0000329 /// \brief Transform the given list of expressions.
330 ///
331 /// This routine transforms a list of expressions by invoking
332 /// \c TransformExpr() for each subexpression. However, it also provides
333 /// support for variadic templates by expanding any pack expansions (if the
334 /// derived class permits such expansion) along the way. When pack expansions
335 /// are present, the number of outputs may not equal the number of inputs.
336 ///
337 /// \param Inputs The set of expressions to be transformed.
338 ///
339 /// \param NumInputs The number of expressions in \c Inputs.
340 ///
341 /// \param IsCall If \c true, then this transform is being performed on
342 /// function-call arguments, and any arguments that should be dropped, will
343 /// be.
344 ///
345 /// \param Outputs The transformed input expressions will be added to this
346 /// vector.
347 ///
348 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
349 /// due to transformation.
350 ///
351 /// \returns true if an error occurred, false otherwise.
352 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000353 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000354 bool *ArgChanged = 0);
355
Douglas Gregor577f75a2009-08-04 16:50:30 +0000356 /// \brief Transform the given declaration, which is referenced from a type
357 /// or expression.
358 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000359 /// By default, acts as the identity function on declarations, unless the
360 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000361 /// may override this function to provide alternate behavior.
Douglas Gregordfca6f52012-02-13 22:00:16 +0000362 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
363 llvm::DenseMap<Decl *, Decl *>::iterator Known
364 = TransformedLocalDecls.find(D);
365 if (Known != TransformedLocalDecls.end())
366 return Known->second;
367
368 return D;
369 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000370
Douglas Gregordfca6f52012-02-13 22:00:16 +0000371 /// \brief Transform the attributes associated with the given declaration and
372 /// place them on the new declaration.
373 ///
374 /// By default, this operation does nothing. Subclasses may override this
375 /// behavior to transform attributes.
376 void transformAttrs(Decl *Old, Decl *New) { }
377
378 /// \brief Note that a local declaration has been transformed by this
379 /// transformer.
380 ///
381 /// Local declarations are typically transformed via a call to
382 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
383 /// the transformer itself has to transform the declarations. This routine
384 /// can be overridden by a subclass that keeps track of such mappings.
385 void transformedLocalDecl(Decl *Old, Decl *New) {
386 TransformedLocalDecls[Old] = New;
387 }
388
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// \brief Transform the definition of the given declaration.
390 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000391 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000392 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000393 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
394 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000395 }
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Douglas Gregor6cd21982009-10-20 05:58:46 +0000397 /// \brief Transform the given declaration, which was the first part of a
398 /// nested-name-specifier in a member access expression.
399 ///
Sean Huntc3021132010-05-05 15:23:54 +0000400 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000401 /// identifier in a nested-name-specifier of a member access expression, e.g.,
402 /// the \c T in \c x->T::member
403 ///
404 /// By default, invokes TransformDecl() to transform the declaration.
405 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000406 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
407 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000408 }
Sean Huntc3021132010-05-05 15:23:54 +0000409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000410 /// \brief Transform the given nested-name-specifier with source-location
411 /// information.
412 ///
413 /// By default, transforms all of the types and declarations within the
414 /// nested-name-specifier. Subclasses may override this function to provide
415 /// alternate behavior.
416 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
417 NestedNameSpecifierLoc NNS,
418 QualType ObjectType = QualType(),
419 NamedDecl *FirstQualifierInScope = 0);
420
Douglas Gregor81499bb2009-09-03 22:13:48 +0000421 /// \brief Transform the given declaration name.
422 ///
423 /// By default, transforms the types of conversion function, constructor,
424 /// and destructor names and then (if needed) rebuilds the declaration name.
425 /// Identifiers and selectors are returned unmodified. Sublcasses may
426 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000427 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000428 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Douglas Gregor577f75a2009-08-04 16:50:30 +0000430 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000431 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000432 /// \param SS The nested-name-specifier that qualifies the template
433 /// name. This nested-name-specifier must already have been transformed.
434 ///
435 /// \param Name The template name to transform.
436 ///
437 /// \param NameLoc The source location of the template name.
438 ///
439 /// \param ObjectType If we're translating a template name within a member
440 /// access expression, this is the type of the object whose member template
441 /// is being referenced.
442 ///
443 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
444 /// also refers to a name within the current (lexical) scope, this is the
445 /// declaration it refers to.
446 ///
447 /// By default, transforms the template name by transforming the declarations
448 /// and nested-name-specifiers that occur within the template name.
449 /// Subclasses may override this function to provide alternate behavior.
450 TemplateName TransformTemplateName(CXXScopeSpec &SS,
451 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000452 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000453 QualType ObjectType = QualType(),
454 NamedDecl *FirstQualifierInScope = 0);
455
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 /// \brief Transform the given template argument.
457 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000458 /// By default, this operation transforms the type, expression, or
459 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000460 /// new template argument from the transformed result. Subclasses may
461 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000462 ///
463 /// Returns true if there was an error.
464 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
465 TemplateArgumentLoc &Output);
466
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// \brief Transform the given set of template arguments.
468 ///
469 /// By default, this operation transforms all of the template arguments
470 /// in the input set using \c TransformTemplateArgument(), and appends
471 /// the transformed arguments to the output list.
472 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 /// Note that this overload of \c TransformTemplateArguments() is merely
474 /// a convenience function. Subclasses that wish to override this behavior
475 /// should override the iterator-based member template version.
476 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000477 /// \param Inputs The set of template arguments to be transformed.
478 ///
479 /// \param NumInputs The number of template arguments in \p Inputs.
480 ///
481 /// \param Outputs The set of transformed template arguments output by this
482 /// routine.
483 ///
484 /// Returns true if an error occurred.
485 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
486 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000487 TemplateArgumentListInfo &Outputs) {
488 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
489 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000490
491 /// \brief Transform the given set of template arguments.
492 ///
493 /// By default, this operation transforms all of the template arguments
494 /// in the input set using \c TransformTemplateArgument(), and appends
495 /// the transformed arguments to the output list.
496 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000497 /// \param First An iterator to the first template argument.
498 ///
499 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 ///
501 /// \param Outputs The set of transformed template arguments output by this
502 /// routine.
503 ///
504 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000505 template<typename InputIterator>
506 bool TransformTemplateArguments(InputIterator First,
507 InputIterator Last,
508 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000509
John McCall833ca992009-10-29 08:12:44 +0000510 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
511 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
512 TemplateArgumentLoc &ArgLoc);
513
John McCalla93c9342009-12-07 02:54:59 +0000514 /// \brief Fakes up a TypeSourceInfo for a type.
515 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
516 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000517 getDerived().getBaseLocation());
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
John McCalla2becad2009-10-21 00:40:46 +0000520#define ABSTRACT_TYPELOC(CLASS, PARENT)
521#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000522 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000523#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000524
John Wiegley28bbe4b2011-04-28 01:08:34 +0000525 StmtResult
526 TransformSEHHandler(Stmt *Handler);
527
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType
529 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
530 TemplateSpecializationTypeLoc TL,
531 TemplateName Template);
532
533 QualType
534 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
535 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000536 TemplateName Template,
537 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000538
539 QualType
540 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000541 DependentTemplateSpecializationTypeLoc TL,
542 NestedNameSpecifierLoc QualifierLoc);
543
John McCall21ef0fa2010-03-11 09:03:00 +0000544 /// \brief Transforms the parameters of a function type into the
545 /// given vectors.
546 ///
547 /// The result vectors should be kept in sync; null entries in the
548 /// variables vector are acceptable.
549 ///
550 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000551 bool TransformFunctionTypeParams(SourceLocation Loc,
552 ParmVarDecl **Params, unsigned NumParams,
553 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000554 SmallVectorImpl<QualType> &PTypes,
555 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000556
557 /// \brief Transforms a single function-type parameter. Return null
558 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000559 ///
560 /// \param indexAdjustment - A number to add to the parameter's
561 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000562 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000563 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000564 llvm::Optional<unsigned> NumExpansions,
565 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000566
John McCall43fed0d2010-11-12 08:19:04 +0000567 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000568
John McCall60d7b3a2010-08-24 06:29:42 +0000569 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
570 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor43959a92009-08-20 07:17:43 +0000572#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000573 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000574#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000575 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000576#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000577#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new pointer type given its pointee type.
580 ///
581 /// By default, performs semantic analysis when building the pointer type.
582 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000583 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584
585 /// \brief Build a new block pointer type given its pointee type.
586 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000587 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000589 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000590
John McCall85737a72009-10-30 00:06:24 +0000591 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000592 ///
John McCall85737a72009-10-30 00:06:24 +0000593 /// By default, performs semantic analysis when building the
594 /// reference type. Subclasses may override this routine to provide
595 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 ///
John McCall85737a72009-10-30 00:06:24 +0000597 /// \param LValue whether the type was written with an lvalue sigil
598 /// or an rvalue sigil.
599 QualType RebuildReferenceType(QualType ReferentType,
600 bool LValue,
601 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000602
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603 /// \brief Build a new member pointer type given the pointee type and the
604 /// class type it refers into.
605 ///
606 /// By default, performs semantic analysis when building the member pointer
607 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000608 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
609 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 /// \brief Build a new array type given the element type, size
612 /// modifier, size of the array (if known), size expression, and index type
613 /// qualifiers.
614 ///
615 /// By default, performs semantic analysis when building the array type.
616 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000617 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000618 QualType RebuildArrayType(QualType ElementType,
619 ArrayType::ArraySizeModifier SizeMod,
620 const llvm::APInt *Size,
621 Expr *SizeExpr,
622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000624
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// \brief Build a new constant array type given the element type, size
626 /// modifier, (known) size of the array, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
632 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new incomplete array type given the element type, size
637 /// modifier, and index type qualifiers.
638 ///
639 /// By default, performs semantic analysis when building the array type.
640 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000641 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000642 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000643 unsigned IndexTypeQuals,
644 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645
Mike Stump1eb44332009-09-09 15:08:12 +0000646 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 /// size modifier, size expression, and index type qualifiers.
648 ///
649 /// By default, performs semantic analysis when building the array type.
650 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000651 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000653 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 unsigned IndexTypeQuals,
655 SourceRange BracketsRange);
656
Mike Stump1eb44332009-09-09 15:08:12 +0000657 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// size modifier, size expression, and index type qualifiers.
659 ///
660 /// By default, performs semantic analysis when building the array type.
661 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000662 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000664 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 unsigned IndexTypeQuals,
666 SourceRange BracketsRange);
667
668 /// \brief Build a new vector type given the element type and
669 /// number of elements.
670 ///
671 /// By default, performs semantic analysis when building the vector type.
672 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000673 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000674 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000675
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// \brief Build a new extended vector type given the element type and
677 /// number of elements.
678 ///
679 /// By default, performs semantic analysis when building the vector type.
680 /// Subclasses may override this routine to provide different behavior.
681 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
682 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
684 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 /// given the element type and number of elements.
686 ///
687 /// By default, performs semantic analysis when building the vector type.
688 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000689 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000692
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 /// \brief Build a new function type.
694 ///
695 /// By default, performs semantic analysis when building the function type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000698 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000700 bool Variadic, bool HasTrailingReturn,
701 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000702 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000703 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000704
John McCalla2becad2009-10-21 00:40:46 +0000705 /// \brief Build a new unprototyped function type.
706 QualType RebuildFunctionNoProtoType(QualType ResultType);
707
John McCalled976492009-12-04 22:46:56 +0000708 /// \brief Rebuild an unresolved typename type, given the decl that
709 /// the UnresolvedUsingTypenameDecl was transformed to.
710 QualType RebuildUnresolvedUsingType(Decl *D);
711
Douglas Gregor577f75a2009-08-04 16:50:30 +0000712 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000713 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000714 return SemaRef.Context.getTypeDeclType(Typedef);
715 }
716
717 /// \brief Build a new class/struct/union type.
718 QualType RebuildRecordType(RecordDecl *Record) {
719 return SemaRef.Context.getTypeDeclType(Record);
720 }
721
722 /// \brief Build a new Enum type.
723 QualType RebuildEnumType(EnumDecl *Enum) {
724 return SemaRef.Context.getTypeDeclType(Enum);
725 }
John McCall7da24312009-09-05 00:15:47 +0000726
Mike Stump1eb44332009-09-09 15:08:12 +0000727 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 ///
729 /// By default, performs semantic analysis when building the typeof type.
730 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000731 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732
Mike Stump1eb44332009-09-09 15:08:12 +0000733 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734 ///
735 /// By default, builds a new TypeOfType with the given underlying type.
736 QualType RebuildTypeOfType(QualType Underlying);
737
Sean Huntca63c202011-05-24 22:41:36 +0000738 /// \brief Build a new unary transform type.
739 QualType RebuildUnaryTransformType(QualType BaseType,
740 UnaryTransformType::UTTKind UKind,
741 SourceLocation Loc);
742
Mike Stump1eb44332009-09-09 15:08:12 +0000743 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000744 ///
745 /// By default, performs semantic analysis when building the decltype type.
746 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000747 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000748
Richard Smith34b41d92011-02-20 03:19:35 +0000749 /// \brief Build a new C++0x auto type.
750 ///
751 /// By default, builds a new AutoType with the given deduced type.
752 QualType RebuildAutoType(QualType Deduced) {
753 return SemaRef.Context.getAutoType(Deduced);
754 }
755
Douglas Gregor577f75a2009-08-04 16:50:30 +0000756 /// \brief Build a new template specialization type.
757 ///
758 /// By default, performs semantic analysis when building the template
759 /// specialization type. Subclasses may override this routine to provide
760 /// different behavior.
761 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000762 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000763 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000765 /// \brief Build a new parenthesized type.
766 ///
767 /// By default, builds a new ParenType type from the inner type.
768 /// Subclasses may override this routine to provide different behavior.
769 QualType RebuildParenType(QualType InnerType) {
770 return SemaRef.Context.getParenType(InnerType);
771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new qualified name type.
774 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000775 /// By default, builds a new ElaboratedType type from the keyword,
776 /// the nested-name-specifier and the named type.
777 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000778 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
779 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000780 NestedNameSpecifierLoc QualifierLoc,
781 QualType Named) {
782 return SemaRef.Context.getElaboratedType(Keyword,
783 QualifierLoc.getNestedNameSpecifier(),
784 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000785 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000786
787 /// \brief Build a new typename type that refers to a template-id.
788 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 /// By default, builds a new DependentNameType type from the
790 /// nested-name-specifier and the given type. Subclasses may override
791 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000792 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000793 ElaboratedTypeKeyword Keyword,
794 NestedNameSpecifierLoc QualifierLoc,
795 const IdentifierInfo *Name,
796 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000797 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 // Rebuild the template name.
799 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000800 CXXScopeSpec SS;
801 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000802 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000803 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000804
805 if (InstName.isNull())
806 return QualType();
807
808 // If it's still dependent, make a dependent specialization.
809 if (InstName.getAsDependentTemplateName())
810 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
811 QualifierLoc.getNestedNameSpecifier(),
812 Name,
813 Args);
814
815 // Otherwise, make an elaborated type wrapping a non-dependent
816 // specialization.
817 QualType T =
818 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
819 if (T.isNull()) return QualType();
820
821 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
822 return T;
823
824 return SemaRef.Context.getElaboratedType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
826 T);
827 }
828
Douglas Gregor577f75a2009-08-04 16:50:30 +0000829 /// \brief Build a new typename type that refers to an identifier.
830 ///
831 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000832 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000833 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000834 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000835 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000836 NestedNameSpecifierLoc QualifierLoc,
837 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000838 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000839 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000840 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000841
Douglas Gregor2494dd02011-03-01 01:34:45 +0000842 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000843 // If the name is still dependent, just build a new dependent name type.
844 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 return SemaRef.Context.getDependentNameType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
847 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000848 }
849
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000850 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000851 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000852 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000853
854 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
855
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000857 // into a non-dependent elaborated-type-specifier. Find the tag we're
858 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000859 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000860 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
861 if (!DC)
862 return QualType();
863
John McCall56138762010-05-27 06:40:31 +0000864 if (SemaRef.RequireCompleteDeclContext(SS, DC))
865 return QualType();
866
Douglas Gregor40336422010-03-31 22:19:08 +0000867 TagDecl *Tag = 0;
868 SemaRef.LookupQualifiedName(Result, DC);
869 switch (Result.getResultKind()) {
870 case LookupResult::NotFound:
871 case LookupResult::NotFoundInCurrentInstantiation:
872 break;
Sean Huntc3021132010-05-05 15:23:54 +0000873
Douglas Gregor40336422010-03-31 22:19:08 +0000874 case LookupResult::Found:
875 Tag = Result.getAsSingle<TagDecl>();
876 break;
Sean Huntc3021132010-05-05 15:23:54 +0000877
Douglas Gregor40336422010-03-31 22:19:08 +0000878 case LookupResult::FoundOverloaded:
879 case LookupResult::FoundUnresolvedValue:
880 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000881
Douglas Gregor40336422010-03-31 22:19:08 +0000882 case LookupResult::Ambiguous:
883 // Let the LookupResult structure handle ambiguities.
884 return QualType();
885 }
886
887 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000888 // Check where the name exists but isn't a tag type and use that to emit
889 // better diagnostics.
890 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
891 SemaRef.LookupQualifiedName(Result, DC);
892 switch (Result.getResultKind()) {
893 case LookupResult::Found:
894 case LookupResult::FoundOverloaded:
895 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000896 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000897 unsigned Kind = 0;
898 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000899 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
900 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000901 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
902 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
903 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000904 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 default:
906 // FIXME: Would be nice to highlight just the source range.
907 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
908 << Kind << Id << DC;
909 break;
910 }
Douglas Gregor40336422010-03-31 22:19:08 +0000911 return QualType();
912 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000913
Richard Trieubbf34c02011-06-10 03:11:26 +0000914 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
915 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000916 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000917 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
918 return QualType();
919 }
920
921 // Build the elaborated-type-specifier type.
922 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
925 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000926 }
Mike Stump1eb44332009-09-09 15:08:12 +0000927
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000928 /// \brief Build a new pack expansion type.
929 ///
930 /// By default, builds a new PackExpansionType type from the given pattern.
931 /// Subclasses may override this routine to provide different behavior.
932 QualType RebuildPackExpansionType(QualType Pattern,
933 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000934 SourceLocation EllipsisLoc,
935 llvm::Optional<unsigned> NumExpansions) {
936 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
937 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 }
939
Eli Friedmanb001de72011-10-06 23:00:33 +0000940 /// \brief Build a new atomic type given its value type.
941 ///
942 /// By default, performs semantic analysis when building the atomic type.
943 /// Subclasses may override this routine to provide different behavior.
944 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
945
Douglas Gregord1067e52009-08-06 06:41:21 +0000946 /// \brief Build a new template name given a nested name specifier, a flag
947 /// indicating whether the "template" keyword was provided, and the template
948 /// that the template name refers to.
949 ///
950 /// By default, builds the new template name directly. Subclasses may override
951 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000952 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000953 bool TemplateKW,
954 TemplateDecl *Template);
955
Douglas Gregord1067e52009-08-06 06:41:21 +0000956 /// \brief Build a new template name given a nested name specifier and the
957 /// name that is referred to as a template.
958 ///
959 /// By default, performs semantic analysis to determine whether the name can
960 /// be resolved to a specific template, then builds the appropriate kind of
961 /// template name. Subclasses may override this routine to provide different
962 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000963 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
964 const IdentifierInfo &Name,
965 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000966 QualType ObjectType,
967 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000969 /// \brief Build a new template name given a nested name specifier and the
970 /// overloaded operator name that is referred to as a template.
971 ///
972 /// By default, performs semantic analysis to determine whether the name can
973 /// be resolved to a specific template, then builds the appropriate kind of
974 /// template name. Subclasses may override this routine to provide different
975 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000976 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000977 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000978 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000979 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000980
981 /// \brief Build a new template name given a template template parameter pack
982 /// and the
983 ///
984 /// By default, performs semantic analysis to determine whether the name can
985 /// be resolved to a specific template, then builds the appropriate kind of
986 /// template name. Subclasses may override this routine to provide different
987 /// behavior.
988 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
989 const TemplateArgument &ArgPack) {
990 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
991 }
992
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 /// \brief Build a new compound statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000997 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 MultiStmtArg Statements,
999 SourceLocation RBraceLoc,
1000 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001001 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 IsStmtExpr);
1003 }
1004
1005 /// \brief Build a new case statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001010 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001012 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001014 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 ColonLoc);
1016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 /// \brief Attach the body to a new case statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001022 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001023 getSema().ActOnCaseStmtBody(S, Body);
1024 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 /// \brief Build a new default statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001033 Stmt *SubStmt) {
1034 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /*CurScope=*/0);
1036 }
Mike Stump1eb44332009-09-09 15:08:12 +00001037
Douglas Gregor43959a92009-08-20 07:17:43 +00001038 /// \brief Build a new label statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1043 SourceLocation ColonLoc, Stmt *SubStmt) {
1044 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new "if" statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001052 VarDecl *CondVar, Stmt *Then,
1053 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001054 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 }
Mike Stump1eb44332009-09-09 15:08:12 +00001056
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 /// \brief Start building a new switch statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001061 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001062 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001063 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001064 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 }
Mike Stump1eb44332009-09-09 15:08:12 +00001066
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 /// \brief Attach the body to the switch statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001071 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001072 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001073 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
1075
1076 /// \brief Build a new while statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1081 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001082 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Build a new do-while statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation WhileLoc, SourceLocation LParenLoc,
1091 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1093 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 }
1095
1096 /// \brief Build a new for statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001100 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1101 Stmt *Init, Sema::FullExprArg Cond,
1102 VarDecl *CondVar, Sema::FullExprArg Inc,
1103 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001104 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 /// \brief Build a new goto statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001112 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1113 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001114 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 }
1116
1117 /// \brief Build a new indirect goto statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001121 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001122 SourceLocation StarLoc,
1123 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001124 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001125 }
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 /// \brief Build a new return statement.
1128 ///
1129 /// By default, performs semantic analysis to build the new statement.
1130 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001131 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001132 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new declaration statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001139 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001140 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001142 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1143 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Anders Carlsson703e3942010-01-24 05:50:09 +00001146 /// \brief Build a new inline asm statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001151 bool IsSimple,
1152 bool IsVolatile,
1153 unsigned NumOutputs,
1154 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001155 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001156 MultiExprArg Constraints,
1157 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001158 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001159 MultiExprArg Clobbers,
1160 SourceLocation RParenLoc,
1161 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001162 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001163 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001164 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 RParenLoc, MSAsm);
1166 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001167
1168 /// \brief Build a new Objective-C @try statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001174 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Stmt *Finally) {
1176 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1177 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001178 }
1179
Douglas Gregorbe270a02010-04-26 17:57:08 +00001180 /// \brief Rebuild an Objective-C exception declaration.
1181 ///
1182 /// By default, performs semantic analysis to build the new declaration.
1183 /// Subclasses may override this routine to provide different behavior.
1184 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1185 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001186 return getSema().BuildObjCExceptionDecl(TInfo, T,
1187 ExceptionDecl->getInnerLocStart(),
1188 ExceptionDecl->getLocation(),
1189 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
Douglas Gregorbe270a02010-04-26 17:57:08 +00001192 /// \brief Build a new Objective-C @catch statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 SourceLocation RParenLoc,
1198 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001200 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001202 }
Sean Huntc3021132010-05-05 15:23:54 +00001203
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 /// \brief Build a new Objective-C @finally statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001208 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001209 Stmt *Body) {
1210 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001211 }
Sean Huntc3021132010-05-05 15:23:54 +00001212
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001213 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001217 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Expr *Operand) {
1219 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001220 }
Sean Huntc3021132010-05-05 15:23:54 +00001221
John McCall07524032011-07-27 21:50:02 +00001222 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
1226 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1227 Expr *object) {
1228 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1229 }
1230
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001231 /// \brief Build a new Objective-C @synchronized statement.
1232 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001236 Expr *Object, Stmt *Body) {
1237 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001238 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001239
John McCallf85e1932011-06-15 23:02:42 +00001240 /// \brief Build a new Objective-C @autoreleasepool statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
1244 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1245 Stmt *Body) {
1246 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1247 }
John McCall990567c2011-07-27 01:07:15 +00001248
1249 /// \brief Build the collection operand to a new Objective-C fast
1250 /// enumeration statement.
1251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
1254 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1255 Expr *collection) {
1256 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1257 }
John McCallf85e1932011-06-15 23:02:42 +00001258
Douglas Gregorc3203e72010-04-22 23:10:45 +00001259 /// \brief Build a new Objective-C fast enumeration statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001263 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001264 SourceLocation LParenLoc,
1265 Stmt *Element,
1266 Expr *Collection,
1267 SourceLocation RParenLoc,
1268 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001270 Element,
1271 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001272 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001273 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 }
Sean Huntc3021132010-05-05 15:23:54 +00001275
Douglas Gregor43959a92009-08-20 07:17:43 +00001276 /// \brief Build a new C++ exception declaration.
1277 ///
1278 /// By default, performs semantic analysis to build the new decaration.
1279 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001280 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001281 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001282 SourceLocation StartLoc,
1283 SourceLocation IdLoc,
1284 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001285 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1286 StartLoc, IdLoc, Id);
1287 if (Var)
1288 getSema().CurContext->addDecl(Var);
1289 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 }
1291
1292 /// \brief Build a new C++ catch statement.
1293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001296 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001297 VarDecl *ExceptionDecl,
1298 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001299 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1300 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001301 }
Mike Stump1eb44332009-09-09 15:08:12 +00001302
Douglas Gregor43959a92009-08-20 07:17:43 +00001303 /// \brief Build a new C++ try statement.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001307 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001308 Stmt *TryBlock,
1309 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001310 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
Mike Stump1eb44332009-09-09 15:08:12 +00001312
Richard Smithad762fc2011-04-14 22:09:26 +00001313 /// \brief Build a new C++0x range-based for statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1318 SourceLocation ColonLoc,
1319 Stmt *Range, Stmt *BeginEnd,
1320 Expr *Cond, Expr *Inc,
1321 Stmt *LoopVar,
1322 SourceLocation RParenLoc) {
1323 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1324 Cond, Inc, LoopVar, RParenLoc);
1325 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001326
1327 /// \brief Build a new C++0x range-based for statement.
1328 ///
1329 /// By default, performs semantic analysis to build the new statement.
1330 /// Subclasses may override this routine to provide different behavior.
1331 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1332 bool IsIfExists,
1333 NestedNameSpecifierLoc QualifierLoc,
1334 DeclarationNameInfo NameInfo,
1335 Stmt *Nested) {
1336 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1337 QualifierLoc, NameInfo, Nested);
1338 }
1339
Richard Smithad762fc2011-04-14 22:09:26 +00001340 /// \brief Attach body to a C++0x range-based for statement.
1341 ///
1342 /// By default, performs semantic analysis to finish the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
1344 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1345 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1346 }
1347
John Wiegley28bbe4b2011-04-28 01:08:34 +00001348 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1349 SourceLocation TryLoc,
1350 Stmt *TryBlock,
1351 Stmt *Handler) {
1352 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1353 }
1354
1355 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1356 Expr *FilterExpr,
1357 Stmt *Block) {
1358 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1359 }
1360
1361 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1362 Stmt *Block) {
1363 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1364 }
1365
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 /// \brief Build a new expression that references a declaration.
1367 ///
1368 /// By default, performs semantic analysis to build the new expression.
1369 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001370 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001371 LookupResult &R,
1372 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001373 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1374 }
1375
1376
1377 /// \brief Build a new expression that references a declaration.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001381 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001382 ValueDecl *VD,
1383 const DeclarationNameInfo &NameInfo,
1384 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001385 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001386 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001387
1388 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001389
1390 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001394 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001397 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001398 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001399 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
1401
Douglas Gregora71d8192009-09-04 17:36:40 +00001402 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001407 SourceLocation OperatorLoc,
1408 bool isArrow,
1409 CXXScopeSpec &SS,
1410 TypeSourceInfo *ScopeType,
1411 SourceLocation CCLoc,
1412 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001413 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001420 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001421 Expr *SubExpr) {
1422 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
Mike Stump1eb44332009-09-09 15:08:12 +00001424
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001425 /// \brief Build a new builtin offsetof expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001430 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001431 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001432 unsigned NumComponents,
1433 SourceLocation RParenLoc) {
1434 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1435 NumComponents, RParenLoc);
1436 }
Sean Huntc3021132010-05-05 15:23:54 +00001437
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001438 /// \brief Build a new sizeof, alignof or vec_step expression with a
1439 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001440 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001443 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1444 SourceLocation OpLoc,
1445 UnaryExprOrTypeTrait ExprKind,
1446 SourceRange R) {
1447 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 }
1449
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001450 /// \brief Build a new sizeof, alignof or vec step expression with an
1451 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001452 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001455 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1456 UnaryExprOrTypeTrait ExprKind,
1457 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001458 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001459 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 return move(Result);
1464 }
Mike Stump1eb44332009-09-09 15:08:12 +00001465
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001467 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001474 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1475 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 RBracketLoc);
1477 }
1478
1479 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001480 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001485 SourceLocation RParenLoc,
1486 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001487 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001488 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001492 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001495 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001496 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001497 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001498 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001499 const DeclarationNameInfo &MemberNameInfo,
1500 ValueDecl *Member,
1501 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001502 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001503 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001504 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1505 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001506 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001507 // We have a reference to an unnamed field. This is always the
1508 // base of an anonymous struct/union member access, i.e. the
1509 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001510 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001511 assert(Member->getType()->isRecordType() &&
1512 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Richard Smith9138b4e2011-10-26 19:06:56 +00001514 BaseResult =
1515 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001516 QualifierLoc.getNestedNameSpecifier(),
1517 FoundDecl, Member);
1518 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001519 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001520 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001521 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001522 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001523 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001524 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001525 cast<FieldDecl>(Member)->getType(),
1526 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001527 return getSema().Owned(ME);
1528 }
Mike Stump1eb44332009-09-09 15:08:12 +00001529
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001530 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001531 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001532
John Wiegley429bb272011-04-08 18:41:53 +00001533 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001534 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001535
John McCall6bb80172010-03-30 21:47:33 +00001536 // FIXME: this involves duplicating earlier analysis in a lot of
1537 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001539 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001540 R.resolveKind();
1541
John McCall9ae2f072010-08-23 23:25:46 +00001542 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001543 SS, TemplateKWLoc,
1544 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001545 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 }
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001549 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 /// By default, performs semantic analysis to build the new expression.
1551 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001552 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001553 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Expr *LHS, Expr *RHS) {
1555 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
1558 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001559 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001562 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001563 SourceLocation QuestionLoc,
1564 Expr *LHS,
1565 SourceLocation ColonLoc,
1566 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001567 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1568 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001576 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001578 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001579 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001580 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001584 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// By default, performs semantic analysis to build the new expression.
1586 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001588 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001591 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation OpLoc,
1601 SourceLocation AccessorLoc,
1602 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001603
John McCall129e2df2009-11-30 22:42:35 +00001604 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001605 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001606 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001607 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001608 SS, SourceLocation(),
1609 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001610 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001611 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001619 MultiExprArg Inits,
1620 SourceLocation RBraceLoc,
1621 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001623 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1624 if (Result.isInvalid() || ResultTy->isDependentType())
1625 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001626
Douglas Gregore48319a2009-11-09 17:16:50 +00001627 // Patch in the result type we were given, which may have been computed
1628 // when the initial InitListExpr was built.
1629 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1630 ILE->setType(ResultTy);
1631 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001635 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001638 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 MultiExprArg ArrayExprs,
1640 SourceLocation EqualOrColonLoc,
1641 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001642 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001645 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 ArrayExprs.release();
1650 return move(Result);
1651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, builds the implicit value initialization without performing
1656 /// any semantic analysis. Subclasses may override this routine to provide
1657 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1660 }
Mike Stump1eb44332009-09-09 15:08:12 +00001661
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001663 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// By default, performs semantic analysis to build the new expression.
1665 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001667 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001668 SourceLocation RParenLoc) {
1669 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001670 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001671 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
1673
1674 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001679 MultiExprArg SubExprs,
1680 SourceLocation RParenLoc) {
1681 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
1686 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// rather than attempting to map the label statement itself.
1688 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001689 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001690 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001691 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001699 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001701 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 }
Mike Stump1eb44332009-09-09 15:08:12 +00001703
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// \brief Build a new __builtin_choose_expr expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001708 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001709 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation RParenLoc) {
1711 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 RParenLoc);
1714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Peter Collingbournef111d932011-04-15 00:35:48 +00001716 /// \brief Build a new generic selection expression.
1717 ///
1718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
1720 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1721 SourceLocation DefaultLoc,
1722 SourceLocation RParenLoc,
1723 Expr *ControllingExpr,
1724 TypeSourceInfo **Types,
1725 Expr **Exprs,
1726 unsigned NumAssocs) {
1727 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1728 ControllingExpr, Types, Exprs,
1729 NumAssocs);
1730 }
1731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new overloaded operator call expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// The semantic analysis provides the behavior of template instantiation,
1736 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001737 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 /// argument-dependent lookup, etc. Subclasses may override this routine to
1739 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001742 Expr *Callee,
1743 Expr *First,
1744 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001745
1746 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 /// reinterpret_cast.
1748 ///
1749 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001750 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 Stmt::StmtClass Class,
1754 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001755 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RAngleLoc,
1757 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation RParenLoc) {
1760 switch (Class) {
1761 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001762 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001763 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765
1766 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001767 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001768 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001770
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001772 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001773 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001778 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001779 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001781
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001783 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 }
Mike Stump1eb44332009-09-09 15:08:12 +00001786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 /// \brief Build a new C++ static_cast expression.
1788 ///
1789 /// By default, performs semantic analysis to build the new expression.
1790 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001791 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001793 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RAngleLoc,
1795 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001798 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001799 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001800 SourceRange(LAngleLoc, RAngleLoc),
1801 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
1803
1804 /// \brief Build a new C++ dynamic_cast expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001810 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RAngleLoc,
1812 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001815 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001816 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001817 SourceRange(LAngleLoc, RAngleLoc),
1818 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
1820
1821 /// \brief Build a new C++ reinterpret_cast expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001827 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RAngleLoc,
1829 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001830 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001832 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001833 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001834 SourceRange(LAngleLoc, RAngleLoc),
1835 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 }
1837
1838 /// \brief Build a new C++ const_cast expression.
1839 ///
1840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001842 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001844 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RAngleLoc,
1846 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001847 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001849 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001850 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001851 SourceRange(LAngleLoc, RAngleLoc),
1852 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
Mike Stump1eb44332009-09-09 15:08:12 +00001854
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 /// \brief Build a new C++ functional-style cast expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001859 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1860 SourceLocation LParenLoc,
1861 Expr *Sub,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001864 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 RParenLoc);
1866 }
Mike Stump1eb44332009-09-09 15:08:12 +00001867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// \brief Build a new C++ typeid(type) expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001873 SourceLocation TypeidLoc,
1874 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001876 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001877 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 }
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Francois Pichet01b7c302010-09-08 12:20:18 +00001880
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 /// \brief Build a new C++ typeid(expr) expression.
1882 ///
1883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001885 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001886 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001887 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001889 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001890 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001891 }
1892
Francois Pichet01b7c302010-09-08 12:20:18 +00001893 /// \brief Build a new C++ __uuidof(type) expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
1897 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1898 SourceLocation TypeidLoc,
1899 TypeSourceInfo *Operand,
1900 SourceLocation RParenLoc) {
1901 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1902 RParenLoc);
1903 }
1904
1905 /// \brief Build a new C++ __uuidof(expr) expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1910 SourceLocation TypeidLoc,
1911 Expr *Operand,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1914 RParenLoc);
1915 }
1916
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 /// \brief Build a new C++ "this" expression.
1918 ///
1919 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001920 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001923 QualType ThisType,
1924 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001925 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001927 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1928 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 }
1930
1931 /// \brief Build a new C++ throw expression.
1932 ///
1933 /// By default, performs semantic analysis to build the new expression.
1934 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001935 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1936 bool IsThrownVariableInScope) {
1937 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 }
1939
1940 /// \brief Build a new C++ default-argument expression.
1941 ///
1942 /// By default, builds a new default-argument expression, which does not
1943 /// require any semantic analysis. Subclasses may override this routine to
1944 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001945 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001946 ParmVarDecl *Param) {
1947 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1948 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 }
1950
1951 /// \brief Build a new C++ zero-initialization expression.
1952 ///
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001955 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1956 SourceLocation LParenLoc,
1957 SourceLocation RParenLoc) {
1958 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001959 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001960 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// \brief Build a new C++ "new" expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001967 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001968 bool UseGlobal,
1969 SourceLocation PlacementLParen,
1970 MultiExprArg PlacementArgs,
1971 SourceLocation PlacementRParen,
1972 SourceRange TypeIdParens,
1973 QualType AllocatedType,
1974 TypeSourceInfo *AllocatedTypeInfo,
1975 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001976 SourceRange DirectInitRange,
1977 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001978 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 PlacementLParen,
1980 move(PlacementArgs),
1981 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001982 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001983 AllocatedType,
1984 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001985 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001986 DirectInitRange,
1987 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 }
Mike Stump1eb44332009-09-09 15:08:12 +00001989
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 /// \brief Build a new C++ "delete" expression.
1991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001994 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 bool IsGlobalDelete,
1996 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001997 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001999 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
Mike Stump1eb44332009-09-09 15:08:12 +00002001
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 /// \brief Build a new unary type trait expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002007 SourceLocation StartLoc,
2008 TypeSourceInfo *T,
2009 SourceLocation RParenLoc) {
2010 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 }
2012
Francois Pichet6ad6f282010-12-07 00:08:36 +00002013 /// \brief Build a new binary type trait expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
2017 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2018 SourceLocation StartLoc,
2019 TypeSourceInfo *LhsT,
2020 TypeSourceInfo *RhsT,
2021 SourceLocation RParenLoc) {
2022 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2023 }
2024
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002025 /// \brief Build a new type trait expression.
2026 ///
2027 /// By default, performs semantic analysis to build the new expression.
2028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildTypeTrait(TypeTrait Trait,
2030 SourceLocation StartLoc,
2031 ArrayRef<TypeSourceInfo *> Args,
2032 SourceLocation RParenLoc) {
2033 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2034 }
2035
John Wiegley21ff2e52011-04-28 00:16:57 +00002036 /// \brief Build a new array type trait expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
2040 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2041 SourceLocation StartLoc,
2042 TypeSourceInfo *TSInfo,
2043 Expr *DimExpr,
2044 SourceLocation RParenLoc) {
2045 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2046 }
2047
John Wiegley55262202011-04-25 06:54:41 +00002048 /// \brief Build a new expression trait expression.
2049 ///
2050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
2052 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2053 SourceLocation StartLoc,
2054 Expr *Queried,
2055 SourceLocation RParenLoc) {
2056 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2057 }
2058
Mike Stump1eb44332009-09-09 15:08:12 +00002059 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002060 /// expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002064 ExprResult RebuildDependentScopeDeclRefExpr(
2065 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002066 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002067 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002068 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002070 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002071
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002072 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002073 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002074 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002075
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002076 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 }
2078
2079 /// \brief Build a new template-id expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002083 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002084 SourceLocation TemplateKWLoc,
2085 LookupResult &R,
2086 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002087 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002088 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2089 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 }
2091
2092 /// \brief Build a new object-construction expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002097 SourceLocation Loc,
2098 CXXConstructorDecl *Constructor,
2099 bool IsElidable,
2100 MultiExprArg Args,
2101 bool HadMultipleCandidates,
2102 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002103 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002104 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002105 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002106 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002107 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002108 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002109
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002110 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002111 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002112 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002113 RequiresZeroInit, ConstructKind,
2114 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 }
2116
2117 /// \brief Build a new object-construction expression.
2118 ///
2119 /// By default, performs semantic analysis to build the new expression.
2120 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002121 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2122 SourceLocation LParenLoc,
2123 MultiExprArg Args,
2124 SourceLocation RParenLoc) {
2125 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 LParenLoc,
2127 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002128 RParenLoc);
2129 }
2130
2131 /// \brief Build a new object-construction expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002135 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2136 SourceLocation LParenLoc,
2137 MultiExprArg Args,
2138 SourceLocation RParenLoc) {
2139 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 LParenLoc,
2141 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 RParenLoc);
2143 }
Mike Stump1eb44332009-09-09 15:08:12 +00002144
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 /// \brief Build a new member reference expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002149 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002150 QualType BaseType,
2151 bool IsArrow,
2152 SourceLocation OperatorLoc,
2153 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002154 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002155 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002156 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002157 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002159 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002160
John McCall9ae2f072010-08-23 23:25:46 +00002161 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002162 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002163 SS, TemplateKWLoc,
2164 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002165 MemberNameInfo,
2166 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 }
2168
John McCall129e2df2009-11-30 22:42:35 +00002169 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002173 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2174 SourceLocation OperatorLoc,
2175 bool IsArrow,
2176 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002178 NamedDecl *FirstQualifierInScope,
2179 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002180 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002181 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002182 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002183
John McCall9ae2f072010-08-23 23:25:46 +00002184 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002185 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002186 SS, TemplateKWLoc,
2187 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002188 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002189 }
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Sebastian Redl2e156222010-09-10 20:55:43 +00002191 /// \brief Build a new noexcept expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
2195 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2196 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2197 }
2198
Douglas Gregoree8aff02011-01-04 17:33:58 +00002199 /// \brief Build a new expression to compute the length of a parameter pack.
2200 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2201 SourceLocation PackLoc,
2202 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002203 llvm::Optional<unsigned> Length) {
2204 if (Length)
2205 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2206 OperatorLoc, Pack, PackLoc,
2207 RParenLoc, *Length);
2208
Douglas Gregoree8aff02011-01-04 17:33:58 +00002209 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2210 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002211 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002212 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002213
2214 /// \brief Build a new Objective-C array literal.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
2218 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2219 Expr **Elements, unsigned NumElements) {
2220 return getSema().BuildObjCArrayLiteral(Range,
2221 MultiExprArg(Elements, NumElements));
2222 }
2223
2224 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2225 Expr *Base, Expr *Key,
2226 ObjCMethodDecl *getterMethod,
2227 ObjCMethodDecl *setterMethod) {
2228 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2229 getterMethod, setterMethod);
2230 }
2231
2232 /// \brief Build a new Objective-C dictionary literal.
2233 ///
2234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
2236 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2237 ObjCDictionaryElement *Elements,
2238 unsigned NumElements) {
2239 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2240 }
2241
Douglas Gregorb98b1992009-08-11 05:31:07 +00002242 /// \brief Build a new Objective-C @encode expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002246 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002247 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002248 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002249 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002250 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002251 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252
Douglas Gregor92e986e2010-04-22 16:44:27 +00002253 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002254 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002255 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002256 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002257 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002258 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002259 MultiExprArg Args,
2260 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002261 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2262 ReceiverTypeInfo->getType(),
2263 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002264 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002265 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002266 }
2267
2268 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002270 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002271 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002272 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002273 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002274 MultiExprArg Args,
2275 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002276 return SemaRef.BuildInstanceMessage(Receiver,
2277 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002278 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002280 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 }
2282
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002283 /// \brief Build a new Objective-C ivar reference expression.
2284 ///
2285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002288 SourceLocation IvarLoc,
2289 bool IsArrow, bool IsFreeIvar) {
2290 // FIXME: We lose track of the IsFreeIvar bit.
2291 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002292 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002293 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2294 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002295 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002296 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002297 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002298 false);
John Wiegley429bb272011-04-08 18:41:53 +00002299 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002300 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002301
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 if (Result.get())
2303 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002304
John Wiegley429bb272011-04-08 18:41:53 +00002305 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002306 /*FIXME:*/IvarLoc, IsArrow,
2307 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002308 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002309 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 /*TemplateArgs=*/0);
2311 }
Douglas Gregore3303542010-04-26 20:47:02 +00002312
2313 /// \brief Build a new Objective-C property reference expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002317 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002318 ObjCPropertyDecl *Property,
2319 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002320 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002322 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2323 Sema::LookupMemberName);
2324 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002325 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002326 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002327 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002328 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002329 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002330
Douglas Gregore3303542010-04-26 20:47:02 +00002331 if (Result.get())
2332 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002333
John Wiegley429bb272011-04-08 18:41:53 +00002334 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002335 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002336 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002337 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002338 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002339 /*TemplateArgs=*/0);
2340 }
Sean Huntc3021132010-05-05 15:23:54 +00002341
John McCall12f78a62010-12-02 01:19:52 +00002342 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002343 ///
2344 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002345 /// Subclasses may override this routine to provide different behavior.
2346 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2347 ObjCMethodDecl *Getter,
2348 ObjCMethodDecl *Setter,
2349 SourceLocation PropertyLoc) {
2350 // Since these expressions can only be value-dependent, we do not
2351 // need to perform semantic analysis again.
2352 return Owned(
2353 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2354 VK_LValue, OK_ObjCProperty,
2355 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002356 }
2357
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002358 /// \brief Build a new Objective-C "isa" expression.
2359 ///
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002362 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002363 bool IsArrow) {
2364 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002365 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002366 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2367 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002368 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002369 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002370 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002371 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002372 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002373
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 if (Result.get())
2375 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002376
John Wiegley429bb272011-04-08 18:41:53 +00002377 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002378 /*FIXME:*/IsaLoc, IsArrow,
2379 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002381 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002382 /*TemplateArgs=*/0);
2383 }
Sean Huntc3021132010-05-05 15:23:54 +00002384
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 /// \brief Build a new shuffle vector expression.
2386 ///
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002389 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002390 MultiExprArg SubExprs,
2391 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002392 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002393 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002394 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2395 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2396 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2397 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002398
Douglas Gregorb98b1992009-08-11 05:31:07 +00002399 // Build a reference to the __builtin_shufflevector builtin
2400 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002401 ExprResult Callee
2402 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2403 VK_LValue, BuiltinLoc));
2404 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2405 if (Callee.isInvalid())
2406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002407
2408 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002409 unsigned NumSubExprs = SubExprs.size();
2410 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002411 ExprResult TheCall = SemaRef.Owned(
2412 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002413 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002414 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002415 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002416 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002417
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002419 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002420 }
John McCall43fed0d2010-11-12 08:19:04 +00002421
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002422 /// \brief Build a new template argument pack expansion.
2423 ///
2424 /// By default, performs semantic analysis to build a new pack expansion
2425 /// for a template argument. Subclasses may override this routine to provide
2426 /// different behavior.
2427 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002428 SourceLocation EllipsisLoc,
2429 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002430 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002431 case TemplateArgument::Expression: {
2432 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002433 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2434 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002435 if (Result.isInvalid())
2436 return TemplateArgumentLoc();
2437
2438 return TemplateArgumentLoc(Result.get(), Result.get());
2439 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002440
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002441 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002442 return TemplateArgumentLoc(TemplateArgument(
2443 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002444 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002445 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002446 Pattern.getTemplateNameLoc(),
2447 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002448
2449 case TemplateArgument::Null:
2450 case TemplateArgument::Integral:
2451 case TemplateArgument::Declaration:
2452 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002453 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 llvm_unreachable("Pack expansion pattern has no parameter packs");
2455
2456 case TemplateArgument::Type:
2457 if (TypeSourceInfo *Expansion
2458 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002459 EllipsisLoc,
2460 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002461 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2462 Expansion);
2463 break;
2464 }
2465
2466 return TemplateArgumentLoc();
2467 }
2468
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002469 /// \brief Build a new expression pack expansion.
2470 ///
2471 /// By default, performs semantic analysis to build a new pack expansion
2472 /// for an expression. Subclasses may override this routine to provide
2473 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002474 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2475 llvm::Optional<unsigned> NumExpansions) {
2476 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002477 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002478
2479 /// \brief Build a new atomic operation expression.
2480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2484 MultiExprArg SubExprs,
2485 QualType RetTy,
2486 AtomicExpr::AtomicOp Op,
2487 SourceLocation RParenLoc) {
2488 // Just create the expression; there is not any interesting semantic
2489 // analysis here because we can't actually build an AtomicExpr until
2490 // we are sure it is semantically sound.
2491 unsigned NumSubExprs = SubExprs.size();
2492 Expr **Subs = (Expr **)SubExprs.release();
2493 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2494 NumSubExprs, RetTy, Op,
2495 RParenLoc);
2496 }
2497
John McCall43fed0d2010-11-12 08:19:04 +00002498private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002499 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2500 QualType ObjectType,
2501 NamedDecl *FirstQualifierInScope,
2502 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002503
2504 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2505 QualType ObjectType,
2506 NamedDecl *FirstQualifierInScope,
2507 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002508};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002509
Douglas Gregor43959a92009-08-20 07:17:43 +00002510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002511StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002512 if (!S)
2513 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002514
Douglas Gregor43959a92009-08-20 07:17:43 +00002515 switch (S->getStmtClass()) {
2516 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002517
Douglas Gregor43959a92009-08-20 07:17:43 +00002518 // Transform individual statement nodes
2519#define STMT(Node, Parent) \
2520 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002521#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002522#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002523#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525 // Transform expressions by calling TransformExpr.
2526#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002527#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002528#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002529#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002530 {
John McCall60d7b3a2010-08-24 06:29:42 +00002531 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002532 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002533 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002534
John McCall9ae2f072010-08-23 23:25:46 +00002535 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 }
Mike Stump1eb44332009-09-09 15:08:12 +00002537 }
2538
John McCall3fa5cae2010-10-26 07:05:15 +00002539 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002540}
Mike Stump1eb44332009-09-09 15:08:12 +00002541
2542
Douglas Gregor670444e2009-08-04 22:27:00 +00002543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002544ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002545 if (!E)
2546 return SemaRef.Owned(E);
2547
2548 switch (E->getStmtClass()) {
2549 case Stmt::NoStmtClass: break;
2550#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002551#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002552#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002553 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002554#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002555 }
2556
John McCall3fa5cae2010-10-26 07:05:15 +00002557 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002558}
2559
2560template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002561bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2562 unsigned NumInputs,
2563 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002564 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002565 bool *ArgChanged) {
2566 for (unsigned I = 0; I != NumInputs; ++I) {
2567 // If requested, drop call arguments that need to be dropped.
2568 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2569 if (ArgChanged)
2570 *ArgChanged = true;
2571
2572 break;
2573 }
2574
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002575 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2576 Expr *Pattern = Expansion->getPattern();
2577
Chris Lattner686775d2011-07-20 06:58:45 +00002578 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002579 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2580 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2581
2582 // Determine whether the set of unexpanded parameter packs can and should
2583 // be expanded.
2584 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002585 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002586 llvm::Optional<unsigned> OrigNumExpansions
2587 = Expansion->getNumExpansions();
2588 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002589 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2590 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002591 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002592 Expand, RetainExpansion,
2593 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002594 return true;
2595
2596 if (!Expand) {
2597 // The transform has determined that we should perform a simple
2598 // transformation on the pack expansion, producing another pack
2599 // expansion.
2600 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2601 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2602 if (OutPattern.isInvalid())
2603 return true;
2604
2605 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002606 Expansion->getEllipsisLoc(),
2607 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 if (Out.isInvalid())
2609 return true;
2610
2611 if (ArgChanged)
2612 *ArgChanged = true;
2613 Outputs.push_back(Out.get());
2614 continue;
2615 }
John McCallc8fc90a2011-07-06 07:30:07 +00002616
2617 // Record right away that the argument was changed. This needs
2618 // to happen even if the array expands to nothing.
2619 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002620
2621 // The transform has determined that we should perform an elementwise
2622 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002623 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2625 ExprResult Out = getDerived().TransformExpr(Pattern);
2626 if (Out.isInvalid())
2627 return true;
2628
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002629 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002630 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2631 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002632 if (Out.isInvalid())
2633 return true;
2634 }
2635
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002636 Outputs.push_back(Out.get());
2637 }
2638
2639 continue;
2640 }
2641
Douglas Gregoraa165f82011-01-03 19:04:46 +00002642 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2643 if (Result.isInvalid())
2644 return true;
2645
2646 if (Result.get() != Inputs[I] && ArgChanged)
2647 *ArgChanged = true;
2648
2649 Outputs.push_back(Result.get());
2650 }
2651
2652 return false;
2653}
2654
2655template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002656NestedNameSpecifierLoc
2657TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2658 NestedNameSpecifierLoc NNS,
2659 QualType ObjectType,
2660 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002661 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002662 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2663 Qualifier = Qualifier.getPrefix())
2664 Qualifiers.push_back(Qualifier);
2665
2666 CXXScopeSpec SS;
2667 while (!Qualifiers.empty()) {
2668 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2669 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2670
2671 switch (QNNS->getKind()) {
2672 case NestedNameSpecifier::Identifier:
2673 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2674 *QNNS->getAsIdentifier(),
2675 Q.getLocalBeginLoc(),
2676 Q.getLocalEndLoc(),
2677 ObjectType, false, SS,
2678 FirstQualifierInScope, false))
2679 return NestedNameSpecifierLoc();
2680
2681 break;
2682
2683 case NestedNameSpecifier::Namespace: {
2684 NamespaceDecl *NS
2685 = cast_or_null<NamespaceDecl>(
2686 getDerived().TransformDecl(
2687 Q.getLocalBeginLoc(),
2688 QNNS->getAsNamespace()));
2689 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2690 break;
2691 }
2692
2693 case NestedNameSpecifier::NamespaceAlias: {
2694 NamespaceAliasDecl *Alias
2695 = cast_or_null<NamespaceAliasDecl>(
2696 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2697 QNNS->getAsNamespaceAlias()));
2698 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2699 Q.getLocalEndLoc());
2700 break;
2701 }
2702
2703 case NestedNameSpecifier::Global:
2704 // There is no meaningful transformation that one could perform on the
2705 // global scope.
2706 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2707 break;
2708
2709 case NestedNameSpecifier::TypeSpecWithTemplate:
2710 case NestedNameSpecifier::TypeSpec: {
2711 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2712 FirstQualifierInScope, SS);
2713
2714 if (!TL)
2715 return NestedNameSpecifierLoc();
2716
2717 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2718 (SemaRef.getLangOptions().CPlusPlus0x &&
2719 TL.getType()->isEnumeralType())) {
2720 assert(!TL.getType().hasLocalQualifiers() &&
2721 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002722 if (TL.getType()->isEnumeralType())
2723 SemaRef.Diag(TL.getBeginLoc(),
2724 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002725 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2726 Q.getLocalEndLoc());
2727 break;
2728 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002729 // If the nested-name-specifier is an invalid type def, don't emit an
2730 // error because a previous error should have already been emitted.
2731 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2732 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2733 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2734 << TL.getType() << SS.getRange();
2735 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 return NestedNameSpecifierLoc();
2737 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002738 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002739
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002740 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002742 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743 }
2744
2745 // Don't rebuild the nested-name-specifier if we don't have to.
2746 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2747 !getDerived().AlwaysRebuild())
2748 return NNS;
2749
2750 // If we can re-use the source-location data from the original
2751 // nested-name-specifier, do so.
2752 if (SS.location_size() == NNS.getDataLength() &&
2753 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2754 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2755
2756 // Allocate new nested-name-specifier location information.
2757 return SS.getWithLocInContext(SemaRef.Context);
2758}
2759
2760template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002761DeclarationNameInfo
2762TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002763::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002764 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002765 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002766 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002767
2768 switch (Name.getNameKind()) {
2769 case DeclarationName::Identifier:
2770 case DeclarationName::ObjCZeroArgSelector:
2771 case DeclarationName::ObjCOneArgSelector:
2772 case DeclarationName::ObjCMultiArgSelector:
2773 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002774 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002775 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002776 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002777
Douglas Gregor81499bb2009-09-03 22:13:48 +00002778 case DeclarationName::CXXConstructorName:
2779 case DeclarationName::CXXDestructorName:
2780 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002781 TypeSourceInfo *NewTInfo;
2782 CanQualType NewCanTy;
2783 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002784 NewTInfo = getDerived().TransformType(OldTInfo);
2785 if (!NewTInfo)
2786 return DeclarationNameInfo();
2787 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002788 }
2789 else {
2790 NewTInfo = 0;
2791 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002792 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002793 if (NewT.isNull())
2794 return DeclarationNameInfo();
2795 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2796 }
Mike Stump1eb44332009-09-09 15:08:12 +00002797
Abramo Bagnara25777432010-08-11 22:01:17 +00002798 DeclarationName NewName
2799 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2800 NewCanTy);
2801 DeclarationNameInfo NewNameInfo(NameInfo);
2802 NewNameInfo.setName(NewName);
2803 NewNameInfo.setNamedTypeInfo(NewTInfo);
2804 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002805 }
Mike Stump1eb44332009-09-09 15:08:12 +00002806 }
2807
David Blaikieb219cfc2011-09-23 05:06:16 +00002808 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002809}
2810
2811template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002812TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002813TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2814 TemplateName Name,
2815 SourceLocation NameLoc,
2816 QualType ObjectType,
2817 NamedDecl *FirstQualifierInScope) {
2818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2819 TemplateDecl *Template = QTN->getTemplateDecl();
2820 assert(Template && "qualified template name must refer to a template");
2821
2822 TemplateDecl *TransTemplate
2823 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2824 Template));
2825 if (!TransTemplate)
2826 return TemplateName();
2827
2828 if (!getDerived().AlwaysRebuild() &&
2829 SS.getScopeRep() == QTN->getQualifier() &&
2830 TransTemplate == Template)
2831 return Name;
2832
2833 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2834 TransTemplate);
2835 }
2836
2837 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2838 if (SS.getScopeRep()) {
2839 // These apply to the scope specifier, not the template.
2840 ObjectType = QualType();
2841 FirstQualifierInScope = 0;
2842 }
2843
2844 if (!getDerived().AlwaysRebuild() &&
2845 SS.getScopeRep() == DTN->getQualifier() &&
2846 ObjectType.isNull())
2847 return Name;
2848
2849 if (DTN->isIdentifier()) {
2850 return getDerived().RebuildTemplateName(SS,
2851 *DTN->getIdentifier(),
2852 NameLoc,
2853 ObjectType,
2854 FirstQualifierInScope);
2855 }
2856
2857 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2858 ObjectType);
2859 }
2860
2861 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2862 TemplateDecl *TransTemplate
2863 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2864 Template));
2865 if (!TransTemplate)
2866 return TemplateName();
2867
2868 if (!getDerived().AlwaysRebuild() &&
2869 TransTemplate == Template)
2870 return Name;
2871
2872 return TemplateName(TransTemplate);
2873 }
2874
2875 if (SubstTemplateTemplateParmPackStorage *SubstPack
2876 = Name.getAsSubstTemplateTemplateParmPack()) {
2877 TemplateTemplateParmDecl *TransParam
2878 = cast_or_null<TemplateTemplateParmDecl>(
2879 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2880 if (!TransParam)
2881 return TemplateName();
2882
2883 if (!getDerived().AlwaysRebuild() &&
2884 TransParam == SubstPack->getParameterPack())
2885 return Name;
2886
2887 return getDerived().RebuildTemplateName(TransParam,
2888 SubstPack->getArgumentPack());
2889 }
2890
2891 // These should be getting filtered out before they reach the AST.
2892 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002893}
2894
2895template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002896void TreeTransform<Derived>::InventTemplateArgumentLoc(
2897 const TemplateArgument &Arg,
2898 TemplateArgumentLoc &Output) {
2899 SourceLocation Loc = getDerived().getBaseLocation();
2900 switch (Arg.getKind()) {
2901 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002902 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002903 break;
2904
2905 case TemplateArgument::Type:
2906 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002907 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002908
John McCall833ca992009-10-29 08:12:44 +00002909 break;
2910
Douglas Gregor788cd062009-11-11 01:00:40 +00002911 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002912 case TemplateArgument::TemplateExpansion: {
2913 NestedNameSpecifierLocBuilder Builder;
2914 TemplateName Template = Arg.getAsTemplate();
2915 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2916 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2917 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2918 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2919
2920 if (Arg.getKind() == TemplateArgument::Template)
2921 Output = TemplateArgumentLoc(Arg,
2922 Builder.getWithLocInContext(SemaRef.Context),
2923 Loc);
2924 else
2925 Output = TemplateArgumentLoc(Arg,
2926 Builder.getWithLocInContext(SemaRef.Context),
2927 Loc, Loc);
2928
Douglas Gregor788cd062009-11-11 01:00:40 +00002929 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002930 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002931
John McCall833ca992009-10-29 08:12:44 +00002932 case TemplateArgument::Expression:
2933 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2934 break;
2935
2936 case TemplateArgument::Declaration:
2937 case TemplateArgument::Integral:
2938 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002939 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002940 break;
2941 }
2942}
2943
2944template<typename Derived>
2945bool TreeTransform<Derived>::TransformTemplateArgument(
2946 const TemplateArgumentLoc &Input,
2947 TemplateArgumentLoc &Output) {
2948 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002949 switch (Arg.getKind()) {
2950 case TemplateArgument::Null:
2951 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002952 Output = Input;
2953 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002954
Douglas Gregor670444e2009-08-04 22:27:00 +00002955 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002956 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002957 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002958 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002959
2960 DI = getDerived().TransformType(DI);
2961 if (!DI) return true;
2962
2963 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2964 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 }
Mike Stump1eb44332009-09-09 15:08:12 +00002966
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002968 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002969 DeclarationName Name;
2970 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2971 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002972 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002973 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002974 if (!D) return true;
2975
John McCall828bff22009-10-29 18:45:58 +00002976 Expr *SourceExpr = Input.getSourceDeclExpression();
2977 if (SourceExpr) {
2978 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002979 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002980 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002981 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002982 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002983 }
2984
2985 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002986 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002987 }
Mike Stump1eb44332009-09-09 15:08:12 +00002988
Douglas Gregor788cd062009-11-11 01:00:40 +00002989 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002990 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2991 if (QualifierLoc) {
2992 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2993 if (!QualifierLoc)
2994 return true;
2995 }
2996
Douglas Gregor1d752d72011-03-02 18:46:51 +00002997 CXXScopeSpec SS;
2998 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003000 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3001 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003002 if (Template.isNull())
3003 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003004
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003005 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003006 Input.getTemplateNameLoc());
3007 return false;
3008 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003009
3010 case TemplateArgument::TemplateExpansion:
3011 llvm_unreachable("Caller should expand pack expansions");
3012
Douglas Gregor670444e2009-08-04 22:27:00 +00003013 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003014 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003015 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003016 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003017
John McCall833ca992009-10-29 08:12:44 +00003018 Expr *InputExpr = Input.getSourceExpression();
3019 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3020
Chris Lattner223de242011-04-25 20:37:58 +00003021 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003022 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003023 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003024 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003025 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003026 }
Mike Stump1eb44332009-09-09 15:08:12 +00003027
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003029 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003030 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003031 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003032 AEnd = Arg.pack_end();
3033 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003034
John McCall833ca992009-10-29 08:12:44 +00003035 // FIXME: preserve source information here when we start
3036 // caring about parameter packs.
3037
John McCall828bff22009-10-29 18:45:58 +00003038 TemplateArgumentLoc InputArg;
3039 TemplateArgumentLoc OutputArg;
3040 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3041 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003042 return true;
3043
John McCall828bff22009-10-29 18:45:58 +00003044 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003046
3047 TemplateArgument *TransformedArgsPtr
3048 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3049 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3050 TransformedArgsPtr);
3051 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3052 TransformedArgs.size()),
3053 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003054 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 }
3056 }
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003059 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003060}
3061
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003062/// \brief Iterator adaptor that invents template argument location information
3063/// for each of the template arguments in its underlying iterator.
3064template<typename Derived, typename InputIterator>
3065class TemplateArgumentLocInventIterator {
3066 TreeTransform<Derived> &Self;
3067 InputIterator Iter;
3068
3069public:
3070 typedef TemplateArgumentLoc value_type;
3071 typedef TemplateArgumentLoc reference;
3072 typedef typename std::iterator_traits<InputIterator>::difference_type
3073 difference_type;
3074 typedef std::input_iterator_tag iterator_category;
3075
3076 class pointer {
3077 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003078
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003079 public:
3080 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3081
3082 const TemplateArgumentLoc *operator->() const { return &Arg; }
3083 };
3084
3085 TemplateArgumentLocInventIterator() { }
3086
3087 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3088 InputIterator Iter)
3089 : Self(Self), Iter(Iter) { }
3090
3091 TemplateArgumentLocInventIterator &operator++() {
3092 ++Iter;
3093 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003094 }
3095
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 TemplateArgumentLocInventIterator operator++(int) {
3097 TemplateArgumentLocInventIterator Old(*this);
3098 ++(*this);
3099 return Old;
3100 }
3101
3102 reference operator*() const {
3103 TemplateArgumentLoc Result;
3104 Self.InventTemplateArgumentLoc(*Iter, Result);
3105 return Result;
3106 }
3107
3108 pointer operator->() const { return pointer(**this); }
3109
3110 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3111 const TemplateArgumentLocInventIterator &Y) {
3112 return X.Iter == Y.Iter;
3113 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3116 const TemplateArgumentLocInventIterator &Y) {
3117 return X.Iter != Y.Iter;
3118 }
3119};
3120
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003121template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003122template<typename InputIterator>
3123bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3124 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003125 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003127 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003128 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003129
3130 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3131 // Unpack argument packs, which we translate them into separate
3132 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 // FIXME: We could do much better if we could guarantee that the
3134 // TemplateArgumentLocInfo for the pack expansion would be usable for
3135 // all of the template arguments in the argument pack.
3136 typedef TemplateArgumentLocInventIterator<Derived,
3137 TemplateArgument::pack_iterator>
3138 PackLocIterator;
3139 if (TransformTemplateArguments(PackLocIterator(*this,
3140 In.getArgument().pack_begin()),
3141 PackLocIterator(*this,
3142 In.getArgument().pack_end()),
3143 Outputs))
3144 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003145
3146 continue;
3147 }
3148
3149 if (In.getArgument().isPackExpansion()) {
3150 // We have a pack expansion, for which we will be substituting into
3151 // the pattern.
3152 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003153 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003154 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003155 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3156 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003157
Chris Lattner686775d2011-07-20 06:58:45 +00003158 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3160 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3161
3162 // Determine whether the set of unexpanded parameter packs can and should
3163 // be expanded.
3164 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003165 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003166 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003167 if (getDerived().TryExpandParameterPacks(Ellipsis,
3168 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003169 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003170 Expand,
3171 RetainExpansion,
3172 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003173 return true;
3174
3175 if (!Expand) {
3176 // The transform has determined that we should perform a simple
3177 // transformation on the pack expansion, producing another pack
3178 // expansion.
3179 TemplateArgumentLoc OutPattern;
3180 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3181 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3182 return true;
3183
Douglas Gregorcded4f62011-01-14 17:04:44 +00003184 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3185 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 if (Out.getArgument().isNull())
3187 return true;
3188
3189 Outputs.addArgument(Out);
3190 continue;
3191 }
3192
3193 // The transform has determined that we should perform an elementwise
3194 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003195 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3197
3198 if (getDerived().TransformTemplateArgument(Pattern, Out))
3199 return true;
3200
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003201 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003202 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3203 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003204 if (Out.getArgument().isNull())
3205 return true;
3206 }
3207
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003208 Outputs.addArgument(Out);
3209 }
3210
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003211 // If we're supposed to retain a pack expansion, do so by temporarily
3212 // forgetting the partially-substituted parameter pack.
3213 if (RetainExpansion) {
3214 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3215
3216 if (getDerived().TransformTemplateArgument(Pattern, Out))
3217 return true;
3218
Douglas Gregorcded4f62011-01-14 17:04:44 +00003219 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3220 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003221 if (Out.getArgument().isNull())
3222 return true;
3223
3224 Outputs.addArgument(Out);
3225 }
Douglas Gregord3731192011-01-10 07:32:04 +00003226
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 continue;
3228 }
3229
3230 // The simple case:
3231 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003232 return true;
3233
3234 Outputs.addArgument(Out);
3235 }
3236
3237 return false;
3238
3239}
3240
Douglas Gregor577f75a2009-08-04 16:50:30 +00003241//===----------------------------------------------------------------------===//
3242// Type transformation
3243//===----------------------------------------------------------------------===//
3244
3245template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003246QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003247 if (getDerived().AlreadyTransformed(T))
3248 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003249
John McCalla2becad2009-10-21 00:40:46 +00003250 // Temporary workaround. All of these transformations should
3251 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003252 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3253 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003254
John McCall43fed0d2010-11-12 08:19:04 +00003255 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003256
John McCalla2becad2009-10-21 00:40:46 +00003257 if (!NewDI)
3258 return QualType();
3259
3260 return NewDI->getType();
3261}
3262
3263template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003264TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003265 // Refine the base location to the type's location.
3266 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3267 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003268 if (getDerived().AlreadyTransformed(DI->getType()))
3269 return DI;
3270
3271 TypeLocBuilder TLB;
3272
3273 TypeLoc TL = DI->getTypeLoc();
3274 TLB.reserve(TL.getFullDataSize());
3275
John McCall43fed0d2010-11-12 08:19:04 +00003276 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return 0;
3279
John McCalla93c9342009-12-07 02:54:59 +00003280 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003281}
3282
3283template<typename Derived>
3284QualType
John McCall43fed0d2010-11-12 08:19:04 +00003285TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003286 switch (T.getTypeLocClass()) {
3287#define ABSTRACT_TYPELOC(CLASS, PARENT)
3288#define TYPELOC(CLASS, PARENT) \
3289 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003290 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003291#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003292 }
Mike Stump1eb44332009-09-09 15:08:12 +00003293
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003294 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003295}
3296
3297/// FIXME: By default, this routine adds type qualifiers only to types
3298/// that can have qualifiers, and silently suppresses those qualifiers
3299/// that are not permitted (e.g., qualifiers on reference or function
3300/// types). This is the right thing for template instantiation, but
3301/// probably not for other clients.
3302template<typename Derived>
3303QualType
3304TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003305 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003306 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003307
John McCall43fed0d2010-11-12 08:19:04 +00003308 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003309 if (Result.isNull())
3310 return QualType();
3311
3312 // Silently suppress qualifiers if the result type can't be qualified.
3313 // FIXME: this is the right thing for template instantiation, but
3314 // probably not for other clients.
3315 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003317
John McCallf85e1932011-06-15 23:02:42 +00003318 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003319 // resulting type.
3320 if (Quals.hasObjCLifetime()) {
3321 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3322 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003323 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003324 // Objective-C ARC:
3325 // A lifetime qualifier applied to a substituted template parameter
3326 // overrides the lifetime qualifier from the template argument.
3327 if (const SubstTemplateTypeParmType *SubstTypeParam
3328 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3329 QualType Replacement = SubstTypeParam->getReplacementType();
3330 Qualifiers Qs = Replacement.getQualifiers();
3331 Qs.removeObjCLifetime();
3332 Replacement
3333 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3334 Qs);
3335 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3336 SubstTypeParam->getReplacedParameter(),
3337 Replacement);
3338 TLB.TypeWasModifiedSafely(Result);
3339 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003340 // Otherwise, complain about the addition of a qualifier to an
3341 // already-qualified type.
3342 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003343 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003344 << Result << R;
3345
Douglas Gregore559ca12011-06-17 22:11:49 +00003346 Quals.removeObjCLifetime();
3347 }
3348 }
3349 }
John McCall28654742010-06-05 06:41:15 +00003350 if (!Quals.empty()) {
3351 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3352 TLB.push<QualifiedTypeLoc>(Result);
3353 // No location information to preserve.
3354 }
John McCalla2becad2009-10-21 00:40:46 +00003355
3356 return Result;
3357}
3358
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003359template<typename Derived>
3360TypeLoc
3361TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3362 QualType ObjectType,
3363 NamedDecl *UnqualLookup,
3364 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003365 QualType T = TL.getType();
3366 if (getDerived().AlreadyTransformed(T))
3367 return TL;
3368
3369 TypeLocBuilder TLB;
3370 QualType Result;
3371
3372 if (isa<TemplateSpecializationType>(T)) {
3373 TemplateSpecializationTypeLoc SpecTL
3374 = cast<TemplateSpecializationTypeLoc>(TL);
3375
3376 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003377 getDerived().TransformTemplateName(SS,
3378 SpecTL.getTypePtr()->getTemplateName(),
3379 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003380 ObjectType, UnqualLookup);
3381 if (Template.isNull())
3382 return TypeLoc();
3383
3384 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3385 Template);
3386 } else if (isa<DependentTemplateSpecializationType>(T)) {
3387 DependentTemplateSpecializationTypeLoc SpecTL
3388 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3389
Douglas Gregora88f09f2011-02-28 17:23:35 +00003390 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003391 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003392 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003393 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003394 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003395 if (Template.isNull())
3396 return TypeLoc();
3397
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003398 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003399 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003400 Template,
3401 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003402 } else {
3403 // Nothing special needs to be done for these.
3404 Result = getDerived().TransformType(TLB, TL);
3405 }
3406
3407 if (Result.isNull())
3408 return TypeLoc();
3409
3410 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3411}
3412
Douglas Gregorb71d8212011-03-02 18:32:08 +00003413template<typename Derived>
3414TypeSourceInfo *
3415TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3416 QualType ObjectType,
3417 NamedDecl *UnqualLookup,
3418 CXXScopeSpec &SS) {
3419 // FIXME: Painfully copy-paste from the above!
3420
3421 QualType T = TSInfo->getType();
3422 if (getDerived().AlreadyTransformed(T))
3423 return TSInfo;
3424
3425 TypeLocBuilder TLB;
3426 QualType Result;
3427
3428 TypeLoc TL = TSInfo->getTypeLoc();
3429 if (isa<TemplateSpecializationType>(T)) {
3430 TemplateSpecializationTypeLoc SpecTL
3431 = cast<TemplateSpecializationTypeLoc>(TL);
3432
3433 TemplateName Template
3434 = getDerived().TransformTemplateName(SS,
3435 SpecTL.getTypePtr()->getTemplateName(),
3436 SpecTL.getTemplateNameLoc(),
3437 ObjectType, UnqualLookup);
3438 if (Template.isNull())
3439 return 0;
3440
3441 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3442 Template);
3443 } else if (isa<DependentTemplateSpecializationType>(T)) {
3444 DependentTemplateSpecializationTypeLoc SpecTL
3445 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3446
3447 TemplateName Template
3448 = getDerived().RebuildTemplateName(SS,
3449 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003450 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003451 ObjectType, UnqualLookup);
3452 if (Template.isNull())
3453 return 0;
3454
3455 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3456 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003457 Template,
3458 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003459 } else {
3460 // Nothing special needs to be done for these.
3461 Result = getDerived().TransformType(TLB, TL);
3462 }
3463
3464 if (Result.isNull())
3465 return 0;
3466
3467 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3468}
3469
John McCalla2becad2009-10-21 00:40:46 +00003470template <class TyLoc> static inline
3471QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3472 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3473 NewT.setNameLoc(T.getNameLoc());
3474 return T.getType();
3475}
3476
John McCalla2becad2009-10-21 00:40:46 +00003477template<typename Derived>
3478QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003479 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003480 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3481 NewT.setBuiltinLoc(T.getBuiltinLoc());
3482 if (T.needsExtraLocalData())
3483 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3484 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003485}
Mike Stump1eb44332009-09-09 15:08:12 +00003486
Douglas Gregor577f75a2009-08-04 16:50:30 +00003487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003488QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003490 // FIXME: recurse?
3491 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492}
Mike Stump1eb44332009-09-09 15:08:12 +00003493
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003495QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003496 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003497 QualType PointeeType
3498 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003499 if (PointeeType.isNull())
3500 return QualType();
3501
3502 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003503 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003504 // A dependent pointer type 'T *' has is being transformed such
3505 // that an Objective-C class type is being replaced for 'T'. The
3506 // resulting pointer type is an ObjCObjectPointerType, not a
3507 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003508 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003509
John McCallc12c5bb2010-05-15 11:32:37 +00003510 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3511 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003512 return Result;
3513 }
John McCall43fed0d2010-11-12 08:19:04 +00003514
Douglas Gregor92e986e2010-04-22 16:44:27 +00003515 if (getDerived().AlwaysRebuild() ||
3516 PointeeType != TL.getPointeeLoc().getType()) {
3517 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3518 if (Result.isNull())
3519 return QualType();
3520 }
John McCallf85e1932011-06-15 23:02:42 +00003521
3522 // Objective-C ARC can add lifetime qualifiers to the type that we're
3523 // pointing to.
3524 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3525
Douglas Gregor92e986e2010-04-22 16:44:27 +00003526 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3527 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003528 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
3531template<typename Derived>
3532QualType
John McCalla2becad2009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003535 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003536 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3537 if (PointeeType.isNull())
3538 return QualType();
3539
3540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 PointeeType != TL.getPointeeLoc().getType()) {
3543 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003544 TL.getSigilLoc());
3545 if (Result.isNull())
3546 return QualType();
3547 }
3548
Douglas Gregor39968ad2010-04-22 16:50:51 +00003549 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003550 NewT.setSigilLoc(TL.getSigilLoc());
3551 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003552}
3553
John McCall85737a72009-10-30 00:06:24 +00003554/// Transforms a reference type. Note that somewhat paradoxically we
3555/// don't care whether the type itself is an l-value type or an r-value
3556/// type; we only care if the type was *written* as an l-value type
3557/// or an r-value type.
3558template<typename Derived>
3559QualType
3560TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003561 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003562 const ReferenceType *T = TL.getTypePtr();
3563
3564 // Note that this works with the pointee-as-written.
3565 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3566 if (PointeeType.isNull())
3567 return QualType();
3568
3569 QualType Result = TL.getType();
3570 if (getDerived().AlwaysRebuild() ||
3571 PointeeType != T->getPointeeTypeAsWritten()) {
3572 Result = getDerived().RebuildReferenceType(PointeeType,
3573 T->isSpelledAsLValue(),
3574 TL.getSigilLoc());
3575 if (Result.isNull())
3576 return QualType();
3577 }
3578
John McCallf85e1932011-06-15 23:02:42 +00003579 // Objective-C ARC can add lifetime qualifiers to the type that we're
3580 // referring to.
3581 TLB.TypeWasModifiedSafely(
3582 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3583
John McCall85737a72009-10-30 00:06:24 +00003584 // r-value references can be rebuilt as l-value references.
3585 ReferenceTypeLoc NewTL;
3586 if (isa<LValueReferenceType>(Result))
3587 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3588 else
3589 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3590 NewTL.setSigilLoc(TL.getSigilLoc());
3591
3592 return Result;
3593}
3594
Mike Stump1eb44332009-09-09 15:08:12 +00003595template<typename Derived>
3596QualType
John McCalla2becad2009-10-21 00:40:46 +00003597TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003598 LValueReferenceTypeLoc TL) {
3599 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003600}
3601
Mike Stump1eb44332009-09-09 15:08:12 +00003602template<typename Derived>
3603QualType
John McCalla2becad2009-10-21 00:40:46 +00003604TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003605 RValueReferenceTypeLoc TL) {
3606 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003607}
Mike Stump1eb44332009-09-09 15:08:12 +00003608
Douglas Gregor577f75a2009-08-04 16:50:30 +00003609template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003610QualType
John McCalla2becad2009-10-21 00:40:46 +00003611TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003612 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003613 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003614 if (PointeeType.isNull())
3615 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003616
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003617 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3618 TypeSourceInfo* NewClsTInfo = 0;
3619 if (OldClsTInfo) {
3620 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3621 if (!NewClsTInfo)
3622 return QualType();
3623 }
3624
3625 const MemberPointerType *T = TL.getTypePtr();
3626 QualType OldClsType = QualType(T->getClass(), 0);
3627 QualType NewClsType;
3628 if (NewClsTInfo)
3629 NewClsType = NewClsTInfo->getType();
3630 else {
3631 NewClsType = getDerived().TransformType(OldClsType);
3632 if (NewClsType.isNull())
3633 return QualType();
3634 }
Mike Stump1eb44332009-09-09 15:08:12 +00003635
John McCalla2becad2009-10-21 00:40:46 +00003636 QualType Result = TL.getType();
3637 if (getDerived().AlwaysRebuild() ||
3638 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003639 NewClsType != OldClsType) {
3640 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003641 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003642 if (Result.isNull())
3643 return QualType();
3644 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003645
John McCalla2becad2009-10-21 00:40:46 +00003646 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3647 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003648 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003649
3650 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651}
3652
Mike Stump1eb44332009-09-09 15:08:12 +00003653template<typename Derived>
3654QualType
John McCalla2becad2009-10-21 00:40:46 +00003655TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003656 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003657 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003658 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659 if (ElementType.isNull())
3660 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003661
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType Result = TL.getType();
3663 if (getDerived().AlwaysRebuild() ||
3664 ElementType != T->getElementType()) {
3665 Result = getDerived().RebuildConstantArrayType(ElementType,
3666 T->getSizeModifier(),
3667 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003668 T->getIndexTypeCVRQualifiers(),
3669 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003670 if (Result.isNull())
3671 return QualType();
3672 }
Eli Friedman457a3772012-01-25 22:19:07 +00003673
3674 // We might have either a ConstantArrayType or a VariableArrayType now:
3675 // a ConstantArrayType is allowed to have an element type which is a
3676 // VariableArrayType if the type is dependent. Fortunately, all array
3677 // types have the same location layout.
3678 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003679 NewTL.setLBracketLoc(TL.getLBracketLoc());
3680 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003681
John McCalla2becad2009-10-21 00:40:46 +00003682 Expr *Size = TL.getSizeExpr();
3683 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003684 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3685 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003686 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003687 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003688 }
3689 NewTL.setSizeExpr(Size);
3690
3691 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692}
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003696 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003700 if (ElementType.isNull())
3701 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
John McCalla2becad2009-10-21 00:40:46 +00003703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 ElementType != T->getElementType()) {
3706 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003708 T->getIndexTypeCVRQualifiers(),
3709 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003710 if (Result.isNull())
3711 return QualType();
3712 }
Sean Huntc3021132010-05-05 15:23:54 +00003713
John McCalla2becad2009-10-21 00:40:46 +00003714 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3715 NewTL.setLBracketLoc(TL.getLBracketLoc());
3716 NewTL.setRBracketLoc(TL.getRBracketLoc());
3717 NewTL.setSizeExpr(0);
3718
3719 return Result;
3720}
3721
3722template<typename Derived>
3723QualType
3724TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003725 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003726 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3728 if (ElementType.isNull())
3729 return QualType();
3730
John McCall60d7b3a2010-08-24 06:29:42 +00003731 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003732 = getDerived().TransformExpr(T->getSizeExpr());
3733 if (SizeResult.isInvalid())
3734 return QualType();
3735
John McCall9ae2f072010-08-23 23:25:46 +00003736 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003737
3738 QualType Result = TL.getType();
3739 if (getDerived().AlwaysRebuild() ||
3740 ElementType != T->getElementType() ||
3741 Size != T->getSizeExpr()) {
3742 Result = getDerived().RebuildVariableArrayType(ElementType,
3743 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003744 Size,
John McCalla2becad2009-10-21 00:40:46 +00003745 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003746 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003747 if (Result.isNull())
3748 return QualType();
3749 }
Sean Huntc3021132010-05-05 15:23:54 +00003750
John McCalla2becad2009-10-21 00:40:46 +00003751 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3752 NewTL.setLBracketLoc(TL.getLBracketLoc());
3753 NewTL.setRBracketLoc(TL.getRBracketLoc());
3754 NewTL.setSizeExpr(Size);
3755
3756 return Result;
3757}
3758
3759template<typename Derived>
3760QualType
3761TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003762 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003763 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003764 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3765 if (ElementType.isNull())
3766 return QualType();
3767
Richard Smithf6702a32011-12-20 02:08:33 +00003768 // Array bounds are constant expressions.
3769 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3770 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003771
John McCall3b657512011-01-19 10:06:00 +00003772 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3773 Expr *origSize = TL.getSizeExpr();
3774 if (!origSize) origSize = T->getSizeExpr();
3775
3776 ExprResult sizeResult
3777 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003778 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003779 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003780 return QualType();
3781
John McCall3b657512011-01-19 10:06:00 +00003782 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003783
3784 QualType Result = TL.getType();
3785 if (getDerived().AlwaysRebuild() ||
3786 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003787 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003788 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3789 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003790 size,
John McCalla2becad2009-10-21 00:40:46 +00003791 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003792 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003793 if (Result.isNull())
3794 return QualType();
3795 }
John McCalla2becad2009-10-21 00:40:46 +00003796
3797 // We might have any sort of array type now, but fortunately they
3798 // all have the same location layout.
3799 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3800 NewTL.setLBracketLoc(TL.getLBracketLoc());
3801 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003802 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003803
3804 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003805}
Mike Stump1eb44332009-09-09 15:08:12 +00003806
3807template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003808QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003809 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003810 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003811 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003812
3813 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814 QualType ElementType = getDerived().TransformType(T->getElementType());
3815 if (ElementType.isNull())
3816 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003817
Richard Smithf6702a32011-12-20 02:08:33 +00003818 // Vector sizes are constant expressions.
3819 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3820 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003821
John McCall60d7b3a2010-08-24 06:29:42 +00003822 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003823 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824 if (Size.isInvalid())
3825 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003826
John McCalla2becad2009-10-21 00:40:46 +00003827 QualType Result = TL.getType();
3828 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003829 ElementType != T->getElementType() ||
3830 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003831 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003832 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003834 if (Result.isNull())
3835 return QualType();
3836 }
John McCalla2becad2009-10-21 00:40:46 +00003837
3838 // Result might be dependent or not.
3839 if (isa<DependentSizedExtVectorType>(Result)) {
3840 DependentSizedExtVectorTypeLoc NewTL
3841 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3842 NewTL.setNameLoc(TL.getNameLoc());
3843 } else {
3844 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3845 NewTL.setNameLoc(TL.getNameLoc());
3846 }
3847
3848 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849}
Mike Stump1eb44332009-09-09 15:08:12 +00003850
3851template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003852QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003853 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003854 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003855 QualType ElementType = getDerived().TransformType(T->getElementType());
3856 if (ElementType.isNull())
3857 return QualType();
3858
John McCalla2becad2009-10-21 00:40:46 +00003859 QualType Result = TL.getType();
3860 if (getDerived().AlwaysRebuild() ||
3861 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003862 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003863 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003864 if (Result.isNull())
3865 return QualType();
3866 }
Sean Huntc3021132010-05-05 15:23:54 +00003867
John McCalla2becad2009-10-21 00:40:46 +00003868 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3869 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003870
John McCalla2becad2009-10-21 00:40:46 +00003871 return Result;
3872}
3873
3874template<typename Derived>
3875QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003876 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003877 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003878 QualType ElementType = getDerived().TransformType(T->getElementType());
3879 if (ElementType.isNull())
3880 return QualType();
3881
3882 QualType Result = TL.getType();
3883 if (getDerived().AlwaysRebuild() ||
3884 ElementType != T->getElementType()) {
3885 Result = getDerived().RebuildExtVectorType(ElementType,
3886 T->getNumElements(),
3887 /*FIXME*/ SourceLocation());
3888 if (Result.isNull())
3889 return QualType();
3890 }
Sean Huntc3021132010-05-05 15:23:54 +00003891
John McCalla2becad2009-10-21 00:40:46 +00003892 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3893 NewTL.setNameLoc(TL.getNameLoc());
3894
3895 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003896}
Mike Stump1eb44332009-09-09 15:08:12 +00003897
3898template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003899ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003900TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003901 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003902 llvm::Optional<unsigned> NumExpansions,
3903 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003904 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003905 TypeSourceInfo *NewDI = 0;
3906
3907 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3908 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003909 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003910 TypeLoc OldTL = OldDI->getTypeLoc();
3911 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3912
3913 TypeLocBuilder TLB;
3914 TypeLoc NewTL = OldDI->getTypeLoc();
3915 TLB.reserve(NewTL.getFullDataSize());
3916
3917 QualType Result = getDerived().TransformType(TLB,
3918 OldExpansionTL.getPatternLoc());
3919 if (Result.isNull())
3920 return 0;
3921
3922 Result = RebuildPackExpansionType(Result,
3923 OldExpansionTL.getPatternLoc().getSourceRange(),
3924 OldExpansionTL.getEllipsisLoc(),
3925 NumExpansions);
3926 if (Result.isNull())
3927 return 0;
3928
3929 PackExpansionTypeLoc NewExpansionTL
3930 = TLB.push<PackExpansionTypeLoc>(Result);
3931 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3932 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3933 } else
3934 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003935 if (!NewDI)
3936 return 0;
3937
John McCallfb44de92011-05-01 22:35:37 +00003938 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003939 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003940
3941 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3942 OldParm->getDeclContext(),
3943 OldParm->getInnerLocStart(),
3944 OldParm->getLocation(),
3945 OldParm->getIdentifier(),
3946 NewDI->getType(),
3947 NewDI,
3948 OldParm->getStorageClass(),
3949 OldParm->getStorageClassAsWritten(),
3950 /* DefArg */ NULL);
3951 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3952 OldParm->getFunctionScopeIndex() + indexAdjustment);
3953 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003954}
3955
3956template<typename Derived>
3957bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003958 TransformFunctionTypeParams(SourceLocation Loc,
3959 ParmVarDecl **Params, unsigned NumParams,
3960 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003961 SmallVectorImpl<QualType> &OutParamTypes,
3962 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003963 int indexAdjustment = 0;
3964
Douglas Gregora009b592011-01-07 00:20:55 +00003965 for (unsigned i = 0; i != NumParams; ++i) {
3966 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003967 assert(OldParm->getFunctionScopeIndex() == i);
3968
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003969 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003970 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 if (OldParm->isParameterPack()) {
3972 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003973 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003974
Douglas Gregor603cfb42011-01-05 23:12:31 +00003975 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003976 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3977 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3978 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3979 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003980 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3981
Douglas Gregor603cfb42011-01-05 23:12:31 +00003982 // Determine whether we should expand the parameter packs.
3983 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003984 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003985 llvm::Optional<unsigned> OrigNumExpansions
3986 = ExpansionTL.getTypePtr()->getNumExpansions();
3987 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003988 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3989 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003990 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003991 ShouldExpand,
3992 RetainExpansion,
3993 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 return true;
3995 }
3996
3997 if (ShouldExpand) {
3998 // Expand the function parameter pack into multiple, separate
3999 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004000 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004001 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4003 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004004 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004005 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004006 OrigNumExpansions,
4007 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004008 if (!NewParm)
4009 return true;
4010
Douglas Gregora009b592011-01-07 00:20:55 +00004011 OutParamTypes.push_back(NewParm->getType());
4012 if (PVars)
4013 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004014 }
Douglas Gregord3731192011-01-10 07:32:04 +00004015
4016 // If we're supposed to retain a pack expansion, do so by temporarily
4017 // forgetting the partially-substituted parameter pack.
4018 if (RetainExpansion) {
4019 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4020 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004021 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004022 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004023 OrigNumExpansions,
4024 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004025 if (!NewParm)
4026 return true;
4027
4028 OutParamTypes.push_back(NewParm->getType());
4029 if (PVars)
4030 PVars->push_back(NewParm);
4031 }
4032
John McCallfb44de92011-05-01 22:35:37 +00004033 // The next parameter should have the same adjustment as the
4034 // last thing we pushed, but we post-incremented indexAdjustment
4035 // on every push. Also, if we push nothing, the adjustment should
4036 // go down by one.
4037 indexAdjustment--;
4038
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 // We're done with the pack expansion.
4040 continue;
4041 }
4042
4043 // We'll substitute the parameter now without expanding the pack
4044 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004045 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4046 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004047 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004048 NumExpansions,
4049 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004050 } else {
4051 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004052 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004053 llvm::Optional<unsigned>(),
4054 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004056
John McCall21ef0fa2010-03-11 09:03:00 +00004057 if (!NewParm)
4058 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004059
Douglas Gregora009b592011-01-07 00:20:55 +00004060 OutParamTypes.push_back(NewParm->getType());
4061 if (PVars)
4062 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 continue;
4064 }
John McCall21ef0fa2010-03-11 09:03:00 +00004065
4066 // Deal with the possibility that we don't have a parameter
4067 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004068 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004070 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 if (const PackExpansionType *Expansion
4073 = dyn_cast<PackExpansionType>(OldType)) {
4074 // We have a function parameter pack that may need to be expanded.
4075 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004076 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004077 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4078
4079 // Determine whether we should expand the parameter packs.
4080 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004081 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004082 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004083 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004084 ShouldExpand,
4085 RetainExpansion,
4086 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004087 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 }
4089
4090 if (ShouldExpand) {
4091 // Expand the function parameter pack into multiple, separate
4092 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004093 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4095 QualType NewType = getDerived().TransformType(Pattern);
4096 if (NewType.isNull())
4097 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004098
Douglas Gregora009b592011-01-07 00:20:55 +00004099 OutParamTypes.push_back(NewType);
4100 if (PVars)
4101 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 }
4103
4104 // We're done with the pack expansion.
4105 continue;
4106 }
4107
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004108 // If we're supposed to retain a pack expansion, do so by temporarily
4109 // forgetting the partially-substituted parameter pack.
4110 if (RetainExpansion) {
4111 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4112 QualType NewType = getDerived().TransformType(Pattern);
4113 if (NewType.isNull())
4114 return true;
4115
4116 OutParamTypes.push_back(NewType);
4117 if (PVars)
4118 PVars->push_back(0);
4119 }
Douglas Gregord3731192011-01-10 07:32:04 +00004120
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 // We'll substitute the parameter now without expanding the pack
4122 // expansion.
4123 OldType = Expansion->getPattern();
4124 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004125 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4126 NewType = getDerived().TransformType(OldType);
4127 } else {
4128 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 }
4130
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 if (NewType.isNull())
4132 return true;
4133
4134 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004135 NewType = getSema().Context.getPackExpansionType(NewType,
4136 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004137
Douglas Gregora009b592011-01-07 00:20:55 +00004138 OutParamTypes.push_back(NewType);
4139 if (PVars)
4140 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004141 }
4142
John McCallfb44de92011-05-01 22:35:37 +00004143#ifndef NDEBUG
4144 if (PVars) {
4145 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4146 if (ParmVarDecl *parm = (*PVars)[i])
4147 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004148 }
John McCallfb44de92011-05-01 22:35:37 +00004149#endif
4150
4151 return false;
4152}
John McCall21ef0fa2010-03-11 09:03:00 +00004153
4154template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004155QualType
John McCalla2becad2009-10-21 00:40:46 +00004156TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004157 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004158 // Transform the parameters and return type.
4159 //
4160 // We instantiate in source order, with the return type first followed by
4161 // the parameters, because users tend to expect this (even if they shouldn't
4162 // rely on it!).
4163 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004164 // When the function has a trailing return type, we instantiate the
4165 // parameters before the return type, since the return type can then refer
4166 // to the parameters themselves (via decltype, sizeof, etc.).
4167 //
Chris Lattner686775d2011-07-20 06:58:45 +00004168 SmallVector<QualType, 4> ParamTypes;
4169 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004170 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004171
Douglas Gregordab60ad2010-10-01 18:44:50 +00004172 QualType ResultType;
4173
4174 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004175 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4176 TL.getParmArray(),
4177 TL.getNumArgs(),
4178 TL.getTypePtr()->arg_type_begin(),
4179 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004180 return QualType();
4181
4182 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4183 if (ResultType.isNull())
4184 return QualType();
4185 }
4186 else {
4187 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4188 if (ResultType.isNull())
4189 return QualType();
4190
Douglas Gregora009b592011-01-07 00:20:55 +00004191 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4192 TL.getParmArray(),
4193 TL.getNumArgs(),
4194 TL.getTypePtr()->arg_type_begin(),
4195 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004196 return QualType();
4197 }
4198
John McCalla2becad2009-10-21 00:40:46 +00004199 QualType Result = TL.getType();
4200 if (getDerived().AlwaysRebuild() ||
4201 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004202 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004203 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4204 Result = getDerived().RebuildFunctionProtoType(ResultType,
4205 ParamTypes.data(),
4206 ParamTypes.size(),
4207 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004208 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004209 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004210 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004211 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004212 if (Result.isNull())
4213 return QualType();
4214 }
Mike Stump1eb44332009-09-09 15:08:12 +00004215
John McCalla2becad2009-10-21 00:40:46 +00004216 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004217 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4218 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004219 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004220 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4221 NewTL.setArg(i, ParamDecls[i]);
4222
4223 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregor577f75a2009-08-04 16:50:30 +00004226template<typename Derived>
4227QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004228 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004229 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004230 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004231 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4232 if (ResultType.isNull())
4233 return QualType();
4234
4235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 ResultType != T->getResultType())
4238 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4239
4240 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004241 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4242 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004243 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004244
4245 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004246}
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCalled976492009-12-04 22:46:56 +00004248template<typename Derived> QualType
4249TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004250 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004251 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004252 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004253 if (!D)
4254 return QualType();
4255
4256 QualType Result = TL.getType();
4257 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4258 Result = getDerived().RebuildUnresolvedUsingType(D);
4259 if (Result.isNull())
4260 return QualType();
4261 }
4262
4263 // We might get an arbitrary type spec type back. We should at
4264 // least always get a type spec type, though.
4265 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4266 NewTL.setNameLoc(TL.getNameLoc());
4267
4268 return Result;
4269}
4270
Douglas Gregor577f75a2009-08-04 16:50:30 +00004271template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004272QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004273 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004274 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004275 TypedefNameDecl *Typedef
4276 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4277 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004278 if (!Typedef)
4279 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004280
John McCalla2becad2009-10-21 00:40:46 +00004281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() ||
4283 Typedef != T->getDecl()) {
4284 Result = getDerived().RebuildTypedefType(Typedef);
4285 if (Result.isNull())
4286 return QualType();
4287 }
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCalla2becad2009-10-21 00:40:46 +00004289 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4290 NewTL.setNameLoc(TL.getNameLoc());
4291
4292 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004293}
Mike Stump1eb44332009-09-09 15:08:12 +00004294
Douglas Gregor577f75a2009-08-04 16:50:30 +00004295template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004296QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004297 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004298 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004300
John McCall60d7b3a2010-08-24 06:29:42 +00004301 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004302 if (E.isInvalid())
4303 return QualType();
4304
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004305 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4306 if (E.isInvalid())
4307 return QualType();
4308
John McCalla2becad2009-10-21 00:40:46 +00004309 QualType Result = TL.getType();
4310 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004311 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004312 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004313 if (Result.isNull())
4314 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004315 }
John McCalla2becad2009-10-21 00:40:46 +00004316 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004317
John McCalla2becad2009-10-21 00:40:46 +00004318 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004319 NewTL.setTypeofLoc(TL.getTypeofLoc());
4320 NewTL.setLParenLoc(TL.getLParenLoc());
4321 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004322
4323 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004324}
Mike Stump1eb44332009-09-09 15:08:12 +00004325
4326template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004327QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004328 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004329 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4330 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4331 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004333
John McCalla2becad2009-10-21 00:40:46 +00004334 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004335 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4336 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004337 if (Result.isNull())
4338 return QualType();
4339 }
Mike Stump1eb44332009-09-09 15:08:12 +00004340
John McCalla2becad2009-10-21 00:40:46 +00004341 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004342 NewTL.setTypeofLoc(TL.getTypeofLoc());
4343 NewTL.setLParenLoc(TL.getLParenLoc());
4344 NewTL.setRParenLoc(TL.getRParenLoc());
4345 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004346
4347 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348}
Mike Stump1eb44332009-09-09 15:08:12 +00004349
4350template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004351QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004352 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004353 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004354
Douglas Gregor670444e2009-08-04 22:27:00 +00004355 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004356 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4357 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCall60d7b3a2010-08-24 06:29:42 +00004359 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (E.isInvalid())
4361 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Richard Smith76f3f692012-02-22 02:04:18 +00004363 E = getSema().ActOnDecltypeExpression(E.take());
4364 if (E.isInvalid())
4365 return QualType();
4366
John McCalla2becad2009-10-21 00:40:46 +00004367 QualType Result = TL.getType();
4368 if (getDerived().AlwaysRebuild() ||
4369 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004370 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004371 if (Result.isNull())
4372 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 }
John McCalla2becad2009-10-21 00:40:46 +00004374 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4377 NewTL.setNameLoc(TL.getNameLoc());
4378
4379 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380}
4381
4382template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004383QualType TreeTransform<Derived>::TransformUnaryTransformType(
4384 TypeLocBuilder &TLB,
4385 UnaryTransformTypeLoc TL) {
4386 QualType Result = TL.getType();
4387 if (Result->isDependentType()) {
4388 const UnaryTransformType *T = TL.getTypePtr();
4389 QualType NewBase =
4390 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4391 Result = getDerived().RebuildUnaryTransformType(NewBase,
4392 T->getUTTKind(),
4393 TL.getKWLoc());
4394 if (Result.isNull())
4395 return QualType();
4396 }
4397
4398 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4399 NewTL.setKWLoc(TL.getKWLoc());
4400 NewTL.setParensRange(TL.getParensRange());
4401 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4402 return Result;
4403}
4404
4405template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004406QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4407 AutoTypeLoc TL) {
4408 const AutoType *T = TL.getTypePtr();
4409 QualType OldDeduced = T->getDeducedType();
4410 QualType NewDeduced;
4411 if (!OldDeduced.isNull()) {
4412 NewDeduced = getDerived().TransformType(OldDeduced);
4413 if (NewDeduced.isNull())
4414 return QualType();
4415 }
4416
4417 QualType Result = TL.getType();
4418 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4419 Result = getDerived().RebuildAutoType(NewDeduced);
4420 if (Result.isNull())
4421 return QualType();
4422 }
4423
4424 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4425 NewTL.setNameLoc(TL.getNameLoc());
4426
4427 return Result;
4428}
4429
4430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004431QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004432 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004433 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004435 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4436 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004437 if (!Record)
4438 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalla2becad2009-10-21 00:40:46 +00004440 QualType Result = TL.getType();
4441 if (getDerived().AlwaysRebuild() ||
4442 Record != T->getDecl()) {
4443 Result = getDerived().RebuildRecordType(Record);
4444 if (Result.isNull())
4445 return QualType();
4446 }
Mike Stump1eb44332009-09-09 15:08:12 +00004447
John McCalla2becad2009-10-21 00:40:46 +00004448 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4449 NewTL.setNameLoc(TL.getNameLoc());
4450
4451 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452}
Mike Stump1eb44332009-09-09 15:08:12 +00004453
4454template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004455QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004456 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004457 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004458 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004459 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4460 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004461 if (!Enum)
4462 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004463
John McCalla2becad2009-10-21 00:40:46 +00004464 QualType Result = TL.getType();
4465 if (getDerived().AlwaysRebuild() ||
4466 Enum != T->getDecl()) {
4467 Result = getDerived().RebuildEnumType(Enum);
4468 if (Result.isNull())
4469 return QualType();
4470 }
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCalla2becad2009-10-21 00:40:46 +00004472 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4473 NewTL.setNameLoc(TL.getNameLoc());
4474
4475 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004476}
John McCall7da24312009-09-05 00:15:47 +00004477
John McCall3cb0ebd2010-03-10 03:28:59 +00004478template<typename Derived>
4479QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4480 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004481 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004482 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4483 TL.getTypePtr()->getDecl());
4484 if (!D) return QualType();
4485
4486 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4487 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4488 return T;
4489}
4490
Douglas Gregor577f75a2009-08-04 16:50:30 +00004491template<typename Derived>
4492QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004493 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004494 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004495 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004496}
4497
Mike Stump1eb44332009-09-09 15:08:12 +00004498template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004499QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004500 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004501 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004502 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4503
4504 // Substitute into the replacement type, which itself might involve something
4505 // that needs to be transformed. This only tends to occur with default
4506 // template arguments of template template parameters.
4507 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4508 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4509 if (Replacement.isNull())
4510 return QualType();
4511
4512 // Always canonicalize the replacement type.
4513 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4514 QualType Result
4515 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4516 Replacement);
4517
4518 // Propagate type-source information.
4519 SubstTemplateTypeParmTypeLoc NewTL
4520 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4521 NewTL.setNameLoc(TL.getNameLoc());
4522 return Result;
4523
John McCall49a832b2009-10-18 09:09:24 +00004524}
4525
4526template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004527QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4528 TypeLocBuilder &TLB,
4529 SubstTemplateTypeParmPackTypeLoc TL) {
4530 return TransformTypeSpecType(TLB, TL);
4531}
4532
4533template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004534QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004535 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004536 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004537 const TemplateSpecializationType *T = TL.getTypePtr();
4538
Douglas Gregor1d752d72011-03-02 18:46:51 +00004539 // The nested-name-specifier never matters in a TemplateSpecializationType,
4540 // because we can't have a dependent nested-name-specifier anyway.
4541 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004542 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004543 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4544 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004545 if (Template.isNull())
4546 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004547
John McCall43fed0d2010-11-12 08:19:04 +00004548 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4549}
4550
Eli Friedmanb001de72011-10-06 23:00:33 +00004551template<typename Derived>
4552QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4553 AtomicTypeLoc TL) {
4554 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4555 if (ValueType.isNull())
4556 return QualType();
4557
4558 QualType Result = TL.getType();
4559 if (getDerived().AlwaysRebuild() ||
4560 ValueType != TL.getValueLoc().getType()) {
4561 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4562 if (Result.isNull())
4563 return QualType();
4564 }
4565
4566 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4567 NewTL.setKWLoc(TL.getKWLoc());
4568 NewTL.setLParenLoc(TL.getLParenLoc());
4569 NewTL.setRParenLoc(TL.getRParenLoc());
4570
4571 return Result;
4572}
4573
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004574namespace {
4575 /// \brief Simple iterator that traverses the template arguments in a
4576 /// container that provides a \c getArgLoc() member function.
4577 ///
4578 /// This iterator is intended to be used with the iterator form of
4579 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4580 template<typename ArgLocContainer>
4581 class TemplateArgumentLocContainerIterator {
4582 ArgLocContainer *Container;
4583 unsigned Index;
4584
4585 public:
4586 typedef TemplateArgumentLoc value_type;
4587 typedef TemplateArgumentLoc reference;
4588 typedef int difference_type;
4589 typedef std::input_iterator_tag iterator_category;
4590
4591 class pointer {
4592 TemplateArgumentLoc Arg;
4593
4594 public:
4595 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4596
4597 const TemplateArgumentLoc *operator->() const {
4598 return &Arg;
4599 }
4600 };
4601
4602
4603 TemplateArgumentLocContainerIterator() {}
4604
4605 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4606 unsigned Index)
4607 : Container(&Container), Index(Index) { }
4608
4609 TemplateArgumentLocContainerIterator &operator++() {
4610 ++Index;
4611 return *this;
4612 }
4613
4614 TemplateArgumentLocContainerIterator operator++(int) {
4615 TemplateArgumentLocContainerIterator Old(*this);
4616 ++(*this);
4617 return Old;
4618 }
4619
4620 TemplateArgumentLoc operator*() const {
4621 return Container->getArgLoc(Index);
4622 }
4623
4624 pointer operator->() const {
4625 return pointer(Container->getArgLoc(Index));
4626 }
4627
4628 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004629 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004630 return X.Container == Y.Container && X.Index == Y.Index;
4631 }
4632
4633 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004634 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 return !(X == Y);
4636 }
4637 };
4638}
4639
4640
John McCall43fed0d2010-11-12 08:19:04 +00004641template <typename Derived>
4642QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4643 TypeLocBuilder &TLB,
4644 TemplateSpecializationTypeLoc TL,
4645 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004646 TemplateArgumentListInfo NewTemplateArgs;
4647 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4648 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4650 ArgIterator;
4651 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4652 ArgIterator(TL, TL.getNumArgs()),
4653 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004654 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004655
John McCall833ca992009-10-29 08:12:44 +00004656 // FIXME: maybe don't rebuild if all the template arguments are the same.
4657
4658 QualType Result =
4659 getDerived().RebuildTemplateSpecializationType(Template,
4660 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004661 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004662
4663 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004664 // Specializations of template template parameters are represented as
4665 // TemplateSpecializationTypes, and substitution of type alias templates
4666 // within a dependent context can transform them into
4667 // DependentTemplateSpecializationTypes.
4668 if (isa<DependentTemplateSpecializationType>(Result)) {
4669 DependentTemplateSpecializationTypeLoc NewTL
4670 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004671 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004672 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004673 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004674 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004675 NewTL.setLAngleLoc(TL.getLAngleLoc());
4676 NewTL.setRAngleLoc(TL.getRAngleLoc());
4677 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4678 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4679 return Result;
4680 }
4681
John McCall833ca992009-10-29 08:12:44 +00004682 TemplateSpecializationTypeLoc NewTL
4683 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004684 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004685 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4686 NewTL.setLAngleLoc(TL.getLAngleLoc());
4687 NewTL.setRAngleLoc(TL.getRAngleLoc());
4688 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4689 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004690 }
Mike Stump1eb44332009-09-09 15:08:12 +00004691
John McCall833ca992009-10-29 08:12:44 +00004692 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
Douglas Gregora88f09f2011-02-28 17:23:35 +00004695template <typename Derived>
4696QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4697 TypeLocBuilder &TLB,
4698 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004699 TemplateName Template,
4700 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004701 TemplateArgumentListInfo NewTemplateArgs;
4702 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4703 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4704 typedef TemplateArgumentLocContainerIterator<
4705 DependentTemplateSpecializationTypeLoc> ArgIterator;
4706 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4707 ArgIterator(TL, TL.getNumArgs()),
4708 NewTemplateArgs))
4709 return QualType();
4710
4711 // FIXME: maybe don't rebuild if all the template arguments are the same.
4712
4713 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4714 QualType Result
4715 = getSema().Context.getDependentTemplateSpecializationType(
4716 TL.getTypePtr()->getKeyword(),
4717 DTN->getQualifier(),
4718 DTN->getIdentifier(),
4719 NewTemplateArgs);
4720
4721 DependentTemplateSpecializationTypeLoc NewTL
4722 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004723 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004724 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004725 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004726 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004727 NewTL.setLAngleLoc(TL.getLAngleLoc());
4728 NewTL.setRAngleLoc(TL.getRAngleLoc());
4729 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4730 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4731 return Result;
4732 }
4733
4734 QualType Result
4735 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004736 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004737 NewTemplateArgs);
4738
4739 if (!Result.isNull()) {
4740 /// FIXME: Wrap this in an elaborated-type-specifier?
4741 TemplateSpecializationTypeLoc NewTL
4742 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004743 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004744 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004745 NewTL.setLAngleLoc(TL.getLAngleLoc());
4746 NewTL.setRAngleLoc(TL.getRAngleLoc());
4747 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4748 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4749 }
4750
4751 return Result;
4752}
4753
Mike Stump1eb44332009-09-09 15:08:12 +00004754template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004755QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004756TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004757 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004758 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004759
Douglas Gregor9e876872011-03-01 18:12:44 +00004760 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004761 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004762 if (TL.getQualifierLoc()) {
4763 QualifierLoc
4764 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4765 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004766 return QualType();
4767 }
Mike Stump1eb44332009-09-09 15:08:12 +00004768
John McCall43fed0d2010-11-12 08:19:04 +00004769 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4770 if (NamedT.isNull())
4771 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004772
Richard Smith3e4c6c42011-05-05 21:57:07 +00004773 // C++0x [dcl.type.elab]p2:
4774 // If the identifier resolves to a typedef-name or the simple-template-id
4775 // resolves to an alias template specialization, the
4776 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004777 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4778 if (const TemplateSpecializationType *TST =
4779 NamedT->getAs<TemplateSpecializationType>()) {
4780 TemplateName Template = TST->getTemplateName();
4781 if (TypeAliasTemplateDecl *TAT =
4782 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4783 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4784 diag::err_tag_reference_non_tag) << 4;
4785 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4786 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004787 }
4788 }
4789
John McCalla2becad2009-10-21 00:40:46 +00004790 QualType Result = TL.getType();
4791 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004792 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004793 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004794 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004795 T->getKeyword(),
4796 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004797 if (Result.isNull())
4798 return QualType();
4799 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004800
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004801 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004802 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004804 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004805}
Mike Stump1eb44332009-09-09 15:08:12 +00004806
4807template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004808QualType TreeTransform<Derived>::TransformAttributedType(
4809 TypeLocBuilder &TLB,
4810 AttributedTypeLoc TL) {
4811 const AttributedType *oldType = TL.getTypePtr();
4812 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4813 if (modifiedType.isNull())
4814 return QualType();
4815
4816 QualType result = TL.getType();
4817
4818 // FIXME: dependent operand expressions?
4819 if (getDerived().AlwaysRebuild() ||
4820 modifiedType != oldType->getModifiedType()) {
4821 // TODO: this is really lame; we should really be rebuilding the
4822 // equivalent type from first principles.
4823 QualType equivalentType
4824 = getDerived().TransformType(oldType->getEquivalentType());
4825 if (equivalentType.isNull())
4826 return QualType();
4827 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4828 modifiedType,
4829 equivalentType);
4830 }
4831
4832 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4833 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4834 if (TL.hasAttrOperand())
4835 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4836 if (TL.hasAttrExprOperand())
4837 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4838 else if (TL.hasAttrEnumOperand())
4839 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4840
4841 return result;
4842}
4843
4844template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004845QualType
4846TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4847 ParenTypeLoc TL) {
4848 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4849 if (Inner.isNull())
4850 return QualType();
4851
4852 QualType Result = TL.getType();
4853 if (getDerived().AlwaysRebuild() ||
4854 Inner != TL.getInnerLoc().getType()) {
4855 Result = getDerived().RebuildParenType(Inner);
4856 if (Result.isNull())
4857 return QualType();
4858 }
4859
4860 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4861 NewTL.setLParenLoc(TL.getLParenLoc());
4862 NewTL.setRParenLoc(TL.getRParenLoc());
4863 return Result;
4864}
4865
4866template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004867QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004868 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004869 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004870
Douglas Gregor2494dd02011-03-01 01:34:45 +00004871 NestedNameSpecifierLoc QualifierLoc
4872 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4873 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004874 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004875
John McCall33500952010-06-11 00:33:02 +00004876 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004877 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004878 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004879 QualifierLoc,
4880 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004881 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004882 if (Result.isNull())
4883 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004884
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004885 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4886 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004887 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4888
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004889 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004890 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004891 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004892 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004893 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004894 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004895 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004896 NewTL.setNameLoc(TL.getNameLoc());
4897 }
John McCalla2becad2009-10-21 00:40:46 +00004898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004899}
Mike Stump1eb44332009-09-09 15:08:12 +00004900
Douglas Gregor577f75a2009-08-04 16:50:30 +00004901template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004902QualType TreeTransform<Derived>::
4903 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004904 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004905 NestedNameSpecifierLoc QualifierLoc;
4906 if (TL.getQualifierLoc()) {
4907 QualifierLoc
4908 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4909 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004910 return QualType();
4911 }
4912
John McCall43fed0d2010-11-12 08:19:04 +00004913 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004914 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004915}
4916
4917template<typename Derived>
4918QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004919TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4920 DependentTemplateSpecializationTypeLoc TL,
4921 NestedNameSpecifierLoc QualifierLoc) {
4922 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4923
4924 TemplateArgumentListInfo NewTemplateArgs;
4925 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4926 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4927
4928 typedef TemplateArgumentLocContainerIterator<
4929 DependentTemplateSpecializationTypeLoc> ArgIterator;
4930 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4931 ArgIterator(TL, TL.getNumArgs()),
4932 NewTemplateArgs))
4933 return QualType();
4934
4935 QualType Result
4936 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4937 QualifierLoc,
4938 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004939 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 NewTemplateArgs);
4941 if (Result.isNull())
4942 return QualType();
4943
4944 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4945 QualType NamedT = ElabT->getNamedType();
4946
4947 // Copy information relevant to the template specialization.
4948 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004949 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004950 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004951 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004952 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4953 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004954 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004955 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004956
4957 // Copy information relevant to the elaborated type.
4958 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004959 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004961 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4962 DependentTemplateSpecializationTypeLoc SpecTL
4963 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004964 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004965 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004966 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004967 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004968 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4969 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004970 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004971 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004972 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004973 TemplateSpecializationTypeLoc SpecTL
4974 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004975 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004976 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004977 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4978 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004979 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004980 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 }
4982 return Result;
4983}
4984
4985template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004986QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4987 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004988 QualType Pattern
4989 = getDerived().TransformType(TLB, TL.getPatternLoc());
4990 if (Pattern.isNull())
4991 return QualType();
4992
4993 QualType Result = TL.getType();
4994 if (getDerived().AlwaysRebuild() ||
4995 Pattern != TL.getPatternLoc().getType()) {
4996 Result = getDerived().RebuildPackExpansionType(Pattern,
4997 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004998 TL.getEllipsisLoc(),
4999 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005000 if (Result.isNull())
5001 return QualType();
5002 }
5003
5004 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5005 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5006 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005007}
5008
5009template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005010QualType
5011TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005012 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005013 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005014 TLB.pushFullCopy(TL);
5015 return TL.getType();
5016}
5017
5018template<typename Derived>
5019QualType
5020TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005021 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005022 // ObjCObjectType is never dependent.
5023 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005024 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005025}
Mike Stump1eb44332009-09-09 15:08:12 +00005026
5027template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005028QualType
5029TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005030 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005031 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005032 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005033 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005034}
5035
Douglas Gregor577f75a2009-08-04 16:50:30 +00005036//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005037// Statement transformation
5038//===----------------------------------------------------------------------===//
5039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005040StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005041TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005042 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005043}
5044
5045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005046StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005047TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5048 return getDerived().TransformCompoundStmt(S, false);
5049}
5050
5051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005053TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005054 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005055 Sema::CompoundScopeRAII CompoundScope(getSema());
5056
John McCall7114cba2010-08-27 19:56:05 +00005057 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005058 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005059 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005060 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5061 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005062 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005063 if (Result.isInvalid()) {
5064 // Immediately fail if this was a DeclStmt, since it's very
5065 // likely that this will cause problems for future statements.
5066 if (isa<DeclStmt>(*B))
5067 return StmtError();
5068
5069 // Otherwise, just keep processing substatements and fail later.
5070 SubStmtInvalid = true;
5071 continue;
5072 }
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregor43959a92009-08-20 07:17:43 +00005074 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5075 Statements.push_back(Result.takeAs<Stmt>());
5076 }
Mike Stump1eb44332009-09-09 15:08:12 +00005077
John McCall7114cba2010-08-27 19:56:05 +00005078 if (SubStmtInvalid)
5079 return StmtError();
5080
Douglas Gregor43959a92009-08-20 07:17:43 +00005081 if (!getDerived().AlwaysRebuild() &&
5082 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005084
5085 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5086 move_arg(Statements),
5087 S->getRBracLoc(),
5088 IsStmtExpr);
5089}
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005094 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005095 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005096 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5097 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Eli Friedman264c1f82009-11-19 03:14:00 +00005099 // Transform the left-hand case value.
5100 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005101 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005102 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Eli Friedman264c1f82009-11-19 03:14:00 +00005105 // Transform the right-hand case value (for the GNU case-range extension).
5106 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005107 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005108 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005109 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005110 }
Mike Stump1eb44332009-09-09 15:08:12 +00005111
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Build the case statement.
5113 // Case statements are always rebuilt so that they will attached to their
5114 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005115 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005116 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005118 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 S->getColonLoc());
5120 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005124 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005129 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005130}
5131
5132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005135 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005136 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005138 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregor43959a92009-08-20 07:17:43 +00005140 // Default statements are always rebuilt
5141 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005142 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005143}
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregor43959a92009-08-20 07:17:43 +00005145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005146StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005147TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005148 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005149 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005151
Chris Lattner57ad3782011-02-17 20:34:02 +00005152 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5153 S->getDecl());
5154 if (!LD)
5155 return StmtError();
5156
5157
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005159 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005160 cast<LabelDecl>(LD), SourceLocation(),
5161 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005162}
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005165StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005166TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005168 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005169 VarDecl *ConditionVar = 0;
5170 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005171 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005172 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005173 getDerived().TransformDefinition(
5174 S->getConditionVariable()->getLocation(),
5175 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005176 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005178 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005179 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005180
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005181 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005182 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005183
5184 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005185 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005186 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5187 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005188 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005189 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005190
John McCall9ae2f072010-08-23 23:25:46 +00005191 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005192 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005193 }
Sean Huntc3021132010-05-05 15:23:54 +00005194
John McCall9ae2f072010-08-23 23:25:46 +00005195 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5196 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005200 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005201 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005205 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005210 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005211 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 Then.get() == S->getThen() &&
5213 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005214 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005216 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005217 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005218 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219}
5220
5221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 }
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005243 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005244 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005245 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005247 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005248
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005250 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005253
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005255 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5256 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005257}
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005260StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005261TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005262 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005263 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005264 VarDecl *ConditionVar = 0;
5265 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005266 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005267 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005268 getDerived().TransformDefinition(
5269 S->getConditionVariable()->getLocation(),
5270 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005271 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005274 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005275
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005276 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005278
5279 if (S->getCond()) {
5280 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005281 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5282 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005283 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005284 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005285 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005286 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005287 }
Mike Stump1eb44332009-09-09 15:08:12 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5290 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005294 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005299 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005302 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005304 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005305 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005306}
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005309StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005310TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005316 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005317 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005318 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (!getDerived().AlwaysRebuild() &&
5322 Cond.get() == S->getCond() &&
5323 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005324 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005325
John McCall9ae2f072010-08-23 23:25:46 +00005326 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5327 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 S->getRParenLoc());
5329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005340 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 VarDecl *ConditionVar = 0;
5342 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005343 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005345 getDerived().TransformDefinition(
5346 S->getConditionVariable()->getLocation(),
5347 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005348 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 } else {
5351 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005352
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005355
5356 if (S->getCond()) {
5357 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005358 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5359 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005360 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005362
John McCall9ae2f072010-08-23 23:25:46 +00005363 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005364 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005365 }
Mike Stump1eb44332009-09-09 15:08:12 +00005366
John McCall9ae2f072010-08-23 23:25:46 +00005367 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5368 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005372 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005375
John McCall9ae2f072010-08-23 23:25:46 +00005376 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5377 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005381 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (!getDerived().AlwaysRebuild() &&
5386 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005387 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 Inc.get() == S->getInc() &&
5389 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005390 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005393 Init.get(), FullCond, ConditionVar,
5394 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005395}
5396
5397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005398StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005399TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005400 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5401 S->getLabel());
5402 if (!LD)
5403 return StmtError();
5404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005406 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005407 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005408}
5409
5410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005416 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 if (!getDerived().AlwaysRebuild() &&
5419 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005420 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005421
5422 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005423 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424}
5425
5426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005427StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005428TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005429 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005430}
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregor43959a92009-08-20 07:17:43 +00005432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005433StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005434TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005435 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005436}
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005439StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005441 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005444
Mike Stump1eb44332009-09-09 15:08:12 +00005445 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005447 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005451StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005452TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005454 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5456 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005457 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5458 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 if (Transformed != *D)
5463 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 Decls.push_back(Transformed);
5466 }
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005470
5471 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 S->getStartLoc(), S->getEndLoc());
5473}
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005476StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005477TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005478
John McCallca0408f2010-08-23 06:44:23 +00005479 ASTOwningVector<Expr*> Constraints(getSema());
5480 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005481 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005482
John McCall60d7b3a2010-08-24 06:29:42 +00005483 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005484 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005485
5486 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005487
Anders Carlsson703e3942010-01-24 05:50:09 +00005488 // Go through the outputs.
5489 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005490 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005491
Anders Carlsson703e3942010-01-24 05:50:09 +00005492 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005493 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005494
Anders Carlsson703e3942010-01-24 05:50:09 +00005495 // Transform the output expr.
5496 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005497 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005498 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005500
Anders Carlsson703e3942010-01-24 05:50:09 +00005501 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005502
John McCall9ae2f072010-08-23 23:25:46 +00005503 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005504 }
Sean Huntc3021132010-05-05 15:23:54 +00005505
Anders Carlsson703e3942010-01-24 05:50:09 +00005506 // Go through the inputs.
5507 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005508 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005509
Anders Carlsson703e3942010-01-24 05:50:09 +00005510 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005511 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005512
Anders Carlsson703e3942010-01-24 05:50:09 +00005513 // Transform the input expr.
5514 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005515 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005516 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005518
Anders Carlsson703e3942010-01-24 05:50:09 +00005519 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005522 }
Sean Huntc3021132010-05-05 15:23:54 +00005523
Anders Carlsson703e3942010-01-24 05:50:09 +00005524 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005526
5527 // Go through the clobbers.
5528 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005529 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005530
5531 // No need to transform the asm string literal.
5532 AsmString = SemaRef.Owned(S->getAsmString());
5533
5534 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5535 S->isSimple(),
5536 S->isVolatile(),
5537 S->getNumOutputs(),
5538 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005539 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005540 move_arg(Constraints),
5541 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005542 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005543 move_arg(Clobbers),
5544 S->getRParenLoc(),
5545 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005546}
5547
5548
5549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005551TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005552 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005553 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005554 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005556
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005557 // Transform the @catch statements (if present).
5558 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005559 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005560 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005561 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005562 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005564 if (Catch.get() != S->getCatchStmt(I))
5565 AnyCatchChanged = true;
5566 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005567 }
Sean Huntc3021132010-05-05 15:23:54 +00005568
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005569 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005570 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005571 if (S->getFinallyStmt()) {
5572 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5573 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005575 }
5576
5577 // If nothing changed, just retain this statement.
5578 if (!getDerived().AlwaysRebuild() &&
5579 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005580 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005581 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005582 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005583
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005584 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005585 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5586 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005587}
Mike Stump1eb44332009-09-09 15:08:12 +00005588
Douglas Gregor43959a92009-08-20 07:17:43 +00005589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005590StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005591TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005592 // Transform the @catch parameter, if there is one.
5593 VarDecl *Var = 0;
5594 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5595 TypeSourceInfo *TSInfo = 0;
5596 if (FromVar->getTypeSourceInfo()) {
5597 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5598 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005599 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005600 }
Sean Huntc3021132010-05-05 15:23:54 +00005601
Douglas Gregorbe270a02010-04-26 17:57:08 +00005602 QualType T;
5603 if (TSInfo)
5604 T = TSInfo->getType();
5605 else {
5606 T = getDerived().TransformType(FromVar->getType());
5607 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005608 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005609 }
Sean Huntc3021132010-05-05 15:23:54 +00005610
Douglas Gregorbe270a02010-04-26 17:57:08 +00005611 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5612 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005613 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005614 }
Sean Huntc3021132010-05-05 15:23:54 +00005615
John McCall60d7b3a2010-08-24 06:29:42 +00005616 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005617 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005619
5620 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005621 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005622 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005623}
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregor43959a92009-08-20 07:17:43 +00005625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005626StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005629 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005630 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005631 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005632
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 // If nothing changed, just retain this statement.
5634 if (!getDerived().AlwaysRebuild() &&
5635 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005636 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637
5638 // Build a new statement.
5639 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005640 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005641}
Mike Stump1eb44332009-09-09 15:08:12 +00005642
Douglas Gregor43959a92009-08-20 07:17:43 +00005643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005644StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005645TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005646 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005647 if (S->getThrowExpr()) {
5648 Operand = getDerived().TransformExpr(S->getThrowExpr());
5649 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005651 }
Sean Huntc3021132010-05-05 15:23:54 +00005652
Douglas Gregord1377b22010-04-22 21:44:01 +00005653 if (!getDerived().AlwaysRebuild() &&
5654 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005655 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005656
John McCall9ae2f072010-08-23 23:25:46 +00005657 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005658}
Mike Stump1eb44332009-09-09 15:08:12 +00005659
Douglas Gregor43959a92009-08-20 07:17:43 +00005660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005661StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005662TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005663 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005664 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005665 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005666 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005668 Object =
5669 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5670 Object.get());
5671 if (Object.isInvalid())
5672 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005673
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005674 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005675 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005676 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005677 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005678
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005679 // If nothing change, just retain the current statement.
5680 if (!getDerived().AlwaysRebuild() &&
5681 Object.get() == S->getSynchExpr() &&
5682 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005683 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005684
5685 // Build a new statement.
5686 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005688}
5689
5690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005691StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005692TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5693 ObjCAutoreleasePoolStmt *S) {
5694 // Transform the body.
5695 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5696 if (Body.isInvalid())
5697 return StmtError();
5698
5699 // If nothing changed, just retain this statement.
5700 if (!getDerived().AlwaysRebuild() &&
5701 Body.get() == S->getSubStmt())
5702 return SemaRef.Owned(S);
5703
5704 // Build a new statement.
5705 return getDerived().RebuildObjCAutoreleasePoolStmt(
5706 S->getAtLoc(), Body.get());
5707}
5708
5709template<typename Derived>
5710StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005711TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005712 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005713 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005714 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005715 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005717
Douglas Gregorc3203e72010-04-22 23:10:45 +00005718 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005720 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005721 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005722 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5723 Collection.take());
5724 if (Collection.isInvalid())
5725 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005726
Douglas Gregorc3203e72010-04-22 23:10:45 +00005727 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005728 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005729 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005731
Douglas Gregorc3203e72010-04-22 23:10:45 +00005732 // If nothing changed, just retain this statement.
5733 if (!getDerived().AlwaysRebuild() &&
5734 Element.get() == S->getElement() &&
5735 Collection.get() == S->getCollection() &&
5736 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005737 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005738
Douglas Gregorc3203e72010-04-22 23:10:45 +00005739 // Build a new statement.
5740 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5741 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005742 Element.get(),
5743 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005744 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005745 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005746}
5747
5748
5749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005750StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005751TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5752 // Transform the exception declaration, if any.
5753 VarDecl *Var = 0;
5754 if (S->getExceptionDecl()) {
5755 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005756 TypeSourceInfo *T = getDerived().TransformType(
5757 ExceptionDecl->getTypeSourceInfo());
5758 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005759 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005760
Douglas Gregor83cb9422010-09-09 17:09:21 +00005761 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005762 ExceptionDecl->getInnerLocStart(),
5763 ExceptionDecl->getLocation(),
5764 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005765 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005766 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005767 }
Mike Stump1eb44332009-09-09 15:08:12 +00005768
Douglas Gregor43959a92009-08-20 07:17:43 +00005769 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005770 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005771 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005772 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005773
Douglas Gregor43959a92009-08-20 07:17:43 +00005774 if (!getDerived().AlwaysRebuild() &&
5775 !Var &&
5776 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005777 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005778
5779 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5780 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005781 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005782}
Mike Stump1eb44332009-09-09 15:08:12 +00005783
Douglas Gregor43959a92009-08-20 07:17:43 +00005784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005785StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005786TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5787 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005788 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005789 = getDerived().TransformCompoundStmt(S->getTryBlock());
5790 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005792
Douglas Gregor43959a92009-08-20 07:17:43 +00005793 // Transform the handlers.
5794 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005795 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005796 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005797 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005798 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5799 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor43959a92009-08-20 07:17:43 +00005802 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5803 Handlers.push_back(Handler.takeAs<Stmt>());
5804 }
Mike Stump1eb44332009-09-09 15:08:12 +00005805
Douglas Gregor43959a92009-08-20 07:17:43 +00005806 if (!getDerived().AlwaysRebuild() &&
5807 TryBlock.get() == S->getTryBlock() &&
5808 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005809 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005810
John McCall9ae2f072010-08-23 23:25:46 +00005811 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005812 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005813}
Mike Stump1eb44332009-09-09 15:08:12 +00005814
Richard Smithad762fc2011-04-14 22:09:26 +00005815template<typename Derived>
5816StmtResult
5817TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5818 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5819 if (Range.isInvalid())
5820 return StmtError();
5821
5822 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5823 if (BeginEnd.isInvalid())
5824 return StmtError();
5825
5826 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5827 if (Cond.isInvalid())
5828 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005829 if (Cond.get())
5830 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5831 if (Cond.isInvalid())
5832 return StmtError();
5833 if (Cond.get())
5834 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005835
5836 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5837 if (Inc.isInvalid())
5838 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005839 if (Inc.get())
5840 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005841
5842 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5843 if (LoopVar.isInvalid())
5844 return StmtError();
5845
5846 StmtResult NewStmt = S;
5847 if (getDerived().AlwaysRebuild() ||
5848 Range.get() != S->getRangeStmt() ||
5849 BeginEnd.get() != S->getBeginEndStmt() ||
5850 Cond.get() != S->getCond() ||
5851 Inc.get() != S->getInc() ||
5852 LoopVar.get() != S->getLoopVarStmt())
5853 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5854 S->getColonLoc(), Range.get(),
5855 BeginEnd.get(), Cond.get(),
5856 Inc.get(), LoopVar.get(),
5857 S->getRParenLoc());
5858
5859 StmtResult Body = getDerived().TransformStmt(S->getBody());
5860 if (Body.isInvalid())
5861 return StmtError();
5862
5863 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5864 // it now so we have a new statement to attach the body to.
5865 if (Body.get() != S->getBody() && NewStmt.get() == S)
5866 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5867 S->getColonLoc(), Range.get(),
5868 BeginEnd.get(), Cond.get(),
5869 Inc.get(), LoopVar.get(),
5870 S->getRParenLoc());
5871
5872 if (NewStmt.get() == S)
5873 return SemaRef.Owned(S);
5874
5875 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5876}
5877
John Wiegley28bbe4b2011-04-28 01:08:34 +00005878template<typename Derived>
5879StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005880TreeTransform<Derived>::TransformMSDependentExistsStmt(
5881 MSDependentExistsStmt *S) {
5882 // Transform the nested-name-specifier, if any.
5883 NestedNameSpecifierLoc QualifierLoc;
5884 if (S->getQualifierLoc()) {
5885 QualifierLoc
5886 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5887 if (!QualifierLoc)
5888 return StmtError();
5889 }
5890
5891 // Transform the declaration name.
5892 DeclarationNameInfo NameInfo = S->getNameInfo();
5893 if (NameInfo.getName()) {
5894 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5895 if (!NameInfo.getName())
5896 return StmtError();
5897 }
5898
5899 // Check whether anything changed.
5900 if (!getDerived().AlwaysRebuild() &&
5901 QualifierLoc == S->getQualifierLoc() &&
5902 NameInfo.getName() == S->getNameInfo().getName())
5903 return S;
5904
5905 // Determine whether this name exists, if we can.
5906 CXXScopeSpec SS;
5907 SS.Adopt(QualifierLoc);
5908 bool Dependent = false;
5909 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5910 case Sema::IER_Exists:
5911 if (S->isIfExists())
5912 break;
5913
5914 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5915
5916 case Sema::IER_DoesNotExist:
5917 if (S->isIfNotExists())
5918 break;
5919
5920 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5921
5922 case Sema::IER_Dependent:
5923 Dependent = true;
5924 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005925
5926 case Sema::IER_Error:
5927 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005928 }
5929
5930 // We need to continue with the instantiation, so do so now.
5931 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5932 if (SubStmt.isInvalid())
5933 return StmtError();
5934
5935 // If we have resolved the name, just transform to the substatement.
5936 if (!Dependent)
5937 return SubStmt;
5938
5939 // The name is still dependent, so build a dependent expression again.
5940 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5941 S->isIfExists(),
5942 QualifierLoc,
5943 NameInfo,
5944 SubStmt.get());
5945}
5946
5947template<typename Derived>
5948StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005949TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5950 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5951 if(TryBlock.isInvalid()) return StmtError();
5952
5953 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5954 if(!getDerived().AlwaysRebuild() &&
5955 TryBlock.get() == S->getTryBlock() &&
5956 Handler.get() == S->getHandler())
5957 return SemaRef.Owned(S);
5958
5959 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5960 S->getTryLoc(),
5961 TryBlock.take(),
5962 Handler.take());
5963}
5964
5965template<typename Derived>
5966StmtResult
5967TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5968 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5969 if(Block.isInvalid()) return StmtError();
5970
5971 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5972 Block.take());
5973}
5974
5975template<typename Derived>
5976StmtResult
5977TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5978 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5979 if(FilterExpr.isInvalid()) return StmtError();
5980
5981 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5982 if(Block.isInvalid()) return StmtError();
5983
5984 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5985 FilterExpr.take(),
5986 Block.take());
5987}
5988
5989template<typename Derived>
5990StmtResult
5991TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5992 if(isa<SEHFinallyStmt>(Handler))
5993 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5994 else
5995 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5996}
5997
Douglas Gregor43959a92009-08-20 07:17:43 +00005998//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005999// Expression transformation
6000//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006002ExprResult
John McCall454feb92009-12-08 09:21:05 +00006003TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006004 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005}
Mike Stump1eb44332009-09-09 15:08:12 +00006006
6007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006008ExprResult
John McCall454feb92009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006010 NestedNameSpecifierLoc QualifierLoc;
6011 if (E->getQualifierLoc()) {
6012 QualifierLoc
6013 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6014 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006015 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006016 }
John McCalldbd872f2009-12-08 09:08:17 +00006017
6018 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006019 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6020 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006023
John McCallec8045d2010-08-17 21:27:17 +00006024 DeclarationNameInfo NameInfo = E->getNameInfo();
6025 if (NameInfo.getName()) {
6026 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6027 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006028 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006029 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006030
6031 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006032 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006033 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006034 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006035 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006036
6037 // Mark it referenced in the new context regardless.
6038 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006039 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006040
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006042 }
John McCalldbd872f2009-12-08 09:08:17 +00006043
6044 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006045 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006046 TemplateArgs = &TransArgs;
6047 TransArgs.setLAngleLoc(E->getLAngleLoc());
6048 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006049 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6050 E->getNumTemplateArgs(),
6051 TransArgs))
6052 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006053 }
6054
Douglas Gregor40d96a62011-02-28 21:54:11 +00006055 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6056 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057}
Mike Stump1eb44332009-09-09 15:08:12 +00006058
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006060ExprResult
John McCall454feb92009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006062 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006063}
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006066ExprResult
John McCall454feb92009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006068 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069}
Mike Stump1eb44332009-09-09 15:08:12 +00006070
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
John McCall454feb92009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075}
Mike Stump1eb44332009-09-09 15:08:12 +00006076
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006078ExprResult
John McCall454feb92009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081}
Mike Stump1eb44332009-09-09 15:08:12 +00006082
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006084ExprResult
John McCall454feb92009-12-08 09:21:05 +00006085TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006086 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006087}
6088
6089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006090ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006091TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6092 return SemaRef.MaybeBindToTemporary(E);
6093}
6094
6095template<typename Derived>
6096ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006097TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6098 ExprResult ControllingExpr =
6099 getDerived().TransformExpr(E->getControllingExpr());
6100 if (ControllingExpr.isInvalid())
6101 return ExprError();
6102
Chris Lattner686775d2011-07-20 06:58:45 +00006103 SmallVector<Expr *, 4> AssocExprs;
6104 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006105 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6106 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6107 if (TS) {
6108 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6109 if (!AssocType)
6110 return ExprError();
6111 AssocTypes.push_back(AssocType);
6112 } else {
6113 AssocTypes.push_back(0);
6114 }
6115
6116 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6117 if (AssocExpr.isInvalid())
6118 return ExprError();
6119 AssocExprs.push_back(AssocExpr.release());
6120 }
6121
6122 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6123 E->getDefaultLoc(),
6124 E->getRParenLoc(),
6125 ControllingExpr.release(),
6126 AssocTypes.data(),
6127 AssocExprs.data(),
6128 E->getNumAssocs());
6129}
6130
6131template<typename Derived>
6132ExprResult
John McCall454feb92009-12-08 09:21:05 +00006133TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006134 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006136 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006140
John McCall9ae2f072010-08-23 23:25:46 +00006141 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 E->getRParen());
6143}
6144
Mike Stump1eb44332009-09-09 15:08:12 +00006145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006146ExprResult
John McCall454feb92009-12-08 09:21:05 +00006147TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006148 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006150 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006154
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6156 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006157 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158}
Mike Stump1eb44332009-09-09 15:08:12 +00006159
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006161ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006162TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6163 // Transform the type.
6164 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6165 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006166 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006167
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006168 // Transform all of the components into components similar to what the
6169 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006170 // FIXME: It would be slightly more efficient in the non-dependent case to
6171 // just map FieldDecls, rather than requiring the rebuilder to look for
6172 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006173 // template code that we don't care.
6174 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006175 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006176 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006177 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006178 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6179 const Node &ON = E->getComponent(I);
6180 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006181 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006182 Comp.LocStart = ON.getSourceRange().getBegin();
6183 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006184 switch (ON.getKind()) {
6185 case Node::Array: {
6186 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006187 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006188 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006189 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006190
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006191 ExprChanged = ExprChanged || Index.get() != FromIndex;
6192 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006193 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006194 break;
6195 }
Sean Huntc3021132010-05-05 15:23:54 +00006196
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006197 case Node::Field:
6198 case Node::Identifier:
6199 Comp.isBrackets = false;
6200 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006201 if (!Comp.U.IdentInfo)
6202 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006203
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006204 break;
Sean Huntc3021132010-05-05 15:23:54 +00006205
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006206 case Node::Base:
6207 // Will be recomputed during the rebuild.
6208 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006209 }
Sean Huntc3021132010-05-05 15:23:54 +00006210
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006211 Components.push_back(Comp);
6212 }
Sean Huntc3021132010-05-05 15:23:54 +00006213
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006214 // If nothing changed, retain the existing expression.
6215 if (!getDerived().AlwaysRebuild() &&
6216 Type == E->getTypeSourceInfo() &&
6217 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006219
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006220 // Build a new offsetof expression.
6221 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6222 Components.data(), Components.size(),
6223 E->getRParenLoc());
6224}
6225
6226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006227ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006228TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6229 assert(getDerived().AlreadyTransformed(E->getType()) &&
6230 "opaque value expression requires transformation");
6231 return SemaRef.Owned(E);
6232}
6233
6234template<typename Derived>
6235ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006236TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006237 // Rebuild the syntactic form. The original syntactic form has
6238 // opaque-value expressions in it, so strip those away and rebuild
6239 // the result. This is a really awful way of doing this, but the
6240 // better solution (rebuilding the semantic expressions and
6241 // rebinding OVEs as necessary) doesn't work; we'd need
6242 // TreeTransform to not strip away implicit conversions.
6243 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6244 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006245 if (result.isInvalid()) return ExprError();
6246
6247 // If that gives us a pseudo-object result back, the pseudo-object
6248 // expression must have been an lvalue-to-rvalue conversion which we
6249 // should reapply.
6250 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6251 result = SemaRef.checkPseudoObjectRValue(result.take());
6252
6253 return result;
6254}
6255
6256template<typename Derived>
6257ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006258TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6259 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006261 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006262
John McCalla93c9342009-12-07 02:54:59 +00006263 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006264 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006266
John McCall5ab75172009-11-04 07:28:41 +00006267 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006269
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006270 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6271 E->getKind(),
6272 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006273 }
Mike Stump1eb44332009-09-09 15:08:12 +00006274
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006275 // C++0x [expr.sizeof]p1:
6276 // The operand is either an expression, which is an unevaluated operand
6277 // [...]
6278 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006279
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006280 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6281 if (SubExpr.isInvalid())
6282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006283
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006284 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6285 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006286
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006287 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6288 E->getOperatorLoc(),
6289 E->getKind(),
6290 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291}
Mike Stump1eb44332009-09-09 15:08:12 +00006292
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006294ExprResult
John McCall454feb92009-12-08 09:21:05 +00006295TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006296 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006298 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006299
John McCall60d7b3a2010-08-24 06:29:42 +00006300 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006303
6304
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 if (!getDerived().AlwaysRebuild() &&
6306 LHS.get() == E->getLHS() &&
6307 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006308 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006309
John McCall9ae2f072010-08-23 23:25:46 +00006310 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006311 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006312 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006313 E->getRBracketLoc());
6314}
Mike Stump1eb44332009-09-09 15:08:12 +00006315
6316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006317ExprResult
John McCall454feb92009-12-08 09:21:05 +00006318TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006319 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006320 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323
6324 // Transform arguments.
6325 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006326 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006327 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6328 &ArgChanged))
6329 return ExprError();
6330
Douglas Gregorb98b1992009-08-11 05:31:07 +00006331 if (!getDerived().AlwaysRebuild() &&
6332 Callee.get() == E->getCallee() &&
6333 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006334 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006337 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006339 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 E->getRParenLoc());
6342}
Mike Stump1eb44332009-09-09 15:08:12 +00006343
6344template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006345ExprResult
John McCall454feb92009-12-08 09:21:05 +00006346TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006347 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006349 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006350
Douglas Gregor40d96a62011-02-28 21:54:11 +00006351 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006352 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006353 QualifierLoc
6354 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6355
6356 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006357 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006358 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006359 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Eli Friedmanf595cc42009-12-04 06:40:45 +00006361 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006362 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6363 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006365 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006366
John McCall6bb80172010-03-30 21:47:33 +00006367 NamedDecl *FoundDecl = E->getFoundDecl();
6368 if (FoundDecl == E->getMemberDecl()) {
6369 FoundDecl = Member;
6370 } else {
6371 FoundDecl = cast_or_null<NamedDecl>(
6372 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6373 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006374 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006375 }
6376
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 if (!getDerived().AlwaysRebuild() &&
6378 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006379 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006380 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006381 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006382 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006383
Anders Carlsson1f240322009-12-22 05:24:09 +00006384 // Mark it referenced in the new context regardless.
6385 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006386 SemaRef.MarkMemberReferenced(E);
6387
John McCall3fa5cae2010-10-26 07:05:15 +00006388 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006389 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390
John McCalld5532b62009-11-23 01:53:49 +00006391 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006392 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006393 TransArgs.setLAngleLoc(E->getLAngleLoc());
6394 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006395 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6396 E->getNumTemplateArgs(),
6397 TransArgs))
6398 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006399 }
Sean Huntc3021132010-05-05 15:23:54 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 // FIXME: Bogus source location for the operator
6402 SourceLocation FakeOperatorLoc
6403 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6404
John McCallc2233c52010-01-15 08:34:02 +00006405 // FIXME: to do this check properly, we will need to preserve the
6406 // first-qualifier-in-scope here, just in case we had a dependent
6407 // base (and therefore couldn't do the check) and a
6408 // nested-name-qualifier (and therefore could do the lookup).
6409 NamedDecl *FirstQualifierInScope = 0;
6410
John McCall9ae2f072010-08-23 23:25:46 +00006411 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006413 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006414 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006415 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006416 Member,
John McCall6bb80172010-03-30 21:47:33 +00006417 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006418 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006419 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006420 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421}
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006424ExprResult
John McCall454feb92009-12-08 09:21:05 +00006425TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006426 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006429
John McCall60d7b3a2010-08-24 06:29:42 +00006430 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434 if (!getDerived().AlwaysRebuild() &&
6435 LHS.get() == E->getLHS() &&
6436 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006438
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006440 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441}
6442
Mike Stump1eb44332009-09-09 15:08:12 +00006443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006444ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006446 CompoundAssignOperator *E) {
6447 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448}
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006451ExprResult TreeTransform<Derived>::
6452TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6453 // Just rebuild the common and RHS expressions and see whether we
6454 // get any changes.
6455
6456 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6457 if (commonExpr.isInvalid())
6458 return ExprError();
6459
6460 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6461 if (rhs.isInvalid())
6462 return ExprError();
6463
6464 if (!getDerived().AlwaysRebuild() &&
6465 commonExpr.get() == e->getCommon() &&
6466 rhs.get() == e->getFalseExpr())
6467 return SemaRef.Owned(e);
6468
6469 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6470 e->getQuestionLoc(),
6471 0,
6472 e->getColonLoc(),
6473 rhs.get());
6474}
6475
6476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006477ExprResult
John McCall454feb92009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (!getDerived().AlwaysRebuild() &&
6492 Cond.get() == E->getCond() &&
6493 LHS.get() == E->getLHS() &&
6494 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006496
John McCall9ae2f072010-08-23 23:25:46 +00006497 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006498 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006499 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006500 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006501 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502}
Mike Stump1eb44332009-09-09 15:08:12 +00006503
6504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
John McCall454feb92009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006507 // Implicit casts are eliminated during transformation, since they
6508 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006509 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510}
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006513ExprResult
John McCall454feb92009-12-08 09:21:05 +00006514TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006515 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6516 if (!Type)
6517 return ExprError();
6518
John McCall60d7b3a2010-08-24 06:29:42 +00006519 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006520 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006525 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006527 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006528
John McCall9d125032010-01-15 18:39:57 +00006529 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006530 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006532 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533}
Mike Stump1eb44332009-09-09 15:08:12 +00006534
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006536ExprResult
John McCall454feb92009-12-08 09:21:05 +00006537TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006538 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6539 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6540 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006542
John McCall60d7b3a2010-08-24 06:29:42 +00006543 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006546
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006548 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006550 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551
John McCall1d7d8d62010-01-19 22:33:45 +00006552 // Note: the expression type doesn't necessarily match the
6553 // type-as-written, but that's okay, because it should always be
6554 // derivable from the initializer.
6555
John McCall42f56b52010-01-18 19:35:47 +00006556 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006558 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559}
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall454feb92009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006564 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 if (!getDerived().AlwaysRebuild() &&
6569 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006570 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006573 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006575 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 E->getAccessorLoc(),
6577 E->getAccessor());
6578}
Mike Stump1eb44332009-09-09 15:08:12 +00006579
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006581ExprResult
John McCall454feb92009-12-08 09:21:05 +00006582TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006584
John McCallca0408f2010-08-23 06:44:23 +00006585 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006586 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6587 Inits, &InitChanged))
6588 return ExprError();
6589
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006591 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006594 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595}
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006598ExprResult
John McCall454feb92009-12-08 09:21:05 +00006599TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregor43959a92009-08-20 07:17:43 +00006602 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006603 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregor43959a92009-08-20 07:17:43 +00006607 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006608 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 bool ExprChanged = false;
6610 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6611 DEnd = E->designators_end();
6612 D != DEnd; ++D) {
6613 if (D->isFieldDesignator()) {
6614 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6615 D->getDotLoc(),
6616 D->getFieldLoc()));
6617 continue;
6618 }
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006624
6625 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6629 ArrayExprs.push_back(Index.release());
6630 continue;
6631 }
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006634 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6636 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
John McCall60d7b3a2010-08-24 06:29:42 +00006639 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
6643 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 End.get(),
6645 D->getLBracketLoc(),
6646 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006647
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6649 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 ArrayExprs.push_back(Start.release());
6652 ArrayExprs.push_back(End.release());
6653 }
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 if (!getDerived().AlwaysRebuild() &&
6656 Init.get() == E->getInit() &&
6657 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006658 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6661 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006662 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663}
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006666ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006668 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006669 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006670
Douglas Gregor5557b252009-10-28 00:29:27 +00006671 // FIXME: Will we ever have proper type location here? Will we actually
6672 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 QualType T = getDerived().TransformType(E->getType());
6674 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (!getDerived().AlwaysRebuild() &&
6678 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006679 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 return getDerived().RebuildImplicitValueInitExpr(T);
6682}
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006685ExprResult
John McCall454feb92009-12-08 09:21:05 +00006686TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006687 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6688 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006690
John McCall60d7b3a2010-08-24 06:29:42 +00006691 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006696 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006698 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006699
John McCall9ae2f072010-08-23 23:25:46 +00006700 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006701 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702}
6703
6704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006705ExprResult
John McCall454feb92009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006708 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006709 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6710 &ArgumentChanged))
6711 return ExprError();
6712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6714 move_arg(Inits),
6715 E->getRParenLoc());
6716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718/// \brief Transform an address-of-label expression.
6719///
6720/// By default, the transformation of an address-of-label expression always
6721/// rebuilds the expression, so that the label identifier can be resolved to
6722/// the corresponding label statement by semantic analysis.
6723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006724ExprResult
John McCall454feb92009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006726 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6727 E->getLabel());
6728 if (!LD)
6729 return ExprError();
6730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006732 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733}
Mike Stump1eb44332009-09-09 15:08:12 +00006734
6735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006736ExprResult
John McCall454feb92009-12-08 09:21:05 +00006737TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006738 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6740 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006741 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 if (!getDerived().AlwaysRebuild() &&
6744 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006745 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006746
6747 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006748 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 E->getRParenLoc());
6750}
Mike Stump1eb44332009-09-09 15:08:12 +00006751
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006753ExprResult
John McCall454feb92009-12-08 09:21:05 +00006754TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006755 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006758
John McCall60d7b3a2010-08-24 06:29:42 +00006759 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006762
John McCall60d7b3a2010-08-24 06:29:42 +00006763 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (!getDerived().AlwaysRebuild() &&
6768 Cond.get() == E->getCond() &&
6769 LHS.get() == E->getLHS() &&
6770 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006771 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006774 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 E->getRParenLoc());
6776}
Mike Stump1eb44332009-09-09 15:08:12 +00006777
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006779ExprResult
John McCall454feb92009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006781 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782}
6783
6784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006787 switch (E->getOperator()) {
6788 case OO_New:
6789 case OO_Delete:
6790 case OO_Array_New:
6791 case OO_Array_Delete:
6792 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006793
Douglas Gregor668d6d92009-12-13 20:44:55 +00006794 case OO_Call: {
6795 // This is a call to an object's operator().
6796 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6797
6798 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006799 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006800 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006801 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006802
6803 // FIXME: Poor location information
6804 SourceLocation FakeLParenLoc
6805 = SemaRef.PP.getLocForEndOfToken(
6806 static_cast<Expr *>(Object.get())->getLocEnd());
6807
6808 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006809 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006810 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6811 Args))
6812 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006813
John McCall9ae2f072010-08-23 23:25:46 +00006814 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006815 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006816 E->getLocEnd());
6817 }
6818
6819#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6820 case OO_##Name:
6821#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6822#include "clang/Basic/OperatorKinds.def"
6823 case OO_Subscript:
6824 // Handled below.
6825 break;
6826
6827 case OO_Conditional:
6828 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006829
6830 case OO_None:
6831 case NUM_OVERLOADED_OPERATORS:
6832 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006833 }
6834
John McCall60d7b3a2010-08-24 06:29:42 +00006835 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006838
John McCall60d7b3a2010-08-24 06:29:42 +00006839 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (E->getNumArgs() == 2) {
6845 Second = getDerived().TransformExpr(E->getArg(1));
6846 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006847 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 }
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 if (!getDerived().AlwaysRebuild() &&
6851 Callee.get() == E->getCallee() &&
6852 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006853 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006854 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6857 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006858 Callee.get(),
6859 First.get(),
6860 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861}
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006864ExprResult
John McCall454feb92009-12-08 09:21:05 +00006865TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6866 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867}
Mike Stump1eb44332009-09-09 15:08:12 +00006868
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006870ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006871TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6872 // Transform the callee.
6873 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6874 if (Callee.isInvalid())
6875 return ExprError();
6876
6877 // Transform exec config.
6878 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6879 if (EC.isInvalid())
6880 return ExprError();
6881
6882 // Transform arguments.
6883 bool ArgChanged = false;
6884 ASTOwningVector<Expr*> Args(SemaRef);
6885 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6886 &ArgChanged))
6887 return ExprError();
6888
6889 if (!getDerived().AlwaysRebuild() &&
6890 Callee.get() == E->getCallee() &&
6891 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006892 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006893
6894 // FIXME: Wrong source location information for the '('.
6895 SourceLocation FakeLParenLoc
6896 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6897 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6898 move_arg(Args),
6899 E->getRParenLoc(), EC.get());
6900}
6901
6902template<typename Derived>
6903ExprResult
John McCall454feb92009-12-08 09:21:05 +00006904TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006905 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6906 if (!Type)
6907 return ExprError();
6908
John McCall60d7b3a2010-08-24 06:29:42 +00006909 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006910 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006913
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006915 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006917 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006920 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6922 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6923 SourceLocation FakeRParenLoc
6924 = SemaRef.PP.getLocForEndOfToken(
6925 E->getSubExpr()->getSourceRange().getEnd());
6926 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006927 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006929 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 FakeRAngleLoc,
6931 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006932 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 FakeRParenLoc);
6934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
John McCall454feb92009-12-08 09:21:05 +00006938TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6939 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940}
Mike Stump1eb44332009-09-09 15:08:12 +00006941
6942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
John McCall454feb92009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6945 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006946}
6947
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006949ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006951 CXXReinterpretCastExpr *E) {
6952 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953}
Mike Stump1eb44332009-09-09 15:08:12 +00006954
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006956ExprResult
John McCall454feb92009-12-08 09:21:05 +00006957TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6958 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959}
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006962ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006964 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006965 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6966 if (!Type)
6967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006968
John McCall60d7b3a2010-08-24 06:29:42 +00006969 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006970 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006972 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006973
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006975 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006979 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006981 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 E->getRParenLoc());
6983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
John McCall454feb92009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006989 TypeSourceInfo *TInfo
6990 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6991 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006992 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006995 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006998 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6999 E->getLocStart(),
7000 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 E->getLocEnd());
7002 }
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Eli Friedmanef331b72012-01-20 01:26:23 +00007004 // We don't know whether the subexpression is potentially evaluated until
7005 // after we perform semantic analysis. We speculatively assume it is
7006 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007008 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007009
John McCall60d7b3a2010-08-24 06:29:42 +00007010 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007012 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 if (!getDerived().AlwaysRebuild() &&
7015 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007016 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007018 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7019 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007020 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 E->getLocEnd());
7022}
7023
7024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007025ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007026TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7027 if (E->isTypeOperand()) {
7028 TypeSourceInfo *TInfo
7029 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7030 if (!TInfo)
7031 return ExprError();
7032
7033 if (!getDerived().AlwaysRebuild() &&
7034 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007036
Douglas Gregor3c52a212011-03-06 17:40:41 +00007037 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007038 E->getLocStart(),
7039 TInfo,
7040 E->getLocEnd());
7041 }
7042
Francois Pichet01b7c302010-09-08 12:20:18 +00007043 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7044
7045 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7046 if (SubExpr.isInvalid())
7047 return ExprError();
7048
7049 if (!getDerived().AlwaysRebuild() &&
7050 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007052
7053 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7054 E->getLocStart(),
7055 SubExpr.get(),
7056 E->getLocEnd());
7057}
7058
7059template<typename Derived>
7060ExprResult
John McCall454feb92009-12-08 09:21:05 +00007061TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007062 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063}
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007066ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007068 CXXNullPtrLiteralExpr *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
John McCall454feb92009-12-08 09:21:05 +00007074TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007075 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007076 QualType T;
7077 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7078 T = MD->getThisType(getSema().Context);
7079 else
7080 T = getSema().Context.getPointerType(
7081 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007082
Douglas Gregorec79d872012-02-24 17:41:38 +00007083 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7084 // Make sure that we capture 'this'.
7085 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007086 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007087 }
7088
Douglas Gregor828a1972010-01-07 23:12:05 +00007089 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090}
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007093ExprResult
John McCall454feb92009-12-08 09:21:05 +00007094TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007095 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() &&
7100 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102
Douglas Gregorbca01b42011-07-06 22:04:06 +00007103 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7104 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105}
Mike Stump1eb44332009-09-09 15:08:12 +00007106
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007108ExprResult
John McCall454feb92009-12-08 09:21:05 +00007109TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007110 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007111 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7112 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007114 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007115
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007116 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Douglas Gregor036aed12009-12-23 23:03:06 +00007120 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121}
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007124ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007125TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7126 CXXScalarValueInitExpr *E) {
7127 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7128 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007132 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007133 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007134
Douglas Gregorab6677e2010-09-08 00:15:04 +00007135 return getDerived().RebuildCXXScalarValueInitExpr(T,
7136 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007137 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007144 TypeSourceInfo *AllocTypeInfo
7145 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7146 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007150 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154 // Transform the placement arguments (if any).
7155 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007156 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007157 if (getDerived().TransformExprs(E->getPlacementArgs(),
7158 E->getNumPlacementArgs(), true,
7159 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007160 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007162 // Transform the initializer (if any).
7163 Expr *OldInit = E->getInitializer();
7164 ExprResult NewInit;
7165 if (OldInit)
7166 NewInit = getDerived().TransformExpr(OldInit);
7167 if (NewInit.isInvalid())
7168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007170 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007171 FunctionDecl *OperatorNew = 0;
7172 if (E->getOperatorNew()) {
7173 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007174 getDerived().TransformDecl(E->getLocStart(),
7175 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007176 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007177 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007178 }
7179
7180 FunctionDecl *OperatorDelete = 0;
7181 if (E->getOperatorDelete()) {
7182 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007183 getDerived().TransformDecl(E->getLocStart(),
7184 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007185 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007186 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007187 }
Sean Huntc3021132010-05-05 15:23:54 +00007188
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007190 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007192 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007193 OperatorNew == E->getOperatorNew() &&
7194 OperatorDelete == E->getOperatorDelete() &&
7195 !ArgumentChanged) {
7196 // Mark any declarations we need as referenced.
7197 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007198 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007199 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007200 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007201 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007202
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007203 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007204 QualType ElementType
7205 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7206 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7207 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7208 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007209 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007210 }
7211 }
7212 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007213
John McCall3fa5cae2010-10-26 07:05:15 +00007214 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007215 }
Mike Stump1eb44332009-09-09 15:08:12 +00007216
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007217 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007218 if (!ArraySize.get()) {
7219 // If no array size was specified, but the new expression was
7220 // instantiated with an array type (e.g., "new T" where T is
7221 // instantiated with "int[4]"), extract the outer bound from the
7222 // array type as our array size. We do this with constant and
7223 // dependently-sized array types.
7224 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7225 if (!ArrayT) {
7226 // Do nothing
7227 } else if (const ConstantArrayType *ConsArrayT
7228 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007229 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007230 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7231 ConsArrayT->getSize(),
7232 SemaRef.Context.getSizeType(),
7233 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007234 AllocType = ConsArrayT->getElementType();
7235 } else if (const DependentSizedArrayType *DepArrayT
7236 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7237 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007238 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007239 AllocType = DepArrayT->getElementType();
7240 }
7241 }
7242 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007243
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7245 E->isGlobalNew(),
7246 /*FIXME:*/E->getLocStart(),
7247 move_arg(PlacementArgs),
7248 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007249 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007251 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007252 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007253 E->getDirectInitRange(),
7254 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255}
Mike Stump1eb44332009-09-09 15:08:12 +00007256
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007258ExprResult
John McCall454feb92009-12-08 09:21:05 +00007259TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007260 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007263
Douglas Gregor1af74512010-02-26 00:38:10 +00007264 // Transform the delete operator, if known.
7265 FunctionDecl *OperatorDelete = 0;
7266 if (E->getOperatorDelete()) {
7267 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007268 getDerived().TransformDecl(E->getLocStart(),
7269 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007270 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007271 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007272 }
Sean Huntc3021132010-05-05 15:23:54 +00007273
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007275 Operand.get() == E->getArgument() &&
7276 OperatorDelete == E->getOperatorDelete()) {
7277 // Mark any declarations we need as referenced.
7278 // FIXME: instantiation-specific.
7279 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007280 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007281
7282 if (!E->getArgument()->isTypeDependent()) {
7283 QualType Destroyed = SemaRef.Context.getBaseElementType(
7284 E->getDestroyedType());
7285 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7286 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007287 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7288 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007289 }
7290 }
7291
John McCall3fa5cae2010-10-26 07:05:15 +00007292 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007293 }
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7296 E->isGlobalDelete(),
7297 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007298 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299}
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007302ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007303TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007304 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007305 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007306 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007308
John McCallb3d87482010-08-24 05:47:05 +00007309 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007310 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007311 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007312 E->getOperatorLoc(),
7313 E->isArrow()? tok::arrow : tok::period,
7314 ObjectTypePtr,
7315 MayBePseudoDestructor);
7316 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007318
John McCallb3d87482010-08-24 05:47:05 +00007319 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007320 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7321 if (QualifierLoc) {
7322 QualifierLoc
7323 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7324 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007325 return ExprError();
7326 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007327 CXXScopeSpec SS;
7328 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007329
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007330 PseudoDestructorTypeStorage Destroyed;
7331 if (E->getDestroyedTypeInfo()) {
7332 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007333 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007334 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007335 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007337 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007338 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007339 // We aren't likely to be able to resolve the identifier down to a type
7340 // now anyway, so just retain the identifier.
7341 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7342 E->getDestroyedTypeLoc());
7343 } else {
7344 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007345 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007346 *E->getDestroyedTypeIdentifier(),
7347 E->getDestroyedTypeLoc(),
7348 /*Scope=*/0,
7349 SS, ObjectTypePtr,
7350 false);
7351 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007353
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007354 Destroyed
7355 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7356 E->getDestroyedTypeLoc());
7357 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007358
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007359 TypeSourceInfo *ScopeTypeInfo = 0;
7360 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007361 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007362 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007363 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007364 }
Sean Huntc3021132010-05-05 15:23:54 +00007365
John McCall9ae2f072010-08-23 23:25:46 +00007366 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007367 E->getOperatorLoc(),
7368 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007369 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007370 ScopeTypeInfo,
7371 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007372 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007373 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007374}
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregora71d8192009-09-04 17:36:40 +00007376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007377ExprResult
John McCallba135432009-11-21 08:51:07 +00007378TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007379 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007380 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7381 Sema::LookupOrdinaryName);
7382
7383 // Transform all the decls.
7384 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7385 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007386 NamedDecl *InstD = static_cast<NamedDecl*>(
7387 getDerived().TransformDecl(Old->getNameLoc(),
7388 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007389 if (!InstD) {
7390 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7391 // This can happen because of dependent hiding.
7392 if (isa<UsingShadowDecl>(*I))
7393 continue;
7394 else
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007396 }
John McCallf7a1a742009-11-24 19:00:30 +00007397
7398 // Expand using declarations.
7399 if (isa<UsingDecl>(InstD)) {
7400 UsingDecl *UD = cast<UsingDecl>(InstD);
7401 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7402 E = UD->shadow_end(); I != E; ++I)
7403 R.addDecl(*I);
7404 continue;
7405 }
7406
7407 R.addDecl(InstD);
7408 }
7409
7410 // Resolve a kind, but don't do any further analysis. If it's
7411 // ambiguous, the callee needs to deal with it.
7412 R.resolveKind();
7413
7414 // Rebuild the nested-name qualifier, if present.
7415 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007416 if (Old->getQualifierLoc()) {
7417 NestedNameSpecifierLoc QualifierLoc
7418 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7419 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007420 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007421
Douglas Gregor4c9be892011-02-28 20:01:57 +00007422 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007423 }
7424
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007425 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007426 CXXRecordDecl *NamingClass
7427 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7428 Old->getNameLoc(),
7429 Old->getNamingClass()));
7430 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007431 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007432
Douglas Gregor66c45152010-04-27 16:10:10 +00007433 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007434 }
7435
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007436 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7437
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007438 // If we have neither explicit template arguments, nor the template keyword,
7439 // it's a normal declaration name.
7440 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007441 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7442
7443 // If we have template arguments, rebuild them, then rebuild the
7444 // templateid expression.
7445 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007446 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7447 Old->getNumTemplateArgs(),
7448 TransArgs))
7449 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007450
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007451 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007452 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453}
Mike Stump1eb44332009-09-09 15:08:12 +00007454
Douglas Gregorb98b1992009-08-11 05:31:07 +00007455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007456ExprResult
John McCall454feb92009-12-08 09:21:05 +00007457TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007458 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7459 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007460 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007461
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007463 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007464 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007465
Mike Stump1eb44332009-09-09 15:08:12 +00007466 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007468 T,
7469 E->getLocEnd());
7470}
Mike Stump1eb44332009-09-09 15:08:12 +00007471
Douglas Gregorb98b1992009-08-11 05:31:07 +00007472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007473ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007474TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7475 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7476 if (!LhsT)
7477 return ExprError();
7478
7479 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7480 if (!RhsT)
7481 return ExprError();
7482
7483 if (!getDerived().AlwaysRebuild() &&
7484 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7485 return SemaRef.Owned(E);
7486
7487 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7488 E->getLocStart(),
7489 LhsT, RhsT,
7490 E->getLocEnd());
7491}
7492
7493template<typename Derived>
7494ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007495TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7496 bool ArgChanged = false;
7497 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7498 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7499 TypeSourceInfo *From = E->getArg(I);
7500 TypeLoc FromTL = From->getTypeLoc();
7501 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7502 TypeLocBuilder TLB;
7503 TLB.reserve(FromTL.getFullDataSize());
7504 QualType To = getDerived().TransformType(TLB, FromTL);
7505 if (To.isNull())
7506 return ExprError();
7507
7508 if (To == From->getType())
7509 Args.push_back(From);
7510 else {
7511 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7512 ArgChanged = true;
7513 }
7514 continue;
7515 }
7516
7517 ArgChanged = true;
7518
7519 // We have a pack expansion. Instantiate it.
7520 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7521 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7522 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7523 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7524
7525 // Determine whether the set of unexpanded parameter packs can and should
7526 // be expanded.
7527 bool Expand = true;
7528 bool RetainExpansion = false;
7529 llvm::Optional<unsigned> OrigNumExpansions
7530 = ExpansionTL.getTypePtr()->getNumExpansions();
7531 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7532 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7533 PatternTL.getSourceRange(),
7534 Unexpanded,
7535 Expand, RetainExpansion,
7536 NumExpansions))
7537 return ExprError();
7538
7539 if (!Expand) {
7540 // The transform has determined that we should perform a simple
7541 // transformation on the pack expansion, producing another pack
7542 // expansion.
7543 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7544
7545 TypeLocBuilder TLB;
7546 TLB.reserve(From->getTypeLoc().getFullDataSize());
7547
7548 QualType To = getDerived().TransformType(TLB, PatternTL);
7549 if (To.isNull())
7550 return ExprError();
7551
7552 To = getDerived().RebuildPackExpansionType(To,
7553 PatternTL.getSourceRange(),
7554 ExpansionTL.getEllipsisLoc(),
7555 NumExpansions);
7556 if (To.isNull())
7557 return ExprError();
7558
7559 PackExpansionTypeLoc ToExpansionTL
7560 = TLB.push<PackExpansionTypeLoc>(To);
7561 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7562 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7563 continue;
7564 }
7565
7566 // Expand the pack expansion by substituting for each argument in the
7567 // pack(s).
7568 for (unsigned I = 0; I != *NumExpansions; ++I) {
7569 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7570 TypeLocBuilder TLB;
7571 TLB.reserve(PatternTL.getFullDataSize());
7572 QualType To = getDerived().TransformType(TLB, PatternTL);
7573 if (To.isNull())
7574 return ExprError();
7575
7576 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7577 }
7578
7579 if (!RetainExpansion)
7580 continue;
7581
7582 // If we're supposed to retain a pack expansion, do so by temporarily
7583 // forgetting the partially-substituted parameter pack.
7584 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7585
7586 TypeLocBuilder TLB;
7587 TLB.reserve(From->getTypeLoc().getFullDataSize());
7588
7589 QualType To = getDerived().TransformType(TLB, PatternTL);
7590 if (To.isNull())
7591 return ExprError();
7592
7593 To = getDerived().RebuildPackExpansionType(To,
7594 PatternTL.getSourceRange(),
7595 ExpansionTL.getEllipsisLoc(),
7596 NumExpansions);
7597 if (To.isNull())
7598 return ExprError();
7599
7600 PackExpansionTypeLoc ToExpansionTL
7601 = TLB.push<PackExpansionTypeLoc>(To);
7602 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7603 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7604 }
7605
7606 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7607 return SemaRef.Owned(E);
7608
7609 return getDerived().RebuildTypeTrait(E->getTrait(),
7610 E->getLocStart(),
7611 Args,
7612 E->getLocEnd());
7613}
7614
7615template<typename Derived>
7616ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007617TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7618 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7619 if (!T)
7620 return ExprError();
7621
7622 if (!getDerived().AlwaysRebuild() &&
7623 T == E->getQueriedTypeSourceInfo())
7624 return SemaRef.Owned(E);
7625
7626 ExprResult SubExpr;
7627 {
7628 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7629 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7630 if (SubExpr.isInvalid())
7631 return ExprError();
7632
7633 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7634 return SemaRef.Owned(E);
7635 }
7636
7637 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7638 E->getLocStart(),
7639 T,
7640 SubExpr.get(),
7641 E->getLocEnd());
7642}
7643
7644template<typename Derived>
7645ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007646TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7647 ExprResult SubExpr;
7648 {
7649 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7650 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7651 if (SubExpr.isInvalid())
7652 return ExprError();
7653
7654 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7655 return SemaRef.Owned(E);
7656 }
7657
7658 return getDerived().RebuildExpressionTrait(
7659 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7660}
7661
7662template<typename Derived>
7663ExprResult
John McCall865d4472009-11-19 22:55:06 +00007664TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007665 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007666 NestedNameSpecifierLoc QualifierLoc
7667 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7668 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007669 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007670 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007671
John McCall43fed0d2010-11-12 08:19:04 +00007672 // TODO: If this is a conversion-function-id, verify that the
7673 // destination type name (if present) resolves the same way after
7674 // instantiation as it did in the local scope.
7675
Abramo Bagnara25777432010-08-11 22:01:17 +00007676 DeclarationNameInfo NameInfo
7677 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7678 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007680
John McCallf7a1a742009-11-24 19:00:30 +00007681 if (!E->hasExplicitTemplateArgs()) {
7682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007683 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007684 // Note: it is sufficient to compare the Name component of NameInfo:
7685 // if name has not changed, DNLoc has not changed either.
7686 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007688
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007689 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007690 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007691 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007692 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007693 }
John McCalld5532b62009-11-23 01:53:49 +00007694
7695 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007696 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7697 E->getNumTemplateArgs(),
7698 TransArgs))
7699 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007700
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007701 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007702 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007703 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007704 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007705}
7706
7707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007708ExprResult
John McCall454feb92009-12-08 09:21:05 +00007709TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007710 // CXXConstructExprs are always implicit, so when we have a
7711 // 1-argument construction we just transform that argument.
7712 if (E->getNumArgs() == 1 ||
7713 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7714 return getDerived().TransformExpr(E->getArg(0));
7715
Douglas Gregorb98b1992009-08-11 05:31:07 +00007716 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7717
7718 QualType T = getDerived().TransformType(E->getType());
7719 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007720 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007721
7722 CXXConstructorDecl *Constructor
7723 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007724 getDerived().TransformDecl(E->getLocStart(),
7725 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007726 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007728
Douglas Gregorb98b1992009-08-11 05:31:07 +00007729 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007730 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007731 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7732 &ArgumentChanged))
7733 return ExprError();
7734
Douglas Gregorb98b1992009-08-11 05:31:07 +00007735 if (!getDerived().AlwaysRebuild() &&
7736 T == E->getType() &&
7737 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007738 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007739 // Mark the constructor as referenced.
7740 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007741 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007742 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007743 }
Mike Stump1eb44332009-09-09 15:08:12 +00007744
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007745 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7746 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007747 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007748 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007749 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007750 E->getConstructionKind(),
7751 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007752}
Mike Stump1eb44332009-09-09 15:08:12 +00007753
Douglas Gregorb98b1992009-08-11 05:31:07 +00007754/// \brief Transform a C++ temporary-binding expression.
7755///
Douglas Gregor51326552009-12-24 18:51:59 +00007756/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7757/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007759ExprResult
John McCall454feb92009-12-08 09:21:05 +00007760TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007761 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007762}
Mike Stump1eb44332009-09-09 15:08:12 +00007763
John McCall4765fa02010-12-06 08:20:24 +00007764/// \brief Transform a C++ expression that contains cleanups that should
7765/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007766///
John McCall4765fa02010-12-06 08:20:24 +00007767/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007768/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007770ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007771TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007772 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773}
Mike Stump1eb44332009-09-09 15:08:12 +00007774
Douglas Gregorb98b1992009-08-11 05:31:07 +00007775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007776ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007777TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007778 CXXTemporaryObjectExpr *E) {
7779 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7780 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007781 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007782
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783 CXXConstructorDecl *Constructor
7784 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007785 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007786 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007787 if (!Constructor)
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 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007791 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007792 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007793 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7794 &ArgumentChanged))
7795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007796
Douglas Gregorb98b1992009-08-11 05:31:07 +00007797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007798 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007800 !ArgumentChanged) {
7801 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007802 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007803 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007804 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007805
7806 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7807 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007808 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007809 E->getLocEnd());
7810}
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregorb98b1992009-08-11 05:31:07 +00007812template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007813ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007814TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007815 // Create the local class that will describe the lambda.
7816 CXXRecordDecl *Class
7817 = getSema().createLambdaClosureType(E->getIntroducerRange());
7818 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7819
7820 // Transform the type of the lambda parameters and start the definition of
7821 // the lambda itself.
7822 TypeSourceInfo *MethodTy
7823 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7824 if (!MethodTy)
7825 return ExprError();
7826
Douglas Gregorc6889e72012-02-14 22:28:59 +00007827 // Transform lambda parameters.
7828 bool Invalid = false;
7829 llvm::SmallVector<QualType, 4> ParamTypes;
7830 llvm::SmallVector<ParmVarDecl *, 4> Params;
7831 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7832 E->getCallOperator()->param_begin(),
7833 E->getCallOperator()->param_size(),
7834 0, ParamTypes, &Params))
7835 Invalid = true;
7836
Douglas Gregordfca6f52012-02-13 22:00:16 +00007837 // Build the call operator.
7838 CXXMethodDecl *CallOperator
7839 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7840 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007841 E->getCallOperator()->getLocEnd(),
7842 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007843 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7844
Douglas Gregord5387e82012-02-14 00:00:48 +00007845 // FIXME: Instantiation-specific.
7846 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7847 TSK_ImplicitInstantiation);
7848
7849 // Introduce the context of the call operator.
7850 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7851
Douglas Gregordfca6f52012-02-13 22:00:16 +00007852 // Enter the scope of the lambda.
7853 sema::LambdaScopeInfo *LSI
7854 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7855 E->getCaptureDefault(),
7856 E->hasExplicitParameters(),
7857 E->hasExplicitResultType(),
7858 E->isMutable());
7859
7860 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007861 bool FinishedExplicitCaptures = false;
7862 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7863 CEnd = E->capture_end();
7864 C != CEnd; ++C) {
7865 // When we hit the first implicit capture, tell Sema that we've finished
7866 // the list of explicit captures.
7867 if (!FinishedExplicitCaptures && C->isImplicit()) {
7868 getSema().finishLambdaExplicitCaptures(LSI);
7869 FinishedExplicitCaptures = true;
7870 }
7871
7872 // Capturing 'this' is trivial.
7873 if (C->capturesThis()) {
7874 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7875 continue;
7876 }
7877
Douglas Gregora7365242012-02-14 19:27:52 +00007878 // Determine the capture kind for Sema.
7879 Sema::TryCaptureKind Kind
7880 = C->isImplicit()? Sema::TryCapture_Implicit
7881 : C->getCaptureKind() == LCK_ByCopy
7882 ? Sema::TryCapture_ExplicitByVal
7883 : Sema::TryCapture_ExplicitByRef;
7884 SourceLocation EllipsisLoc;
7885 if (C->isPackExpansion()) {
7886 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7887 bool ShouldExpand = false;
7888 bool RetainExpansion = false;
7889 llvm::Optional<unsigned> NumExpansions;
7890 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7891 C->getLocation(),
7892 Unexpanded,
7893 ShouldExpand, RetainExpansion,
7894 NumExpansions))
7895 return ExprError();
7896
7897 if (ShouldExpand) {
7898 // The transform has determined that we should perform an expansion;
7899 // transform and capture each of the arguments.
7900 // expansion of the pattern. Do so.
7901 VarDecl *Pack = C->getCapturedVar();
7902 for (unsigned I = 0; I != *NumExpansions; ++I) {
7903 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7904 VarDecl *CapturedVar
7905 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7906 Pack));
7907 if (!CapturedVar) {
7908 Invalid = true;
7909 continue;
7910 }
7911
7912 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007913 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007914 }
7915 continue;
7916 }
7917
7918 EllipsisLoc = C->getEllipsisLoc();
7919 }
7920
Douglas Gregordfca6f52012-02-13 22:00:16 +00007921 // Transform the captured variable.
7922 VarDecl *CapturedVar
7923 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7924 C->getCapturedVar()));
7925 if (!CapturedVar) {
7926 Invalid = true;
7927 continue;
7928 }
Douglas Gregora7365242012-02-14 19:27:52 +00007929
Douglas Gregordfca6f52012-02-13 22:00:16 +00007930 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007931 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 }
7933 if (!FinishedExplicitCaptures)
7934 getSema().finishLambdaExplicitCaptures(LSI);
7935
Douglas Gregordfca6f52012-02-13 22:00:16 +00007936
7937 // Enter a new evaluation context to insulate the lambda from any
7938 // cleanups from the enclosing full-expression.
7939 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
7940
7941 if (Invalid) {
7942 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7943 /*IsInstantiation=*/true);
7944 return ExprError();
7945 }
7946
7947 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007948 StmtResult Body = getDerived().TransformStmt(E->getBody());
7949 if (Body.isInvalid()) {
7950 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
7951 /*IsInstantiation=*/true);
7952 return ExprError();
7953 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007954
7955 // Note: Once a lambda mangling number and context declaration have been
7956 // assigned, they never change.
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007957 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007958 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007959 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregor9e8c92a2012-02-20 19:44:39 +00007960 /*CurScope=*/0, ManglingNumber,
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00007961 ContextDecl,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007962 /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00007963}
7964
7965template<typename Derived>
7966ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007967TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007968 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007969 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7970 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007972
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007974 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007975 Args.reserve(E->arg_size());
7976 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7977 &ArgumentChanged))
7978 return ExprError();
7979
Douglas Gregorb98b1992009-08-11 05:31:07 +00007980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007981 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007982 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007983 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007984
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007986 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007987 E->getLParenLoc(),
7988 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007989 E->getRParenLoc());
7990}
Mike Stump1eb44332009-09-09 15:08:12 +00007991
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007993ExprResult
John McCall865d4472009-11-19 22:55:06 +00007994TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007995 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007997 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007998 Expr *OldBase;
7999 QualType BaseType;
8000 QualType ObjectType;
8001 if (!E->isImplicitAccess()) {
8002 OldBase = E->getBase();
8003 Base = getDerived().TransformExpr(OldBase);
8004 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008005 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008006
John McCallaa81e162009-12-01 22:10:20 +00008007 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008008 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008009 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008010 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008011 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008012 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008013 ObjectTy,
8014 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008015 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008016 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008017
John McCallb3d87482010-08-24 05:47:05 +00008018 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008019 BaseType = ((Expr*) Base.get())->getType();
8020 } else {
8021 OldBase = 0;
8022 BaseType = getDerived().TransformType(E->getBaseType());
8023 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8024 }
Mike Stump1eb44332009-09-09 15:08:12 +00008025
Douglas Gregor6cd21982009-10-20 05:58:46 +00008026 // Transform the first part of the nested-name-specifier that qualifies
8027 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008028 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008029 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008030 E->getFirstQualifierFoundInScope(),
8031 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008032
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008033 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008034 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008035 QualifierLoc
8036 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8037 ObjectType,
8038 FirstQualifierInScope);
8039 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008040 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008041 }
Mike Stump1eb44332009-09-09 15:08:12 +00008042
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008043 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8044
John McCall43fed0d2010-11-12 08:19:04 +00008045 // TODO: If this is a conversion-function-id, verify that the
8046 // destination type name (if present) resolves the same way after
8047 // instantiation as it did in the local scope.
8048
Abramo Bagnara25777432010-08-11 22:01:17 +00008049 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008050 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008051 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008052 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008053
John McCallaa81e162009-12-01 22:10:20 +00008054 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008055 // This is a reference to a member without an explicitly-specified
8056 // template argument list. Optimize for this common case.
8057 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008058 Base.get() == OldBase &&
8059 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008060 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008061 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008062 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008064
John McCall9ae2f072010-08-23 23:25:46 +00008065 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008066 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008067 E->isArrow(),
8068 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008069 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008070 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008071 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008072 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008073 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008074 }
8075
John McCalld5532b62009-11-23 01:53:49 +00008076 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008077 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8078 E->getNumTemplateArgs(),
8079 TransArgs))
8080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008081
John McCall9ae2f072010-08-23 23:25:46 +00008082 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008083 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008084 E->isArrow(),
8085 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008086 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008087 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008088 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008089 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008090 &TransArgs);
8091}
8092
8093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008094ExprResult
John McCall454feb92009-12-08 09:21:05 +00008095TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008096 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008097 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008098 QualType BaseType;
8099 if (!Old->isImplicitAccess()) {
8100 Base = getDerived().TransformExpr(Old->getBase());
8101 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008102 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008103 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8104 Old->isArrow());
8105 if (Base.isInvalid())
8106 return ExprError();
8107 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008108 } else {
8109 BaseType = getDerived().TransformType(Old->getBaseType());
8110 }
John McCall129e2df2009-11-30 22:42:35 +00008111
Douglas Gregor4c9be892011-02-28 20:01:57 +00008112 NestedNameSpecifierLoc QualifierLoc;
8113 if (Old->getQualifierLoc()) {
8114 QualifierLoc
8115 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8116 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008117 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008118 }
8119
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008120 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8121
Abramo Bagnara25777432010-08-11 22:01:17 +00008122 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008123 Sema::LookupOrdinaryName);
8124
8125 // Transform all the decls.
8126 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8127 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008128 NamedDecl *InstD = static_cast<NamedDecl*>(
8129 getDerived().TransformDecl(Old->getMemberLoc(),
8130 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008131 if (!InstD) {
8132 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8133 // This can happen because of dependent hiding.
8134 if (isa<UsingShadowDecl>(*I))
8135 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008136 else {
8137 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008138 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008139 }
John McCall9f54ad42009-12-10 09:41:52 +00008140 }
John McCall129e2df2009-11-30 22:42:35 +00008141
8142 // Expand using declarations.
8143 if (isa<UsingDecl>(InstD)) {
8144 UsingDecl *UD = cast<UsingDecl>(InstD);
8145 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8146 E = UD->shadow_end(); I != E; ++I)
8147 R.addDecl(*I);
8148 continue;
8149 }
8150
8151 R.addDecl(InstD);
8152 }
8153
8154 R.resolveKind();
8155
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008156 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008157 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008158 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008159 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008160 Old->getMemberLoc(),
8161 Old->getNamingClass()));
8162 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008163 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008164
Douglas Gregor66c45152010-04-27 16:10:10 +00008165 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008166 }
Sean Huntc3021132010-05-05 15:23:54 +00008167
John McCall129e2df2009-11-30 22:42:35 +00008168 TemplateArgumentListInfo TransArgs;
8169 if (Old->hasExplicitTemplateArgs()) {
8170 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8171 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008172 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8173 Old->getNumTemplateArgs(),
8174 TransArgs))
8175 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008176 }
John McCallc2233c52010-01-15 08:34:02 +00008177
8178 // FIXME: to do this check properly, we will need to preserve the
8179 // first-qualifier-in-scope here, just in case we had a dependent
8180 // base (and therefore couldn't do the check) and a
8181 // nested-name-qualifier (and therefore could do the lookup).
8182 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008183
John McCall9ae2f072010-08-23 23:25:46 +00008184 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008185 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008186 Old->getOperatorLoc(),
8187 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008188 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008189 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008190 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008191 R,
8192 (Old->hasExplicitTemplateArgs()
8193 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008194}
8195
8196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008197ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008198TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008199 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008200 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8201 if (SubExpr.isInvalid())
8202 return ExprError();
8203
8204 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008205 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008206
8207 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8208}
8209
8210template<typename Derived>
8211ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008212TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008213 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8214 if (Pattern.isInvalid())
8215 return ExprError();
8216
8217 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8218 return SemaRef.Owned(E);
8219
Douglas Gregor67fd1252011-01-14 21:20:45 +00008220 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8221 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008222}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008223
8224template<typename Derived>
8225ExprResult
8226TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8227 // If E is not value-dependent, then nothing will change when we transform it.
8228 // Note: This is an instantiation-centric view.
8229 if (!E->isValueDependent())
8230 return SemaRef.Owned(E);
8231
8232 // Note: None of the implementations of TryExpandParameterPacks can ever
8233 // produce a diagnostic when given only a single unexpanded parameter pack,
8234 // so
8235 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8236 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008237 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008238 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008239 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008240 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008241 ShouldExpand, RetainExpansion,
8242 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008243 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008244
Douglas Gregor089e8932011-10-10 18:59:29 +00008245 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008246 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008247
8248 NamedDecl *Pack = E->getPack();
8249 if (!ShouldExpand) {
8250 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8251 Pack));
8252 if (!Pack)
8253 return ExprError();
8254 }
8255
Douglas Gregoree8aff02011-01-04 17:33:58 +00008256
8257 // We now know the length of the parameter pack, so build a new expression
8258 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008259 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008260 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008261 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008262}
8263
Douglas Gregorbe230c32011-01-03 17:17:50 +00008264template<typename Derived>
8265ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008266TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8267 SubstNonTypeTemplateParmPackExpr *E) {
8268 // Default behavior is to do nothing with this transformation.
8269 return SemaRef.Owned(E);
8270}
8271
8272template<typename Derived>
8273ExprResult
John McCall91a57552011-07-15 05:09:51 +00008274TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8275 SubstNonTypeTemplateParmExpr *E) {
8276 // Default behavior is to do nothing with this transformation.
8277 return SemaRef.Owned(E);
8278}
8279
8280template<typename Derived>
8281ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008282TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8283 MaterializeTemporaryExpr *E) {
8284 return getDerived().TransformExpr(E->GetTemporaryExpr());
8285}
8286
8287template<typename Derived>
8288ExprResult
John McCall454feb92009-12-08 09:21:05 +00008289TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008290 return SemaRef.MaybeBindToTemporary(E);
8291}
8292
8293template<typename Derived>
8294ExprResult
8295TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
8296 return SemaRef.MaybeBindToTemporary(E);
8297}
8298
8299template<typename Derived>
8300ExprResult
8301TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8302 return SemaRef.MaybeBindToTemporary(E);
8303}
8304
8305template<typename Derived>
8306ExprResult
8307TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8308 // Transform each of the elements.
8309 llvm::SmallVector<Expr *, 8> Elements;
8310 bool ArgChanged = false;
8311 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8312 /*IsCall=*/false, Elements, &ArgChanged))
8313 return ExprError();
8314
8315 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8316 return SemaRef.MaybeBindToTemporary(E);
8317
8318 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8319 Elements.data(),
8320 Elements.size());
8321}
8322
8323template<typename Derived>
8324ExprResult
8325TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8326 ObjCDictionaryLiteral *E) {
8327 // Transform each of the elements.
8328 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8329 bool ArgChanged = false;
8330 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8331 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8332
8333 if (OrigElement.isPackExpansion()) {
8334 // This key/value element is a pack expansion.
8335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8336 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8337 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8339
8340 // Determine whether the set of unexpanded parameter packs can
8341 // and should be expanded.
8342 bool Expand = true;
8343 bool RetainExpansion = false;
8344 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8345 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8346 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8347 OrigElement.Value->getLocEnd());
8348 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8349 PatternRange,
8350 Unexpanded,
8351 Expand, RetainExpansion,
8352 NumExpansions))
8353 return ExprError();
8354
8355 if (!Expand) {
8356 // The transform has determined that we should perform a simple
8357 // transformation on the pack expansion, producing another pack
8358 // expansion.
8359 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8360 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8361 if (Key.isInvalid())
8362 return ExprError();
8363
8364 if (Key.get() != OrigElement.Key)
8365 ArgChanged = true;
8366
8367 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8368 if (Value.isInvalid())
8369 return ExprError();
8370
8371 if (Value.get() != OrigElement.Value)
8372 ArgChanged = true;
8373
8374 ObjCDictionaryElement Expansion = {
8375 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8376 };
8377 Elements.push_back(Expansion);
8378 continue;
8379 }
8380
8381 // Record right away that the argument was changed. This needs
8382 // to happen even if the array expands to nothing.
8383 ArgChanged = true;
8384
8385 // The transform has determined that we should perform an elementwise
8386 // expansion of the pattern. Do so.
8387 for (unsigned I = 0; I != *NumExpansions; ++I) {
8388 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8389 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8390 if (Key.isInvalid())
8391 return ExprError();
8392
8393 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8394 if (Value.isInvalid())
8395 return ExprError();
8396
8397 ObjCDictionaryElement Element = {
8398 Key.get(), Value.get(), SourceLocation(), NumExpansions
8399 };
8400
8401 // If any unexpanded parameter packs remain, we still have a
8402 // pack expansion.
8403 if (Key.get()->containsUnexpandedParameterPack() ||
8404 Value.get()->containsUnexpandedParameterPack())
8405 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8406
8407 Elements.push_back(Element);
8408 }
8409
8410 // We've finished with this pack expansion.
8411 continue;
8412 }
8413
8414 // Transform and check key.
8415 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8416 if (Key.isInvalid())
8417 return ExprError();
8418
8419 if (Key.get() != OrigElement.Key)
8420 ArgChanged = true;
8421
8422 // Transform and check value.
8423 ExprResult Value
8424 = getDerived().TransformExpr(OrigElement.Value);
8425 if (Value.isInvalid())
8426 return ExprError();
8427
8428 if (Value.get() != OrigElement.Value)
8429 ArgChanged = true;
8430
8431 ObjCDictionaryElement Element = {
8432 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8433 };
8434 Elements.push_back(Element);
8435 }
8436
8437 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8438 return SemaRef.MaybeBindToTemporary(E);
8439
8440 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8441 Elements.data(),
8442 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008443}
8444
Mike Stump1eb44332009-09-09 15:08:12 +00008445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008446ExprResult
John McCall454feb92009-12-08 09:21:05 +00008447TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008448 TypeSourceInfo *EncodedTypeInfo
8449 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8450 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008452
Douglas Gregorb98b1992009-08-11 05:31:07 +00008453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008454 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008455 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008456
8457 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008458 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008459 E->getRParenLoc());
8460}
Mike Stump1eb44332009-09-09 15:08:12 +00008461
Douglas Gregorb98b1992009-08-11 05:31:07 +00008462template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008463ExprResult TreeTransform<Derived>::
8464TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8465 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8466 if (result.isInvalid()) return ExprError();
8467 Expr *subExpr = result.take();
8468
8469 if (!getDerived().AlwaysRebuild() &&
8470 subExpr == E->getSubExpr())
8471 return SemaRef.Owned(E);
8472
8473 return SemaRef.Owned(new(SemaRef.Context)
8474 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8475}
8476
8477template<typename Derived>
8478ExprResult TreeTransform<Derived>::
8479TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8480 TypeSourceInfo *TSInfo
8481 = getDerived().TransformType(E->getTypeInfoAsWritten());
8482 if (!TSInfo)
8483 return ExprError();
8484
8485 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8486 if (Result.isInvalid())
8487 return ExprError();
8488
8489 if (!getDerived().AlwaysRebuild() &&
8490 TSInfo == E->getTypeInfoAsWritten() &&
8491 Result.get() == E->getSubExpr())
8492 return SemaRef.Owned(E);
8493
8494 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8495 E->getBridgeKeywordLoc(), TSInfo,
8496 Result.get());
8497}
8498
8499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008500ExprResult
John McCall454feb92009-12-08 09:21:05 +00008501TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008502 // Transform arguments.
8503 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008504 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008505 Args.reserve(E->getNumArgs());
8506 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8507 &ArgChanged))
8508 return ExprError();
8509
Douglas Gregor92e986e2010-04-22 16:44:27 +00008510 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8511 // Class message: transform the receiver type.
8512 TypeSourceInfo *ReceiverTypeInfo
8513 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8514 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008515 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008516
Douglas Gregor92e986e2010-04-22 16:44:27 +00008517 // If nothing changed, just retain the existing message send.
8518 if (!getDerived().AlwaysRebuild() &&
8519 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008520 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008521
8522 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008523 SmallVector<SourceLocation, 16> SelLocs;
8524 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008525 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8526 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008527 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008528 E->getMethodDecl(),
8529 E->getLeftLoc(),
8530 move_arg(Args),
8531 E->getRightLoc());
8532 }
8533
8534 // Instance message: transform the receiver
8535 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8536 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008537 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008538 = getDerived().TransformExpr(E->getInstanceReceiver());
8539 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008540 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008541
8542 // If nothing changed, just retain the existing message send.
8543 if (!getDerived().AlwaysRebuild() &&
8544 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008545 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008546
Douglas Gregor92e986e2010-04-22 16:44:27 +00008547 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008548 SmallVector<SourceLocation, 16> SelLocs;
8549 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008550 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008551 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008552 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008553 E->getMethodDecl(),
8554 E->getLeftLoc(),
8555 move_arg(Args),
8556 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008557}
8558
Mike Stump1eb44332009-09-09 15:08:12 +00008559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008560ExprResult
John McCall454feb92009-12-08 09:21:05 +00008561TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008562 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008563}
8564
Mike Stump1eb44332009-09-09 15:08:12 +00008565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008566ExprResult
John McCall454feb92009-12-08 09:21:05 +00008567TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008574 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008575 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008576 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008577 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008578
8579 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008580
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008581 // If nothing changed, just retain the existing expression.
8582 if (!getDerived().AlwaysRebuild() &&
8583 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008584 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008585
John McCall9ae2f072010-08-23 23:25:46 +00008586 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008587 E->getLocation(),
8588 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589}
8590
Mike Stump1eb44332009-09-09 15:08:12 +00008591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008592ExprResult
John McCall454feb92009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008594 // 'super' and types never change. Property never changes. Just
8595 // retain the existing expression.
8596 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008597 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008598
Douglas Gregore3303542010-04-26 20:47:02 +00008599 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008600 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008601 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008602 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008603
Douglas Gregore3303542010-04-26 20:47:02 +00008604 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008605
Douglas Gregore3303542010-04-26 20:47:02 +00008606 // If nothing changed, just retain the existing expression.
8607 if (!getDerived().AlwaysRebuild() &&
8608 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008609 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008610
John McCall12f78a62010-12-02 01:19:52 +00008611 if (E->isExplicitProperty())
8612 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8613 E->getExplicitProperty(),
8614 E->getLocation());
8615
8616 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008617 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008618 E->getImplicitPropertyGetter(),
8619 E->getImplicitPropertySetter(),
8620 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008621}
8622
Mike Stump1eb44332009-09-09 15:08:12 +00008623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008624ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008625TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8626 // Transform the base expression.
8627 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8628 if (Base.isInvalid())
8629 return ExprError();
8630
8631 // Transform the key expression.
8632 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8633 if (Key.isInvalid())
8634 return ExprError();
8635
8636 // If nothing changed, just retain the existing expression.
8637 if (!getDerived().AlwaysRebuild() &&
8638 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8639 return SemaRef.Owned(E);
8640
8641 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8642 Base.get(), Key.get(),
8643 E->getAtIndexMethodDecl(),
8644 E->setAtIndexMethodDecl());
8645}
8646
8647template<typename Derived>
8648ExprResult
John McCall454feb92009-12-08 09:21:05 +00008649TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008650 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008651 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008652 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008653 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008654
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008655 // If nothing changed, just retain the existing expression.
8656 if (!getDerived().AlwaysRebuild() &&
8657 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008658 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008659
John McCall9ae2f072010-08-23 23:25:46 +00008660 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008661 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008662}
8663
Mike Stump1eb44332009-09-09 15:08:12 +00008664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008665ExprResult
John McCall454feb92009-12-08 09:21:05 +00008666TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008667 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008668 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008669 SubExprs.reserve(E->getNumSubExprs());
8670 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8671 SubExprs, &ArgumentChanged))
8672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008673
Douglas Gregorb98b1992009-08-11 05:31:07 +00008674 if (!getDerived().AlwaysRebuild() &&
8675 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008676 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008677
Douglas Gregorb98b1992009-08-11 05:31:07 +00008678 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8679 move_arg(SubExprs),
8680 E->getRParenLoc());
8681}
8682
Mike Stump1eb44332009-09-09 15:08:12 +00008683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008684ExprResult
John McCall454feb92009-12-08 09:21:05 +00008685TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008686 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008687
John McCallc6ac9c32011-02-04 18:33:18 +00008688 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8689 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8690
8691 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008692 blockScope->TheDecl->setBlockMissingReturnType(
8693 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008694
Chris Lattner686775d2011-07-20 06:58:45 +00008695 SmallVector<ParmVarDecl*, 4> params;
8696 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008697
8698 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008699 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8700 oldBlock->param_begin(),
8701 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008702 0, paramTypes, &params)) {
8703 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008704 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008705 }
John McCallc6ac9c32011-02-04 18:33:18 +00008706
8707 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008708 QualType exprResultType =
8709 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008710
8711 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008712 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008713 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008714 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008715 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008716 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008717 return ExprError();
8718 }
John McCall711c52b2011-01-05 12:14:39 +00008719
John McCallc6ac9c32011-02-04 18:33:18 +00008720 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008721 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008722 paramTypes.data(),
8723 paramTypes.size(),
8724 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008725 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008726 exprFunctionType->getExtInfo());
8727 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008728
8729 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008730 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008731 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008732
8733 if (!oldBlock->blockMissingReturnType()) {
8734 blockScope->HasImplicitReturnType = false;
8735 blockScope->ReturnType = exprResultType;
8736 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008737
John McCall711c52b2011-01-05 12:14:39 +00008738 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008739 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008740 if (body.isInvalid()) {
8741 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008742 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008743 }
John McCall711c52b2011-01-05 12:14:39 +00008744
John McCallc6ac9c32011-02-04 18:33:18 +00008745#ifndef NDEBUG
8746 // In builds with assertions, make sure that we captured everything we
8747 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008748 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8749 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8750 e = oldBlock->capture_end(); i != e; ++i) {
8751 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008752
Douglas Gregorfc921372011-05-20 15:32:55 +00008753 // Ignore parameter packs.
8754 if (isa<ParmVarDecl>(oldCapture) &&
8755 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8756 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008757
Douglas Gregorfc921372011-05-20 15:32:55 +00008758 VarDecl *newCapture =
8759 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8760 oldCapture));
8761 assert(blockScope->CaptureMap.count(newCapture));
8762 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008763 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008764 }
8765#endif
8766
8767 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8768 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008769}
8770
Mike Stump1eb44332009-09-09 15:08:12 +00008771template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008772ExprResult
John McCall454feb92009-12-08 09:21:05 +00008773TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008774 ValueDecl *ND
8775 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8776 E->getDecl()));
8777 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008778 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008779
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008780 if (!getDerived().AlwaysRebuild() &&
8781 ND == E->getDecl()) {
8782 // Mark it referenced in the new context regardless.
8783 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008784 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008785
John McCall3fa5cae2010-10-26 07:05:15 +00008786 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008787 }
8788
Abramo Bagnara25777432010-08-11 22:01:17 +00008789 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008790 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008791 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008792}
Mike Stump1eb44332009-09-09 15:08:12 +00008793
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008794template<typename Derived>
8795ExprResult
8796TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008797 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008798}
Eli Friedman276b0612011-10-11 02:20:01 +00008799
8800template<typename Derived>
8801ExprResult
8802TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008803 QualType RetTy = getDerived().TransformType(E->getType());
8804 bool ArgumentChanged = false;
8805 ASTOwningVector<Expr*> SubExprs(SemaRef);
8806 SubExprs.reserve(E->getNumSubExprs());
8807 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8808 SubExprs, &ArgumentChanged))
8809 return ExprError();
8810
8811 if (!getDerived().AlwaysRebuild() &&
8812 !ArgumentChanged)
8813 return SemaRef.Owned(E);
8814
8815 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8816 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008817}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008818
Douglas Gregorb98b1992009-08-11 05:31:07 +00008819//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008820// Type reconstruction
8821//===----------------------------------------------------------------------===//
8822
Mike Stump1eb44332009-09-09 15:08:12 +00008823template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008824QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8825 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008826 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008827 getDerived().getBaseEntity());
8828}
8829
Mike Stump1eb44332009-09-09 15:08:12 +00008830template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008831QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8832 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008833 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008834 getDerived().getBaseEntity());
8835}
8836
Mike Stump1eb44332009-09-09 15:08:12 +00008837template<typename Derived>
8838QualType
John McCall85737a72009-10-30 00:06:24 +00008839TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8840 bool WrittenAsLValue,
8841 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008842 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008843 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008844}
8845
8846template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008847QualType
John McCall85737a72009-10-30 00:06:24 +00008848TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8849 QualType ClassType,
8850 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008851 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008852 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008853}
8854
8855template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008856QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008857TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8858 ArrayType::ArraySizeModifier SizeMod,
8859 const llvm::APInt *Size,
8860 Expr *SizeExpr,
8861 unsigned IndexTypeQuals,
8862 SourceRange BracketsRange) {
8863 if (SizeExpr || !Size)
8864 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8865 IndexTypeQuals, BracketsRange,
8866 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008867
8868 QualType Types[] = {
8869 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8870 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8871 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008872 };
8873 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8874 QualType SizeType;
8875 for (unsigned I = 0; I != NumTypes; ++I)
8876 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8877 SizeType = Types[I];
8878 break;
8879 }
Mike Stump1eb44332009-09-09 15:08:12 +00008880
Eli Friedman01f276d2012-01-25 23:20:27 +00008881 // Note that we can return a VariableArrayType here in the case where
8882 // the element type was a dependent VariableArrayType.
8883 IntegerLiteral *ArraySize
8884 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8885 /*FIXME*/BracketsRange.getBegin());
8886 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008887 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008888 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008889}
Mike Stump1eb44332009-09-09 15:08:12 +00008890
Douglas Gregor577f75a2009-08-04 16:50:30 +00008891template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008892QualType
8893TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008894 ArrayType::ArraySizeModifier SizeMod,
8895 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008896 unsigned IndexTypeQuals,
8897 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008898 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008899 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008900}
8901
8902template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008903QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008904TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008905 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008906 unsigned IndexTypeQuals,
8907 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008908 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008909 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008910}
Mike Stump1eb44332009-09-09 15:08:12 +00008911
Douglas Gregor577f75a2009-08-04 16:50:30 +00008912template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008913QualType
8914TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008915 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008916 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008917 unsigned IndexTypeQuals,
8918 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008919 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008920 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921 IndexTypeQuals, BracketsRange);
8922}
8923
8924template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008925QualType
8926TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008927 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008928 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008929 unsigned IndexTypeQuals,
8930 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008931 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008932 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008933 IndexTypeQuals, BracketsRange);
8934}
8935
8936template<typename Derived>
8937QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008938 unsigned NumElements,
8939 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008941 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942}
Mike Stump1eb44332009-09-09 15:08:12 +00008943
Douglas Gregor577f75a2009-08-04 16:50:30 +00008944template<typename Derived>
8945QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8946 unsigned NumElements,
8947 SourceLocation AttributeLoc) {
8948 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8949 NumElements, true);
8950 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008951 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8952 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008953 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954}
Mike Stump1eb44332009-09-09 15:08:12 +00008955
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008957QualType
8958TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008959 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008961 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
Mike Stump1eb44332009-09-09 15:08:12 +00008963
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964template<typename Derived>
8965QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008966 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008968 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008969 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008970 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008971 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008972 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008973 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008974 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008976 getDerived().getBaseEntity(),
8977 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008978}
Mike Stump1eb44332009-09-09 15:08:12 +00008979
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008981QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8982 return SemaRef.Context.getFunctionNoProtoType(T);
8983}
8984
8985template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008986QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8987 assert(D && "no decl found");
8988 if (D->isInvalidDecl()) return QualType();
8989
Douglas Gregor92e986e2010-04-22 16:44:27 +00008990 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008991 TypeDecl *Ty;
8992 if (isa<UsingDecl>(D)) {
8993 UsingDecl *Using = cast<UsingDecl>(D);
8994 assert(Using->isTypeName() &&
8995 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8996
8997 // A valid resolved using typename decl points to exactly one type decl.
8998 assert(++Using->shadow_begin() == Using->shadow_end());
8999 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009000
John McCalled976492009-12-04 22:46:56 +00009001 } else {
9002 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9003 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9004 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9005 }
9006
9007 return SemaRef.Context.getTypeDeclType(Ty);
9008}
9009
9010template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009011QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9012 SourceLocation Loc) {
9013 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014}
9015
9016template<typename Derived>
9017QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9018 return SemaRef.Context.getTypeOfType(Underlying);
9019}
9020
9021template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009022QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9023 SourceLocation Loc) {
9024 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025}
9026
9027template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009028QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9029 UnaryTransformType::UTTKind UKind,
9030 SourceLocation Loc) {
9031 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9032}
9033
9034template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009035QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009036 TemplateName Template,
9037 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009038 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009039 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009040}
Mike Stump1eb44332009-09-09 15:08:12 +00009041
Douglas Gregordcee1a12009-08-06 05:28:30 +00009042template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009043QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9044 SourceLocation KWLoc) {
9045 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9046}
9047
9048template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009049TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009050TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009051 bool TemplateKW,
9052 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009053 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009054 Template);
9055}
9056
9057template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009058TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009059TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9060 const IdentifierInfo &Name,
9061 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009062 QualType ObjectType,
9063 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009064 UnqualifiedId TemplateName;
9065 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009066 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009067 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009068 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009069 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009070 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009071 /*EnteringContext=*/false,
9072 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009073 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009074}
Mike Stump1eb44332009-09-09 15:08:12 +00009075
Douglas Gregorb98b1992009-08-11 05:31:07 +00009076template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009077TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009078TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009079 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009080 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009081 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009082 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009083 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009084 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009085 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009086 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009087 Sema::TemplateTy Template;
9088 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009089 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009090 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009091 /*EnteringContext=*/false,
9092 Template);
9093 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009094}
Sean Huntc3021132010-05-05 15:23:54 +00009095
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009097ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009098TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9099 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009100 Expr *OrigCallee,
9101 Expr *First,
9102 Expr *Second) {
9103 Expr *Callee = OrigCallee->IgnoreParenCasts();
9104 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009105
Douglas Gregorb98b1992009-08-11 05:31:07 +00009106 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009107 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009108 if (!First->getType()->isOverloadableType() &&
9109 !Second->getType()->isOverloadableType())
9110 return getSema().CreateBuiltinArraySubscriptExpr(First,
9111 Callee->getLocStart(),
9112 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009113 } else if (Op == OO_Arrow) {
9114 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009115 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9116 } else if (Second == 0 || isPostIncDec) {
9117 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009118 // The argument is not of overloadable type, so try to create a
9119 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009120 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009121 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009122
John McCall9ae2f072010-08-23 23:25:46 +00009123 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009124 }
9125 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009126 if (!First->getType()->isOverloadableType() &&
9127 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009128 // Neither of the arguments is an overloadable type, so try to
9129 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009130 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009131 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009132 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009133 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009134 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009135
Douglas Gregorb98b1992009-08-11 05:31:07 +00009136 return move(Result);
9137 }
9138 }
Mike Stump1eb44332009-09-09 15:08:12 +00009139
9140 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009142 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009143
John McCall9ae2f072010-08-23 23:25:46 +00009144 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009145 assert(ULE->requiresADL());
9146
9147 // FIXME: Do we have to check
9148 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009149 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009150 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009151 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009152 }
Mike Stump1eb44332009-09-09 15:08:12 +00009153
Douglas Gregorb98b1992009-08-11 05:31:07 +00009154 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009155 Expr *Args[2] = { First, Second };
9156 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009157
Douglas Gregorb98b1992009-08-11 05:31:07 +00009158 // Create the overloaded operator invocation for unary operators.
9159 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009160 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009161 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009162 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009163 }
Mike Stump1eb44332009-09-09 15:08:12 +00009164
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009165 if (Op == OO_Subscript) {
9166 SourceLocation LBrace;
9167 SourceLocation RBrace;
9168
9169 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9170 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9171 LBrace = SourceLocation::getFromRawEncoding(
9172 NameLoc.CXXOperatorName.BeginOpNameLoc);
9173 RBrace = SourceLocation::getFromRawEncoding(
9174 NameLoc.CXXOperatorName.EndOpNameLoc);
9175 } else {
9176 LBrace = Callee->getLocStart();
9177 RBrace = OpLoc;
9178 }
9179
9180 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9181 First, Second);
9182 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009183
Douglas Gregorb98b1992009-08-11 05:31:07 +00009184 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009185 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009186 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009187 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9188 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009190
Mike Stump1eb44332009-09-09 15:08:12 +00009191 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009192}
Mike Stump1eb44332009-09-09 15:08:12 +00009193
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009195ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009196TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009197 SourceLocation OperatorLoc,
9198 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009199 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009200 TypeSourceInfo *ScopeType,
9201 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009202 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009203 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009204 QualType BaseType = Base->getType();
9205 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009206 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009207 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009208 !BaseType->getAs<PointerType>()->getPointeeType()
9209 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009210 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009211 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009212 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009213 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009214 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009215 /*FIXME?*/true);
9216 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009217
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009218 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009219 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9220 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9221 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9222 NameInfo.setNamedTypeInfo(DestroyedType);
9223
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009224 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009225
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009226 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009227 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009228 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009229 SS, TemplateKWLoc,
9230 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009231 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009232 /*TemplateArgs*/ 0);
9233}
9234
Douglas Gregor577f75a2009-08-04 16:50:30 +00009235} // end namespace clang
9236
9237#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H