blob: a66378e51783d2104a590483c25e075501db14a5 [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
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000525 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
526 FunctionProtoTypeLoc TL,
527 CXXRecordDecl *ThisContext,
528 unsigned ThisTypeQuals);
529
John Wiegley28bbe4b2011-04-28 01:08:34 +0000530 StmtResult
531 TransformSEHHandler(Stmt *Handler);
532
John McCall43fed0d2010-11-12 08:19:04 +0000533 QualType
534 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
535 TemplateSpecializationTypeLoc TL,
536 TemplateName Template);
537
538 QualType
539 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
540 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000541 TemplateName Template,
542 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000543
544 QualType
545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000546 DependentTemplateSpecializationTypeLoc TL,
547 NestedNameSpecifierLoc QualifierLoc);
548
John McCall21ef0fa2010-03-11 09:03:00 +0000549 /// \brief Transforms the parameters of a function type into the
550 /// given vectors.
551 ///
552 /// The result vectors should be kept in sync; null entries in the
553 /// variables vector are acceptable.
554 ///
555 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000556 bool TransformFunctionTypeParams(SourceLocation Loc,
557 ParmVarDecl **Params, unsigned NumParams,
558 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000559 SmallVectorImpl<QualType> &PTypes,
560 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000561
562 /// \brief Transforms a single function-type parameter. Return null
563 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000564 ///
565 /// \param indexAdjustment - A number to add to the parameter's
566 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000567 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000568 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000569 llvm::Optional<unsigned> NumExpansions,
570 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000571
John McCall43fed0d2010-11-12 08:19:04 +0000572 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000573
John McCall60d7b3a2010-08-24 06:29:42 +0000574 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
575 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000809
810 if (InstName.isNull())
811 return QualType();
812
813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
818 Args);
819
820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
825
826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Sean Huntc3021132010-05-05 15:23:54 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Sean Huntc3021132010-05-05 15:23:54 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Sean Huntc3021132010-05-05 15:23:54 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
937 QualType RebuildPackExpansionType(QualType Pattern,
938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
987 /// and the
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
1056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
1057 Stmt *SubStmt) {
1058 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1059 }
1060
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 /// \brief Build a new "if" statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001065 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001066 VarDecl *CondVar, Stmt *Then,
1067 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001068 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 }
Mike Stump1eb44332009-09-09 15:08:12 +00001070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Start building a new switch statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001076 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001077 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001078 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 }
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /// \brief Attach the body to the switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001086 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001087 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001088 }
1089
1090 /// \brief Build a new while statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001094 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1095 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001096 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 }
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Douglas Gregor43959a92009-08-20 07:17:43 +00001099 /// \brief Build a new do-while statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001103 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001104 SourceLocation WhileLoc, SourceLocation LParenLoc,
1105 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001106 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1107 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 }
1109
1110 /// \brief Build a new for statement.
1111 ///
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001114 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1115 Stmt *Init, Sema::FullExprArg Cond,
1116 VarDecl *CondVar, Sema::FullExprArg Inc,
1117 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001118 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001119 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001120 }
Mike Stump1eb44332009-09-09 15:08:12 +00001121
Douglas Gregor43959a92009-08-20 07:17:43 +00001122 /// \brief Build a new goto statement.
1123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001126 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1127 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001128 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001129 }
1130
1131 /// \brief Build a new indirect goto statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001135 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001136 SourceLocation StarLoc,
1137 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001138 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
Mike Stump1eb44332009-09-09 15:08:12 +00001140
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 /// \brief Build a new return statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001145 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001146 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Douglas Gregor43959a92009-08-20 07:17:43 +00001149 /// \brief Build a new declaration statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001153 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001154 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001156 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1157 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001158 }
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Anders Carlsson703e3942010-01-24 05:50:09 +00001160 /// \brief Build a new inline asm statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001165 bool IsSimple,
1166 bool IsVolatile,
1167 unsigned NumOutputs,
1168 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001169 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 MultiExprArg Constraints,
1171 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001172 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 MultiExprArg Clobbers,
1174 SourceLocation RParenLoc,
1175 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001177 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001178 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001179 RParenLoc, MSAsm);
1180 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181
1182 /// \brief Build a new Objective-C @try statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001186 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001187 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001188 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Stmt *Finally) {
1190 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1191 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001192 }
1193
Douglas Gregorbe270a02010-04-26 17:57:08 +00001194 /// \brief Rebuild an Objective-C exception declaration.
1195 ///
1196 /// By default, performs semantic analysis to build the new declaration.
1197 /// Subclasses may override this routine to provide different behavior.
1198 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1199 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001200 return getSema().BuildObjCExceptionDecl(TInfo, T,
1201 ExceptionDecl->getInnerLocStart(),
1202 ExceptionDecl->getLocation(),
1203 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001204 }
Sean Huntc3021132010-05-05 15:23:54 +00001205
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 /// \brief Build a new Objective-C @catch statement.
1207 ///
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001210 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001211 SourceLocation RParenLoc,
1212 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001213 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001215 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 }
Sean Huntc3021132010-05-05 15:23:54 +00001217
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001218 /// \brief Build a new Objective-C @finally statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001223 Stmt *Body) {
1224 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 }
Sean Huntc3021132010-05-05 15:23:54 +00001226
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001227 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001232 Expr *Operand) {
1233 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001234 }
Sean Huntc3021132010-05-05 15:23:54 +00001235
John McCall07524032011-07-27 21:50:02 +00001236 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
1240 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1241 Expr *object) {
1242 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1243 }
1244
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001245 /// \brief Build a new Objective-C @synchronized statement.
1246 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001247 /// By default, performs semantic analysis to build the new statement.
1248 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001249 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001250 Expr *Object, Stmt *Body) {
1251 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001252 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001253
John McCallf85e1932011-06-15 23:02:42 +00001254 /// \brief Build a new Objective-C @autoreleasepool statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
1258 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1259 Stmt *Body) {
1260 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1261 }
John McCall990567c2011-07-27 01:07:15 +00001262
1263 /// \brief Build the collection operand to a new Objective-C fast
1264 /// enumeration statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
1268 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1269 Expr *collection) {
1270 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1271 }
John McCallf85e1932011-06-15 23:02:42 +00001272
Douglas Gregorc3203e72010-04-22 23:10:45 +00001273 /// \brief Build a new Objective-C fast enumeration statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001277 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001278 SourceLocation LParenLoc,
1279 Stmt *Element,
1280 Expr *Collection,
1281 SourceLocation RParenLoc,
1282 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001284 Element,
1285 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001287 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001288 }
Sean Huntc3021132010-05-05 15:23:54 +00001289
Douglas Gregor43959a92009-08-20 07:17:43 +00001290 /// \brief Build a new C++ exception declaration.
1291 ///
1292 /// By default, performs semantic analysis to build the new decaration.
1293 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001294 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001295 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001296 SourceLocation StartLoc,
1297 SourceLocation IdLoc,
1298 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001299 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1300 StartLoc, IdLoc, Id);
1301 if (Var)
1302 getSema().CurContext->addDecl(Var);
1303 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001304 }
1305
1306 /// \brief Build a new C++ catch statement.
1307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001310 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001311 VarDecl *ExceptionDecl,
1312 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001313 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1314 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001315 }
Mike Stump1eb44332009-09-09 15:08:12 +00001316
Douglas Gregor43959a92009-08-20 07:17:43 +00001317 /// \brief Build a new C++ try statement.
1318 ///
1319 /// By default, performs semantic analysis to build the new statement.
1320 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001321 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001322 Stmt *TryBlock,
1323 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001324 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Richard Smithad762fc2011-04-14 22:09:26 +00001327 /// \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 RebuildCXXForRangeStmt(SourceLocation ForLoc,
1332 SourceLocation ColonLoc,
1333 Stmt *Range, Stmt *BeginEnd,
1334 Expr *Cond, Expr *Inc,
1335 Stmt *LoopVar,
1336 SourceLocation RParenLoc) {
1337 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1338 Cond, Inc, LoopVar, RParenLoc);
1339 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001340
1341 /// \brief Build a new C++0x range-based for statement.
1342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1346 bool IsIfExists,
1347 NestedNameSpecifierLoc QualifierLoc,
1348 DeclarationNameInfo NameInfo,
1349 Stmt *Nested) {
1350 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1351 QualifierLoc, NameInfo, Nested);
1352 }
1353
Richard Smithad762fc2011-04-14 22:09:26 +00001354 /// \brief Attach body to a C++0x range-based for statement.
1355 ///
1356 /// By default, performs semantic analysis to finish the new statement.
1357 /// Subclasses may override this routine to provide different behavior.
1358 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1359 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1360 }
1361
John Wiegley28bbe4b2011-04-28 01:08:34 +00001362 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1363 SourceLocation TryLoc,
1364 Stmt *TryBlock,
1365 Stmt *Handler) {
1366 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1367 }
1368
1369 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1370 Expr *FilterExpr,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1373 }
1374
1375 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1376 Stmt *Block) {
1377 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1378 }
1379
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// \brief Build a new expression that references a declaration.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001385 LookupResult &R,
1386 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001387 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1388 }
1389
1390
1391 /// \brief Build a new expression that references a declaration.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001396 ValueDecl *VD,
1397 const DeclarationNameInfo &NameInfo,
1398 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001399 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001401
1402 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001403
1404 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 }
Mike Stump1eb44332009-09-09 15:08:12 +00001406
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001411 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001413 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 }
1415
Douglas Gregora71d8192009-09-04 17:36:40 +00001416 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001420 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001421 SourceLocation OperatorLoc,
1422 bool isArrow,
1423 CXXScopeSpec &SS,
1424 TypeSourceInfo *ScopeType,
1425 SourceLocation CCLoc,
1426 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001427 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001430 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001434 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 Expr *SubExpr) {
1436 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 }
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 /// \brief Build a new builtin offsetof expression.
1440 ///
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001443 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001444 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001445 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001446 unsigned NumComponents,
1447 SourceLocation RParenLoc) {
1448 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1449 NumComponents, RParenLoc);
1450 }
Sean Huntc3021132010-05-05 15:23:54 +00001451
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 /// \brief Build a new sizeof, alignof or vec_step expression with a
1453 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001454 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001457 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1458 SourceLocation OpLoc,
1459 UnaryExprOrTypeTrait ExprKind,
1460 SourceRange R) {
1461 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 }
1463
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 /// \brief Build a new sizeof, alignof or vec step expression with an
1465 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001466 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001469 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1470 UnaryExprOrTypeTrait ExprKind,
1471 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001473 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001475 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001476
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 return move(Result);
1478 }
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001488 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1489 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 RBracketLoc);
1491 }
1492
1493 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001499 SourceLocation RParenLoc,
1500 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001501 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 }
1504
1505 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001506 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001509 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001510 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001511 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001512 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 const DeclarationNameInfo &MemberNameInfo,
1514 ValueDecl *Member,
1515 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001516 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001517 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001518 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1519 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001520 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001521 // We have a reference to an unnamed field. This is always the
1522 // base of an anonymous struct/union member access, i.e. the
1523 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001524 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001525 assert(Member->getType()->isRecordType() &&
1526 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Richard Smith9138b4e2011-10-26 19:06:56 +00001528 BaseResult =
1529 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001530 QualifierLoc.getNestedNameSpecifier(),
1531 FoundDecl, Member);
1532 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001533 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001534 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001535 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001536 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001537 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001538 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001539 cast<FieldDecl>(Member)->getType(),
1540 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001541 return getSema().Owned(ME);
1542 }
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001544 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001545 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001546
John Wiegley429bb272011-04-08 18:41:53 +00001547 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001548 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001549
John McCall6bb80172010-03-30 21:47:33 +00001550 // FIXME: this involves duplicating earlier analysis in a lot of
1551 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001552 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001553 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001554 R.resolveKind();
1555
John McCall9ae2f072010-08-23 23:25:46 +00001556 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001557 SS, TemplateKWLoc,
1558 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001559 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 }
Mike Stump1eb44332009-09-09 15:08:12 +00001561
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001563 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001566 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001567 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001568 Expr *LHS, Expr *RHS) {
1569 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
1571
1572 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001577 SourceLocation QuestionLoc,
1578 Expr *LHS,
1579 SourceLocation ColonLoc,
1580 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001581 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1582 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 }
1584
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001586 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001589 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001590 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001593 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001594 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 }
Mike Stump1eb44332009-09-09 15:08:12 +00001596
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001602 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001604 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001605 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001606 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 SourceLocation OpLoc,
1615 SourceLocation AccessorLoc,
1616 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001617
John McCall129e2df2009-11-30 22:42:35 +00001618 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001620 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001621 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001622 SS, SourceLocation(),
1623 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001625 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001629 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001633 MultiExprArg Inits,
1634 SourceLocation RBraceLoc,
1635 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001637 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1638 if (Result.isInvalid() || ResultTy->isDependentType())
1639 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001640
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 // Patch in the result type we were given, which may have been computed
1642 // when the initial InitListExpr was built.
1643 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1644 ILE->setType(ResultTy);
1645 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 MultiExprArg ArrayExprs,
1654 SourceLocation EqualOrColonLoc,
1655 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001656 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001662
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 ArrayExprs.release();
1664 return move(Result);
1665 }
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001668 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// By default, builds the implicit value initialization without performing
1670 /// any semantic analysis. Subclasses may override this routine to provide
1671 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1674 }
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001677 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001682 SourceLocation RParenLoc) {
1683 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001684 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001685 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001689 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001693 MultiExprArg SubExprs,
1694 SourceLocation RParenLoc) {
1695 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 }
Mike Stump1eb44332009-09-09 15:08:12 +00001697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001699 ///
1700 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// rather than attempting to map the label statement itself.
1702 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001703 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001704 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001705 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001715 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
Mike Stump1eb44332009-09-09 15:08:12 +00001717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// \brief Build a new __builtin_choose_expr expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
1725 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001726 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 RParenLoc);
1728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Peter Collingbournef111d932011-04-15 00:35:48 +00001730 /// \brief Build a new generic selection expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
1734 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1735 SourceLocation DefaultLoc,
1736 SourceLocation RParenLoc,
1737 Expr *ControllingExpr,
1738 TypeSourceInfo **Types,
1739 Expr **Exprs,
1740 unsigned NumAssocs) {
1741 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1742 ControllingExpr, Types, Exprs,
1743 NumAssocs);
1744 }
1745
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// \brief Build a new overloaded operator call expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// The semantic analysis provides the behavior of template instantiation,
1750 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001751 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// argument-dependent lookup, etc. Subclasses may override this routine to
1753 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001756 Expr *Callee,
1757 Expr *First,
1758 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001759
1760 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// reinterpret_cast.
1762 ///
1763 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001764 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 Stmt::StmtClass Class,
1768 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001769 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RAngleLoc,
1771 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation RParenLoc) {
1774 switch (Class) {
1775 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001776 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001777 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001778 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779
1780 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001790
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001792 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001793 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001794 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001797 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new C++ static_cast expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001807 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 SourceLocation RAngleLoc,
1809 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001810 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001812 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001813 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001814 SourceRange(LAngleLoc, RAngleLoc),
1815 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 }
1817
1818 /// \brief Build a new C++ dynamic_cast expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001822 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001824 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 SourceLocation RAngleLoc,
1826 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001827 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001829 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001830 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001831 SourceRange(LAngleLoc, RAngleLoc),
1832 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 }
1834
1835 /// \brief Build a new C++ reinterpret_cast expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001839 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001841 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 SourceLocation RAngleLoc,
1843 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001844 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001846 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001847 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001848 SourceRange(LAngleLoc, RAngleLoc),
1849 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
1851
1852 /// \brief Build a new C++ const_cast expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001856 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001858 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceLocation RAngleLoc,
1860 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001861 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001863 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001864 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001865 SourceRange(LAngleLoc, RAngleLoc),
1866 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 /// \brief Build a new C++ functional-style cast expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001873 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1874 SourceLocation LParenLoc,
1875 Expr *Sub,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001878 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001879 RParenLoc);
1880 }
Mike Stump1eb44332009-09-09 15:08:12 +00001881
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 /// \brief Build a new C++ typeid(type) expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001887 SourceLocation TypeidLoc,
1888 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001890 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001891 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 }
Mike Stump1eb44332009-09-09 15:08:12 +00001893
Francois Pichet01b7c302010-09-08 12:20:18 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 /// \brief Build a new C++ typeid(expr) expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001900 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001901 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001903 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001904 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001905 }
1906
Francois Pichet01b7c302010-09-08 12:20:18 +00001907 /// \brief Build a new C++ __uuidof(type) expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
1911 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1912 SourceLocation TypeidLoc,
1913 TypeSourceInfo *Operand,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1916 RParenLoc);
1917 }
1918
1919 /// \brief Build a new C++ __uuidof(expr) expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
1923 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1924 SourceLocation TypeidLoc,
1925 Expr *Operand,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1928 RParenLoc);
1929 }
1930
Douglas Gregorb98b1992009-08-11 05:31:07 +00001931 /// \brief Build a new C++ "this" expression.
1932 ///
1933 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001934 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001936 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001937 QualType ThisType,
1938 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001939 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001941 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1942 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new C++ throw expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001949 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1950 bool IsThrownVariableInScope) {
1951 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 }
1953
1954 /// \brief Build a new C++ default-argument expression.
1955 ///
1956 /// By default, builds a new default-argument expression, which does not
1957 /// require any semantic analysis. Subclasses may override this routine to
1958 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001959 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001960 ParmVarDecl *Param) {
1961 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1962 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 }
1964
1965 /// \brief Build a new C++ zero-initialization expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001969 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1970 SourceLocation LParenLoc,
1971 SourceLocation RParenLoc) {
1972 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001973 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 /// \brief Build a new C++ "new" expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001981 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001982 bool UseGlobal,
1983 SourceLocation PlacementLParen,
1984 MultiExprArg PlacementArgs,
1985 SourceLocation PlacementRParen,
1986 SourceRange TypeIdParens,
1987 QualType AllocatedType,
1988 TypeSourceInfo *AllocatedTypeInfo,
1989 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001990 SourceRange DirectInitRange,
1991 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001992 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 PlacementLParen,
1994 move(PlacementArgs),
1995 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001996 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001997 AllocatedType,
1998 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001999 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002000 DirectInitRange,
2001 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 }
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 /// \brief Build a new C++ "delete" expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002008 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 bool IsGlobalDelete,
2010 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002011 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002013 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 }
Mike Stump1eb44332009-09-09 15:08:12 +00002015
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 /// \brief Build a new unary type trait expression.
2017 ///
2018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002020 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002021 SourceLocation StartLoc,
2022 TypeSourceInfo *T,
2023 SourceLocation RParenLoc) {
2024 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002025 }
2026
Francois Pichet6ad6f282010-12-07 00:08:36 +00002027 /// \brief Build a new binary type trait expression.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
2031 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2032 SourceLocation StartLoc,
2033 TypeSourceInfo *LhsT,
2034 TypeSourceInfo *RhsT,
2035 SourceLocation RParenLoc) {
2036 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2037 }
2038
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002039 /// \brief Build a new type trait expression.
2040 ///
2041 /// By default, performs semantic analysis to build the new expression.
2042 /// Subclasses may override this routine to provide different behavior.
2043 ExprResult RebuildTypeTrait(TypeTrait Trait,
2044 SourceLocation StartLoc,
2045 ArrayRef<TypeSourceInfo *> Args,
2046 SourceLocation RParenLoc) {
2047 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2048 }
2049
John Wiegley21ff2e52011-04-28 00:16:57 +00002050 /// \brief Build a new array type trait expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2055 SourceLocation StartLoc,
2056 TypeSourceInfo *TSInfo,
2057 Expr *DimExpr,
2058 SourceLocation RParenLoc) {
2059 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2060 }
2061
John Wiegley55262202011-04-25 06:54:41 +00002062 /// \brief Build a new expression trait expression.
2063 ///
2064 /// By default, performs semantic analysis to build the new expression.
2065 /// Subclasses may override this routine to provide different behavior.
2066 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2067 SourceLocation StartLoc,
2068 Expr *Queried,
2069 SourceLocation RParenLoc) {
2070 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2071 }
2072
Mike Stump1eb44332009-09-09 15:08:12 +00002073 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 /// expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002078 ExprResult RebuildDependentScopeDeclRefExpr(
2079 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002080 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002081 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002082 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002084 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002085
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002086 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002088 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002089
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 }
2092
2093 /// \brief Build a new template-id expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002097 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002098 SourceLocation TemplateKWLoc,
2099 LookupResult &R,
2100 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002101 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002102 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2103 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 }
2105
2106 /// \brief Build a new object-construction expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002111 SourceLocation Loc,
2112 CXXConstructorDecl *Constructor,
2113 bool IsElidable,
2114 MultiExprArg Args,
2115 bool HadMultipleCandidates,
2116 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002117 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002118 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002119 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002120 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002121 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002123
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002124 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002125 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002126 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 RequiresZeroInit, ConstructKind,
2128 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 }
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 RebuildCXXTemporaryObjectExpr(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 }
2144
2145 /// \brief Build a new object-construction expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002149 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2150 SourceLocation LParenLoc,
2151 MultiExprArg Args,
2152 SourceLocation RParenLoc) {
2153 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 LParenLoc,
2155 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002156 RParenLoc);
2157 }
Mike Stump1eb44332009-09-09 15:08:12 +00002158
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 /// \brief Build a new member reference expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002163 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002164 QualType BaseType,
2165 bool IsArrow,
2166 SourceLocation OperatorLoc,
2167 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002168 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002169 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002170 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002171 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002173 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002174
John McCall9ae2f072010-08-23 23:25:46 +00002175 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002176 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002177 SS, TemplateKWLoc,
2178 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002179 MemberNameInfo,
2180 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002181 }
2182
John McCall129e2df2009-11-30 22:42:35 +00002183 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002187 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2188 SourceLocation OperatorLoc,
2189 bool IsArrow,
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002192 NamedDecl *FirstQualifierInScope,
2193 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002194 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002195 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002196 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002197
John McCall9ae2f072010-08-23 23:25:46 +00002198 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002199 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002200 SS, TemplateKWLoc,
2201 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002202 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002203 }
Mike Stump1eb44332009-09-09 15:08:12 +00002204
Sebastian Redl2e156222010-09-10 20:55:43 +00002205 /// \brief Build a new noexcept expression.
2206 ///
2207 /// By default, performs semantic analysis to build the new expression.
2208 /// Subclasses may override this routine to provide different behavior.
2209 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2210 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2211 }
2212
Douglas Gregoree8aff02011-01-04 17:33:58 +00002213 /// \brief Build a new expression to compute the length of a parameter pack.
2214 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2215 SourceLocation PackLoc,
2216 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002217 llvm::Optional<unsigned> Length) {
2218 if (Length)
2219 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2220 OperatorLoc, Pack, PackLoc,
2221 RParenLoc, *Length);
2222
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2224 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002225 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002226 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002227
2228 /// \brief Build a new Objective-C array literal.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
2232 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2233 Expr **Elements, unsigned NumElements) {
2234 return getSema().BuildObjCArrayLiteral(Range,
2235 MultiExprArg(Elements, NumElements));
2236 }
2237
2238 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
2239 Expr *Base, Expr *Key,
2240 ObjCMethodDecl *getterMethod,
2241 ObjCMethodDecl *setterMethod) {
2242 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2243 getterMethod, setterMethod);
2244 }
2245
2246 /// \brief Build a new Objective-C dictionary literal.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2251 ObjCDictionaryElement *Elements,
2252 unsigned NumElements) {
2253 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2254 }
2255
Douglas Gregorb98b1992009-08-11 05:31:07 +00002256 /// \brief Build a new Objective-C @encode expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002260 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002261 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002262 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002263 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002264 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002265 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266
Douglas Gregor92e986e2010-04-22 16:44:27 +00002267 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002268 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002269 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002270 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002271 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002272 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002273 MultiExprArg Args,
2274 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002275 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2276 ReceiverTypeInfo->getType(),
2277 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002278 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002279 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 }
2281
2282 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002283 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002285 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002287 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 MultiExprArg Args,
2289 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002290 return SemaRef.BuildInstanceMessage(Receiver,
2291 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002294 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 }
2296
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002297 /// \brief Build a new Objective-C ivar reference expression.
2298 ///
2299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002301 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 SourceLocation IvarLoc,
2303 bool IsArrow, bool IsFreeIvar) {
2304 // FIXME: We lose track of the IsFreeIvar bit.
2305 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002306 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002307 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2308 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002309 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002311 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002312 false);
John Wiegley429bb272011-04-08 18:41:53 +00002313 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002314 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002315
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 if (Result.get())
2317 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002318
John Wiegley429bb272011-04-08 18:41:53 +00002319 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002320 /*FIXME:*/IvarLoc, IsArrow,
2321 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002322 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002323 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002324 /*TemplateArgs=*/0);
2325 }
Douglas Gregore3303542010-04-26 20:47:02 +00002326
2327 /// \brief Build a new Objective-C property reference expression.
2328 ///
2329 /// By default, performs semantic analysis to build the new expression.
2330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002331 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002332 ObjCPropertyDecl *Property,
2333 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002334 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002335 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002336 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2337 Sema::LookupMemberName);
2338 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002339 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002340 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002341 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002342 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002343 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002344
Douglas Gregore3303542010-04-26 20:47:02 +00002345 if (Result.get())
2346 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002347
John Wiegley429bb272011-04-08 18:41:53 +00002348 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002349 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002350 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002351 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002352 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002353 /*TemplateArgs=*/0);
2354 }
Sean Huntc3021132010-05-05 15:23:54 +00002355
John McCall12f78a62010-12-02 01:19:52 +00002356 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002357 ///
2358 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2361 ObjCMethodDecl *Getter,
2362 ObjCMethodDecl *Setter,
2363 SourceLocation PropertyLoc) {
2364 // Since these expressions can only be value-dependent, we do not
2365 // need to perform semantic analysis again.
2366 return Owned(
2367 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2368 VK_LValue, OK_ObjCProperty,
2369 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002370 }
2371
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002372 /// \brief Build a new Objective-C "isa" expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002376 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002377 bool IsArrow) {
2378 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002379 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002380 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2381 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002382 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002383 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002384 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002385 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002386 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002387
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002388 if (Result.get())
2389 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002390
John Wiegley429bb272011-04-08 18:41:53 +00002391 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002392 /*FIXME:*/IsaLoc, IsArrow,
2393 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002394 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002395 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 /*TemplateArgs=*/0);
2397 }
Sean Huntc3021132010-05-05 15:23:54 +00002398
Douglas Gregorb98b1992009-08-11 05:31:07 +00002399 /// \brief Build a new shuffle vector expression.
2400 ///
2401 /// By default, performs semantic analysis to build the new expression.
2402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002403 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002404 MultiExprArg SubExprs,
2405 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002406 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002407 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002408 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2409 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2410 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2411 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002412
Douglas Gregorb98b1992009-08-11 05:31:07 +00002413 // Build a reference to the __builtin_shufflevector builtin
2414 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002415 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002416 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2417 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002418 VK_LValue, BuiltinLoc));
2419 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2420 if (Callee.isInvalid())
2421 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002422
2423 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 unsigned NumSubExprs = SubExprs.size();
2425 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002426 ExprResult TheCall = SemaRef.Owned(
2427 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002428 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002429 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002430 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002431 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregorb98b1992009-08-11 05:31:07 +00002433 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002434 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002435 }
John McCall43fed0d2010-11-12 08:19:04 +00002436
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002437 /// \brief Build a new template argument pack expansion.
2438 ///
2439 /// By default, performs semantic analysis to build a new pack expansion
2440 /// for a template argument. Subclasses may override this routine to provide
2441 /// different behavior.
2442 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002443 SourceLocation EllipsisLoc,
2444 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002445 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002446 case TemplateArgument::Expression: {
2447 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002448 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2449 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002450 if (Result.isInvalid())
2451 return TemplateArgumentLoc();
2452
2453 return TemplateArgumentLoc(Result.get(), Result.get());
2454 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002455
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002457 return TemplateArgumentLoc(TemplateArgument(
2458 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002459 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002460 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002461 Pattern.getTemplateNameLoc(),
2462 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002463
2464 case TemplateArgument::Null:
2465 case TemplateArgument::Integral:
2466 case TemplateArgument::Declaration:
2467 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002468 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002469 llvm_unreachable("Pack expansion pattern has no parameter packs");
2470
2471 case TemplateArgument::Type:
2472 if (TypeSourceInfo *Expansion
2473 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002474 EllipsisLoc,
2475 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002476 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2477 Expansion);
2478 break;
2479 }
2480
2481 return TemplateArgumentLoc();
2482 }
2483
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002484 /// \brief Build a new expression pack expansion.
2485 ///
2486 /// By default, performs semantic analysis to build a new pack expansion
2487 /// for an expression. Subclasses may override this routine to provide
2488 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002489 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2490 llvm::Optional<unsigned> NumExpansions) {
2491 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002492 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002493
2494 /// \brief Build a new atomic operation expression.
2495 ///
2496 /// By default, performs semantic analysis to build the new expression.
2497 /// Subclasses may override this routine to provide different behavior.
2498 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2499 MultiExprArg SubExprs,
2500 QualType RetTy,
2501 AtomicExpr::AtomicOp Op,
2502 SourceLocation RParenLoc) {
2503 // Just create the expression; there is not any interesting semantic
2504 // analysis here because we can't actually build an AtomicExpr until
2505 // we are sure it is semantically sound.
2506 unsigned NumSubExprs = SubExprs.size();
2507 Expr **Subs = (Expr **)SubExprs.release();
2508 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2509 NumSubExprs, RetTy, Op,
2510 RParenLoc);
2511 }
2512
John McCall43fed0d2010-11-12 08:19:04 +00002513private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002514 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2515 QualType ObjectType,
2516 NamedDecl *FirstQualifierInScope,
2517 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002518
2519 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope,
2522 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002523};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002524
Douglas Gregor43959a92009-08-20 07:17:43 +00002525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002526StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002527 if (!S)
2528 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002529
Douglas Gregor43959a92009-08-20 07:17:43 +00002530 switch (S->getStmtClass()) {
2531 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002532
Douglas Gregor43959a92009-08-20 07:17:43 +00002533 // Transform individual statement nodes
2534#define STMT(Node, Parent) \
2535 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002536#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002537#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002538#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002539
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 // Transform expressions by calling TransformExpr.
2541#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002542#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002543#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002544#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 {
John McCall60d7b3a2010-08-24 06:29:42 +00002546 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002547 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002548 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002549
John McCall9ae2f072010-08-23 23:25:46 +00002550 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002551 }
Mike Stump1eb44332009-09-09 15:08:12 +00002552 }
2553
John McCall3fa5cae2010-10-26 07:05:15 +00002554 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002555}
Mike Stump1eb44332009-09-09 15:08:12 +00002556
2557
Douglas Gregor670444e2009-08-04 22:27:00 +00002558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002559ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002560 if (!E)
2561 return SemaRef.Owned(E);
2562
2563 switch (E->getStmtClass()) {
2564 case Stmt::NoStmtClass: break;
2565#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002566#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002567#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002568 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002569#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002570 }
2571
John McCall3fa5cae2010-10-26 07:05:15 +00002572 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002573}
2574
2575template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002576bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2577 unsigned NumInputs,
2578 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002579 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002580 bool *ArgChanged) {
2581 for (unsigned I = 0; I != NumInputs; ++I) {
2582 // If requested, drop call arguments that need to be dropped.
2583 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2584 if (ArgChanged)
2585 *ArgChanged = true;
2586
2587 break;
2588 }
2589
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002590 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2591 Expr *Pattern = Expansion->getPattern();
2592
Chris Lattner686775d2011-07-20 06:58:45 +00002593 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002594 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2595 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2596
2597 // Determine whether the set of unexpanded parameter packs can and should
2598 // be expanded.
2599 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002600 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002601 llvm::Optional<unsigned> OrigNumExpansions
2602 = Expansion->getNumExpansions();
2603 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002604 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2605 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002606 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002607 Expand, RetainExpansion,
2608 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 return true;
2610
2611 if (!Expand) {
2612 // The transform has determined that we should perform a simple
2613 // transformation on the pack expansion, producing another pack
2614 // expansion.
2615 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2616 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2617 if (OutPattern.isInvalid())
2618 return true;
2619
2620 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002621 Expansion->getEllipsisLoc(),
2622 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002623 if (Out.isInvalid())
2624 return true;
2625
2626 if (ArgChanged)
2627 *ArgChanged = true;
2628 Outputs.push_back(Out.get());
2629 continue;
2630 }
John McCallc8fc90a2011-07-06 07:30:07 +00002631
2632 // Record right away that the argument was changed. This needs
2633 // to happen even if the array expands to nothing.
2634 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002635
2636 // The transform has determined that we should perform an elementwise
2637 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002638 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002639 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2640 ExprResult Out = getDerived().TransformExpr(Pattern);
2641 if (Out.isInvalid())
2642 return true;
2643
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002644 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002645 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2646 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002647 if (Out.isInvalid())
2648 return true;
2649 }
2650
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002651 Outputs.push_back(Out.get());
2652 }
2653
2654 continue;
2655 }
2656
Douglas Gregoraa165f82011-01-03 19:04:46 +00002657 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2658 if (Result.isInvalid())
2659 return true;
2660
2661 if (Result.get() != Inputs[I] && ArgChanged)
2662 *ArgChanged = true;
2663
2664 Outputs.push_back(Result.get());
2665 }
2666
2667 return false;
2668}
2669
2670template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002671NestedNameSpecifierLoc
2672TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2673 NestedNameSpecifierLoc NNS,
2674 QualType ObjectType,
2675 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002676 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002677 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2678 Qualifier = Qualifier.getPrefix())
2679 Qualifiers.push_back(Qualifier);
2680
2681 CXXScopeSpec SS;
2682 while (!Qualifiers.empty()) {
2683 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2684 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2685
2686 switch (QNNS->getKind()) {
2687 case NestedNameSpecifier::Identifier:
2688 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2689 *QNNS->getAsIdentifier(),
2690 Q.getLocalBeginLoc(),
2691 Q.getLocalEndLoc(),
2692 ObjectType, false, SS,
2693 FirstQualifierInScope, false))
2694 return NestedNameSpecifierLoc();
2695
2696 break;
2697
2698 case NestedNameSpecifier::Namespace: {
2699 NamespaceDecl *NS
2700 = cast_or_null<NamespaceDecl>(
2701 getDerived().TransformDecl(
2702 Q.getLocalBeginLoc(),
2703 QNNS->getAsNamespace()));
2704 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2705 break;
2706 }
2707
2708 case NestedNameSpecifier::NamespaceAlias: {
2709 NamespaceAliasDecl *Alias
2710 = cast_or_null<NamespaceAliasDecl>(
2711 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2712 QNNS->getAsNamespaceAlias()));
2713 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2714 Q.getLocalEndLoc());
2715 break;
2716 }
2717
2718 case NestedNameSpecifier::Global:
2719 // There is no meaningful transformation that one could perform on the
2720 // global scope.
2721 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2722 break;
2723
2724 case NestedNameSpecifier::TypeSpecWithTemplate:
2725 case NestedNameSpecifier::TypeSpec: {
2726 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2727 FirstQualifierInScope, SS);
2728
2729 if (!TL)
2730 return NestedNameSpecifierLoc();
2731
2732 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
David Blaikie4e4d0842012-03-11 07:00:24 +00002733 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002734 TL.getType()->isEnumeralType())) {
2735 assert(!TL.getType().hasLocalQualifiers() &&
2736 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002737 if (TL.getType()->isEnumeralType())
2738 SemaRef.Diag(TL.getBeginLoc(),
2739 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2741 Q.getLocalEndLoc());
2742 break;
2743 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002744 // If the nested-name-specifier is an invalid type def, don't emit an
2745 // error because a previous error should have already been emitted.
2746 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2747 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2748 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2749 << TL.getType() << SS.getRange();
2750 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 return NestedNameSpecifierLoc();
2752 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002753 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002754
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002755 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002757 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 }
2759
2760 // Don't rebuild the nested-name-specifier if we don't have to.
2761 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2762 !getDerived().AlwaysRebuild())
2763 return NNS;
2764
2765 // If we can re-use the source-location data from the original
2766 // nested-name-specifier, do so.
2767 if (SS.location_size() == NNS.getDataLength() &&
2768 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2769 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2770
2771 // Allocate new nested-name-specifier location information.
2772 return SS.getWithLocInContext(SemaRef.Context);
2773}
2774
2775template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002776DeclarationNameInfo
2777TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002778::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002779 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002780 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002781 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002782
2783 switch (Name.getNameKind()) {
2784 case DeclarationName::Identifier:
2785 case DeclarationName::ObjCZeroArgSelector:
2786 case DeclarationName::ObjCOneArgSelector:
2787 case DeclarationName::ObjCMultiArgSelector:
2788 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002789 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002790 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002792
Douglas Gregor81499bb2009-09-03 22:13:48 +00002793 case DeclarationName::CXXConstructorName:
2794 case DeclarationName::CXXDestructorName:
2795 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002796 TypeSourceInfo *NewTInfo;
2797 CanQualType NewCanTy;
2798 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002799 NewTInfo = getDerived().TransformType(OldTInfo);
2800 if (!NewTInfo)
2801 return DeclarationNameInfo();
2802 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002803 }
2804 else {
2805 NewTInfo = 0;
2806 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002807 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002808 if (NewT.isNull())
2809 return DeclarationNameInfo();
2810 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2811 }
Mike Stump1eb44332009-09-09 15:08:12 +00002812
Abramo Bagnara25777432010-08-11 22:01:17 +00002813 DeclarationName NewName
2814 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2815 NewCanTy);
2816 DeclarationNameInfo NewNameInfo(NameInfo);
2817 NewNameInfo.setName(NewName);
2818 NewNameInfo.setNamedTypeInfo(NewTInfo);
2819 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002820 }
Mike Stump1eb44332009-09-09 15:08:12 +00002821 }
2822
David Blaikieb219cfc2011-09-23 05:06:16 +00002823 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002824}
2825
2826template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002827TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002828TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2829 TemplateName Name,
2830 SourceLocation NameLoc,
2831 QualType ObjectType,
2832 NamedDecl *FirstQualifierInScope) {
2833 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2834 TemplateDecl *Template = QTN->getTemplateDecl();
2835 assert(Template && "qualified template name must refer to a template");
2836
2837 TemplateDecl *TransTemplate
2838 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2839 Template));
2840 if (!TransTemplate)
2841 return TemplateName();
2842
2843 if (!getDerived().AlwaysRebuild() &&
2844 SS.getScopeRep() == QTN->getQualifier() &&
2845 TransTemplate == Template)
2846 return Name;
2847
2848 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2849 TransTemplate);
2850 }
2851
2852 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2853 if (SS.getScopeRep()) {
2854 // These apply to the scope specifier, not the template.
2855 ObjectType = QualType();
2856 FirstQualifierInScope = 0;
2857 }
2858
2859 if (!getDerived().AlwaysRebuild() &&
2860 SS.getScopeRep() == DTN->getQualifier() &&
2861 ObjectType.isNull())
2862 return Name;
2863
2864 if (DTN->isIdentifier()) {
2865 return getDerived().RebuildTemplateName(SS,
2866 *DTN->getIdentifier(),
2867 NameLoc,
2868 ObjectType,
2869 FirstQualifierInScope);
2870 }
2871
2872 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2873 ObjectType);
2874 }
2875
2876 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2877 TemplateDecl *TransTemplate
2878 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2879 Template));
2880 if (!TransTemplate)
2881 return TemplateName();
2882
2883 if (!getDerived().AlwaysRebuild() &&
2884 TransTemplate == Template)
2885 return Name;
2886
2887 return TemplateName(TransTemplate);
2888 }
2889
2890 if (SubstTemplateTemplateParmPackStorage *SubstPack
2891 = Name.getAsSubstTemplateTemplateParmPack()) {
2892 TemplateTemplateParmDecl *TransParam
2893 = cast_or_null<TemplateTemplateParmDecl>(
2894 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2895 if (!TransParam)
2896 return TemplateName();
2897
2898 if (!getDerived().AlwaysRebuild() &&
2899 TransParam == SubstPack->getParameterPack())
2900 return Name;
2901
2902 return getDerived().RebuildTemplateName(TransParam,
2903 SubstPack->getArgumentPack());
2904 }
2905
2906 // These should be getting filtered out before they reach the AST.
2907 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002908}
2909
2910template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002911void TreeTransform<Derived>::InventTemplateArgumentLoc(
2912 const TemplateArgument &Arg,
2913 TemplateArgumentLoc &Output) {
2914 SourceLocation Loc = getDerived().getBaseLocation();
2915 switch (Arg.getKind()) {
2916 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002917 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002918 break;
2919
2920 case TemplateArgument::Type:
2921 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002922 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002923
John McCall833ca992009-10-29 08:12:44 +00002924 break;
2925
Douglas Gregor788cd062009-11-11 01:00:40 +00002926 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002927 case TemplateArgument::TemplateExpansion: {
2928 NestedNameSpecifierLocBuilder Builder;
2929 TemplateName Template = Arg.getAsTemplate();
2930 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2931 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2932 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2933 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2934
2935 if (Arg.getKind() == TemplateArgument::Template)
2936 Output = TemplateArgumentLoc(Arg,
2937 Builder.getWithLocInContext(SemaRef.Context),
2938 Loc);
2939 else
2940 Output = TemplateArgumentLoc(Arg,
2941 Builder.getWithLocInContext(SemaRef.Context),
2942 Loc, Loc);
2943
Douglas Gregor788cd062009-11-11 01:00:40 +00002944 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002945 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002946
John McCall833ca992009-10-29 08:12:44 +00002947 case TemplateArgument::Expression:
2948 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2949 break;
2950
2951 case TemplateArgument::Declaration:
2952 case TemplateArgument::Integral:
2953 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002954 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002955 break;
2956 }
2957}
2958
2959template<typename Derived>
2960bool TreeTransform<Derived>::TransformTemplateArgument(
2961 const TemplateArgumentLoc &Input,
2962 TemplateArgumentLoc &Output) {
2963 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 switch (Arg.getKind()) {
2965 case TemplateArgument::Null:
2966 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002967 Output = Input;
2968 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002969
Douglas Gregor670444e2009-08-04 22:27:00 +00002970 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002971 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002972 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002973 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002974
2975 DI = getDerived().TransformType(DI);
2976 if (!DI) return true;
2977
2978 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2979 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 }
Mike Stump1eb44332009-09-09 15:08:12 +00002981
Douglas Gregor670444e2009-08-04 22:27:00 +00002982 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002983 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002984 DeclarationName Name;
2985 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2986 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002987 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002988 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002989 if (!D) return true;
2990
John McCall828bff22009-10-29 18:45:58 +00002991 Expr *SourceExpr = Input.getSourceDeclExpression();
2992 if (SourceExpr) {
2993 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002994 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002995 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002996 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002997 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002998 }
2999
3000 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003001 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003002 }
Mike Stump1eb44332009-09-09 15:08:12 +00003003
Douglas Gregor788cd062009-11-11 01:00:40 +00003004 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003005 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3006 if (QualifierLoc) {
3007 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3008 if (!QualifierLoc)
3009 return true;
3010 }
3011
Douglas Gregor1d752d72011-03-02 18:46:51 +00003012 CXXScopeSpec SS;
3013 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003014 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003015 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3016 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003017 if (Template.isNull())
3018 return true;
Sean Huntc3021132010-05-05 15:23:54 +00003019
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003020 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003021 Input.getTemplateNameLoc());
3022 return false;
3023 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003024
3025 case TemplateArgument::TemplateExpansion:
3026 llvm_unreachable("Caller should expand pack expansions");
3027
Douglas Gregor670444e2009-08-04 22:27:00 +00003028 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003029 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003030 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003031 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003032
John McCall833ca992009-10-29 08:12:44 +00003033 Expr *InputExpr = Input.getSourceExpression();
3034 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3035
Chris Lattner223de242011-04-25 20:37:58 +00003036 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003037 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003038 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003039 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003040 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003041 }
Mike Stump1eb44332009-09-09 15:08:12 +00003042
Douglas Gregor670444e2009-08-04 22:27:00 +00003043 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003044 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003046 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003047 AEnd = Arg.pack_end();
3048 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003049
John McCall833ca992009-10-29 08:12:44 +00003050 // FIXME: preserve source information here when we start
3051 // caring about parameter packs.
3052
John McCall828bff22009-10-29 18:45:58 +00003053 TemplateArgumentLoc InputArg;
3054 TemplateArgumentLoc OutputArg;
3055 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3056 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003057 return true;
3058
John McCall828bff22009-10-29 18:45:58 +00003059 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003061
3062 TemplateArgument *TransformedArgsPtr
3063 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3064 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3065 TransformedArgsPtr);
3066 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3067 TransformedArgs.size()),
3068 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003069 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003070 }
3071 }
Mike Stump1eb44332009-09-09 15:08:12 +00003072
Douglas Gregor670444e2009-08-04 22:27:00 +00003073 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003074 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003075}
3076
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003077/// \brief Iterator adaptor that invents template argument location information
3078/// for each of the template arguments in its underlying iterator.
3079template<typename Derived, typename InputIterator>
3080class TemplateArgumentLocInventIterator {
3081 TreeTransform<Derived> &Self;
3082 InputIterator Iter;
3083
3084public:
3085 typedef TemplateArgumentLoc value_type;
3086 typedef TemplateArgumentLoc reference;
3087 typedef typename std::iterator_traits<InputIterator>::difference_type
3088 difference_type;
3089 typedef std::input_iterator_tag iterator_category;
3090
3091 class pointer {
3092 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003093
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094 public:
3095 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3096
3097 const TemplateArgumentLoc *operator->() const { return &Arg; }
3098 };
3099
3100 TemplateArgumentLocInventIterator() { }
3101
3102 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3103 InputIterator Iter)
3104 : Self(Self), Iter(Iter) { }
3105
3106 TemplateArgumentLocInventIterator &operator++() {
3107 ++Iter;
3108 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003109 }
3110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 TemplateArgumentLocInventIterator operator++(int) {
3112 TemplateArgumentLocInventIterator Old(*this);
3113 ++(*this);
3114 return Old;
3115 }
3116
3117 reference operator*() const {
3118 TemplateArgumentLoc Result;
3119 Self.InventTemplateArgumentLoc(*Iter, Result);
3120 return Result;
3121 }
3122
3123 pointer operator->() const { return pointer(**this); }
3124
3125 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3126 const TemplateArgumentLocInventIterator &Y) {
3127 return X.Iter == Y.Iter;
3128 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3131 const TemplateArgumentLocInventIterator &Y) {
3132 return X.Iter != Y.Iter;
3133 }
3134};
3135
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003136template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137template<typename InputIterator>
3138bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3139 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003140 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003142 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003144
3145 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3146 // Unpack argument packs, which we translate them into separate
3147 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003148 // FIXME: We could do much better if we could guarantee that the
3149 // TemplateArgumentLocInfo for the pack expansion would be usable for
3150 // all of the template arguments in the argument pack.
3151 typedef TemplateArgumentLocInventIterator<Derived,
3152 TemplateArgument::pack_iterator>
3153 PackLocIterator;
3154 if (TransformTemplateArguments(PackLocIterator(*this,
3155 In.getArgument().pack_begin()),
3156 PackLocIterator(*this,
3157 In.getArgument().pack_end()),
3158 Outputs))
3159 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003160
3161 continue;
3162 }
3163
3164 if (In.getArgument().isPackExpansion()) {
3165 // We have a pack expansion, for which we will be substituting into
3166 // the pattern.
3167 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003168 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003170 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3171 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003172
Chris Lattner686775d2011-07-20 06:58:45 +00003173 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3175 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3176
3177 // Determine whether the set of unexpanded parameter packs can and should
3178 // be expanded.
3179 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003180 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003181 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 if (getDerived().TryExpandParameterPacks(Ellipsis,
3183 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003184 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003185 Expand,
3186 RetainExpansion,
3187 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 return true;
3189
3190 if (!Expand) {
3191 // The transform has determined that we should perform a simple
3192 // transformation on the pack expansion, producing another pack
3193 // expansion.
3194 TemplateArgumentLoc OutPattern;
3195 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3196 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3197 return true;
3198
Douglas Gregorcded4f62011-01-14 17:04:44 +00003199 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3200 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003201 if (Out.getArgument().isNull())
3202 return true;
3203
3204 Outputs.addArgument(Out);
3205 continue;
3206 }
3207
3208 // The transform has determined that we should perform an elementwise
3209 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003210 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3212
3213 if (getDerived().TransformTemplateArgument(Pattern, Out))
3214 return true;
3215
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003216 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003217 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3218 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003219 if (Out.getArgument().isNull())
3220 return true;
3221 }
3222
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 Outputs.addArgument(Out);
3224 }
3225
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003226 // If we're supposed to retain a pack expansion, do so by temporarily
3227 // forgetting the partially-substituted parameter pack.
3228 if (RetainExpansion) {
3229 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3230
3231 if (getDerived().TransformTemplateArgument(Pattern, Out))
3232 return true;
3233
Douglas Gregorcded4f62011-01-14 17:04:44 +00003234 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3235 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003236 if (Out.getArgument().isNull())
3237 return true;
3238
3239 Outputs.addArgument(Out);
3240 }
Douglas Gregord3731192011-01-10 07:32:04 +00003241
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003242 continue;
3243 }
3244
3245 // The simple case:
3246 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003247 return true;
3248
3249 Outputs.addArgument(Out);
3250 }
3251
3252 return false;
3253
3254}
3255
Douglas Gregor577f75a2009-08-04 16:50:30 +00003256//===----------------------------------------------------------------------===//
3257// Type transformation
3258//===----------------------------------------------------------------------===//
3259
3260template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003261QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003262 if (getDerived().AlreadyTransformed(T))
3263 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003264
John McCalla2becad2009-10-21 00:40:46 +00003265 // Temporary workaround. All of these transformations should
3266 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003267 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3268 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003269
John McCall43fed0d2010-11-12 08:19:04 +00003270 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003271
John McCalla2becad2009-10-21 00:40:46 +00003272 if (!NewDI)
3273 return QualType();
3274
3275 return NewDI->getType();
3276}
3277
3278template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003279TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003280 // Refine the base location to the type's location.
3281 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3282 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003283 if (getDerived().AlreadyTransformed(DI->getType()))
3284 return DI;
3285
3286 TypeLocBuilder TLB;
3287
3288 TypeLoc TL = DI->getTypeLoc();
3289 TLB.reserve(TL.getFullDataSize());
3290
John McCall43fed0d2010-11-12 08:19:04 +00003291 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003292 if (Result.isNull())
3293 return 0;
3294
John McCalla93c9342009-12-07 02:54:59 +00003295 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003296}
3297
3298template<typename Derived>
3299QualType
John McCall43fed0d2010-11-12 08:19:04 +00003300TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003301 switch (T.getTypeLocClass()) {
3302#define ABSTRACT_TYPELOC(CLASS, PARENT)
3303#define TYPELOC(CLASS, PARENT) \
3304 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003305 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003306#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003307 }
Mike Stump1eb44332009-09-09 15:08:12 +00003308
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003309 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003310}
3311
3312/// FIXME: By default, this routine adds type qualifiers only to types
3313/// that can have qualifiers, and silently suppresses those qualifiers
3314/// that are not permitted (e.g., qualifiers on reference or function
3315/// types). This is the right thing for template instantiation, but
3316/// probably not for other clients.
3317template<typename Derived>
3318QualType
3319TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003320 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003321 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003322
John McCall43fed0d2010-11-12 08:19:04 +00003323 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003324 if (Result.isNull())
3325 return QualType();
3326
3327 // Silently suppress qualifiers if the result type can't be qualified.
3328 // FIXME: this is the right thing for template instantiation, but
3329 // probably not for other clients.
3330 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003331 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003332
John McCallf85e1932011-06-15 23:02:42 +00003333 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003334 // resulting type.
3335 if (Quals.hasObjCLifetime()) {
3336 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3337 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003338 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003339 // Objective-C ARC:
3340 // A lifetime qualifier applied to a substituted template parameter
3341 // overrides the lifetime qualifier from the template argument.
3342 if (const SubstTemplateTypeParmType *SubstTypeParam
3343 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3344 QualType Replacement = SubstTypeParam->getReplacementType();
3345 Qualifiers Qs = Replacement.getQualifiers();
3346 Qs.removeObjCLifetime();
3347 Replacement
3348 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3349 Qs);
3350 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3351 SubstTypeParam->getReplacedParameter(),
3352 Replacement);
3353 TLB.TypeWasModifiedSafely(Result);
3354 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003355 // Otherwise, complain about the addition of a qualifier to an
3356 // already-qualified type.
3357 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003358 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003359 << Result << R;
3360
Douglas Gregore559ca12011-06-17 22:11:49 +00003361 Quals.removeObjCLifetime();
3362 }
3363 }
3364 }
John McCall28654742010-06-05 06:41:15 +00003365 if (!Quals.empty()) {
3366 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3367 TLB.push<QualifiedTypeLoc>(Result);
3368 // No location information to preserve.
3369 }
John McCalla2becad2009-10-21 00:40:46 +00003370
3371 return Result;
3372}
3373
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003374template<typename Derived>
3375TypeLoc
3376TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3377 QualType ObjectType,
3378 NamedDecl *UnqualLookup,
3379 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003380 QualType T = TL.getType();
3381 if (getDerived().AlreadyTransformed(T))
3382 return TL;
3383
3384 TypeLocBuilder TLB;
3385 QualType Result;
3386
3387 if (isa<TemplateSpecializationType>(T)) {
3388 TemplateSpecializationTypeLoc SpecTL
3389 = cast<TemplateSpecializationTypeLoc>(TL);
3390
3391 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003392 getDerived().TransformTemplateName(SS,
3393 SpecTL.getTypePtr()->getTemplateName(),
3394 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003395 ObjectType, UnqualLookup);
3396 if (Template.isNull())
3397 return TypeLoc();
3398
3399 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3400 Template);
3401 } else if (isa<DependentTemplateSpecializationType>(T)) {
3402 DependentTemplateSpecializationTypeLoc SpecTL
3403 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3404
Douglas Gregora88f09f2011-02-28 17:23:35 +00003405 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003406 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003407 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003408 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003409 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003410 if (Template.isNull())
3411 return TypeLoc();
3412
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003413 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003414 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003415 Template,
3416 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003417 } else {
3418 // Nothing special needs to be done for these.
3419 Result = getDerived().TransformType(TLB, TL);
3420 }
3421
3422 if (Result.isNull())
3423 return TypeLoc();
3424
3425 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3426}
3427
Douglas Gregorb71d8212011-03-02 18:32:08 +00003428template<typename Derived>
3429TypeSourceInfo *
3430TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3431 QualType ObjectType,
3432 NamedDecl *UnqualLookup,
3433 CXXScopeSpec &SS) {
3434 // FIXME: Painfully copy-paste from the above!
3435
3436 QualType T = TSInfo->getType();
3437 if (getDerived().AlreadyTransformed(T))
3438 return TSInfo;
3439
3440 TypeLocBuilder TLB;
3441 QualType Result;
3442
3443 TypeLoc TL = TSInfo->getTypeLoc();
3444 if (isa<TemplateSpecializationType>(T)) {
3445 TemplateSpecializationTypeLoc SpecTL
3446 = cast<TemplateSpecializationTypeLoc>(TL);
3447
3448 TemplateName Template
3449 = getDerived().TransformTemplateName(SS,
3450 SpecTL.getTypePtr()->getTemplateName(),
3451 SpecTL.getTemplateNameLoc(),
3452 ObjectType, UnqualLookup);
3453 if (Template.isNull())
3454 return 0;
3455
3456 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3457 Template);
3458 } else if (isa<DependentTemplateSpecializationType>(T)) {
3459 DependentTemplateSpecializationTypeLoc SpecTL
3460 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3461
3462 TemplateName Template
3463 = getDerived().RebuildTemplateName(SS,
3464 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003465 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 ObjectType, UnqualLookup);
3467 if (Template.isNull())
3468 return 0;
3469
3470 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3471 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003472 Template,
3473 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 } else {
3475 // Nothing special needs to be done for these.
3476 Result = getDerived().TransformType(TLB, TL);
3477 }
3478
3479 if (Result.isNull())
3480 return 0;
3481
3482 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3483}
3484
John McCalla2becad2009-10-21 00:40:46 +00003485template <class TyLoc> static inline
3486QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3487 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3488 NewT.setNameLoc(T.getNameLoc());
3489 return T.getType();
3490}
3491
John McCalla2becad2009-10-21 00:40:46 +00003492template<typename Derived>
3493QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003494 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003495 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3496 NewT.setBuiltinLoc(T.getBuiltinLoc());
3497 if (T.needsExtraLocalData())
3498 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3499 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003500}
Mike Stump1eb44332009-09-09 15:08:12 +00003501
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003503QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003504 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003505 // FIXME: recurse?
3506 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003507}
Mike Stump1eb44332009-09-09 15:08:12 +00003508
Douglas Gregor577f75a2009-08-04 16:50:30 +00003509template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003510QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003511 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003512 QualType PointeeType
3513 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003514 if (PointeeType.isNull())
3515 return QualType();
3516
3517 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003518 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003519 // A dependent pointer type 'T *' has is being transformed such
3520 // that an Objective-C class type is being replaced for 'T'. The
3521 // resulting pointer type is an ObjCObjectPointerType, not a
3522 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003523 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003524
John McCallc12c5bb2010-05-15 11:32:37 +00003525 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3526 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 return Result;
3528 }
John McCall43fed0d2010-11-12 08:19:04 +00003529
Douglas Gregor92e986e2010-04-22 16:44:27 +00003530 if (getDerived().AlwaysRebuild() ||
3531 PointeeType != TL.getPointeeLoc().getType()) {
3532 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3533 if (Result.isNull())
3534 return QualType();
3535 }
John McCallf85e1932011-06-15 23:02:42 +00003536
3537 // Objective-C ARC can add lifetime qualifiers to the type that we're
3538 // pointing to.
3539 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3540
Douglas Gregor92e986e2010-04-22 16:44:27 +00003541 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3542 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003543 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544}
Mike Stump1eb44332009-09-09 15:08:12 +00003545
3546template<typename Derived>
3547QualType
John McCalla2becad2009-10-21 00:40:46 +00003548TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003549 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003550 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003551 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3552 if (PointeeType.isNull())
3553 return QualType();
3554
3555 QualType Result = TL.getType();
3556 if (getDerived().AlwaysRebuild() ||
3557 PointeeType != TL.getPointeeLoc().getType()) {
3558 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003559 TL.getSigilLoc());
3560 if (Result.isNull())
3561 return QualType();
3562 }
3563
Douglas Gregor39968ad2010-04-22 16:50:51 +00003564 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003565 NewT.setSigilLoc(TL.getSigilLoc());
3566 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003567}
3568
John McCall85737a72009-10-30 00:06:24 +00003569/// Transforms a reference type. Note that somewhat paradoxically we
3570/// don't care whether the type itself is an l-value type or an r-value
3571/// type; we only care if the type was *written* as an l-value type
3572/// or an r-value type.
3573template<typename Derived>
3574QualType
3575TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003576 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003577 const ReferenceType *T = TL.getTypePtr();
3578
3579 // Note that this works with the pointee-as-written.
3580 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3581 if (PointeeType.isNull())
3582 return QualType();
3583
3584 QualType Result = TL.getType();
3585 if (getDerived().AlwaysRebuild() ||
3586 PointeeType != T->getPointeeTypeAsWritten()) {
3587 Result = getDerived().RebuildReferenceType(PointeeType,
3588 T->isSpelledAsLValue(),
3589 TL.getSigilLoc());
3590 if (Result.isNull())
3591 return QualType();
3592 }
3593
John McCallf85e1932011-06-15 23:02:42 +00003594 // Objective-C ARC can add lifetime qualifiers to the type that we're
3595 // referring to.
3596 TLB.TypeWasModifiedSafely(
3597 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3598
John McCall85737a72009-10-30 00:06:24 +00003599 // r-value references can be rebuilt as l-value references.
3600 ReferenceTypeLoc NewTL;
3601 if (isa<LValueReferenceType>(Result))
3602 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3603 else
3604 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3605 NewTL.setSigilLoc(TL.getSigilLoc());
3606
3607 return Result;
3608}
3609
Mike Stump1eb44332009-09-09 15:08:12 +00003610template<typename Derived>
3611QualType
John McCalla2becad2009-10-21 00:40:46 +00003612TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003613 LValueReferenceTypeLoc TL) {
3614 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003615}
3616
Mike Stump1eb44332009-09-09 15:08:12 +00003617template<typename Derived>
3618QualType
John McCalla2becad2009-10-21 00:40:46 +00003619TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003620 RValueReferenceTypeLoc TL) {
3621 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003622}
Mike Stump1eb44332009-09-09 15:08:12 +00003623
Douglas Gregor577f75a2009-08-04 16:50:30 +00003624template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003625QualType
John McCalla2becad2009-10-21 00:40:46 +00003626TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003627 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003628 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629 if (PointeeType.isNull())
3630 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003631
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003632 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3633 TypeSourceInfo* NewClsTInfo = 0;
3634 if (OldClsTInfo) {
3635 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3636 if (!NewClsTInfo)
3637 return QualType();
3638 }
3639
3640 const MemberPointerType *T = TL.getTypePtr();
3641 QualType OldClsType = QualType(T->getClass(), 0);
3642 QualType NewClsType;
3643 if (NewClsTInfo)
3644 NewClsType = NewClsTInfo->getType();
3645 else {
3646 NewClsType = getDerived().TransformType(OldClsType);
3647 if (NewClsType.isNull())
3648 return QualType();
3649 }
Mike Stump1eb44332009-09-09 15:08:12 +00003650
John McCalla2becad2009-10-21 00:40:46 +00003651 QualType Result = TL.getType();
3652 if (getDerived().AlwaysRebuild() ||
3653 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003654 NewClsType != OldClsType) {
3655 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003656 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003657 if (Result.isNull())
3658 return QualType();
3659 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3662 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003663 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003664
3665 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003666}
3667
Mike Stump1eb44332009-09-09 15:08:12 +00003668template<typename Derived>
3669QualType
John McCalla2becad2009-10-21 00:40:46 +00003670TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003672 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674 if (ElementType.isNull())
3675 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 ElementType != T->getElementType()) {
3680 Result = getDerived().RebuildConstantArrayType(ElementType,
3681 T->getSizeModifier(),
3682 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003683 T->getIndexTypeCVRQualifiers(),
3684 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003685 if (Result.isNull())
3686 return QualType();
3687 }
Eli Friedman457a3772012-01-25 22:19:07 +00003688
3689 // We might have either a ConstantArrayType or a VariableArrayType now:
3690 // a ConstantArrayType is allowed to have an element type which is a
3691 // VariableArrayType if the type is dependent. Fortunately, all array
3692 // types have the same location layout.
3693 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003694 NewTL.setLBracketLoc(TL.getLBracketLoc());
3695 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003696
John McCalla2becad2009-10-21 00:40:46 +00003697 Expr *Size = TL.getSizeExpr();
3698 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003699 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3700 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003701 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003702 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003703 }
3704 NewTL.setSizeExpr(Size);
3705
3706 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707}
Mike Stump1eb44332009-09-09 15:08:12 +00003708
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003713 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003714 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715 if (ElementType.isNull())
3716 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003717
John McCalla2becad2009-10-21 00:40:46 +00003718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType()) {
3721 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003723 T->getIndexTypeCVRQualifiers(),
3724 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003725 if (Result.isNull())
3726 return QualType();
3727 }
Sean Huntc3021132010-05-05 15:23:54 +00003728
John McCalla2becad2009-10-21 00:40:46 +00003729 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3730 NewTL.setLBracketLoc(TL.getLBracketLoc());
3731 NewTL.setRBracketLoc(TL.getRBracketLoc());
3732 NewTL.setSizeExpr(0);
3733
3734 return Result;
3735}
3736
3737template<typename Derived>
3738QualType
3739TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003740 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003741 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003742 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3743 if (ElementType.isNull())
3744 return QualType();
3745
John McCall60d7b3a2010-08-24 06:29:42 +00003746 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003747 = getDerived().TransformExpr(T->getSizeExpr());
3748 if (SizeResult.isInvalid())
3749 return QualType();
3750
John McCall9ae2f072010-08-23 23:25:46 +00003751 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003752
3753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType() ||
3756 Size != T->getSizeExpr()) {
3757 Result = getDerived().RebuildVariableArrayType(ElementType,
3758 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003759 Size,
John McCalla2becad2009-10-21 00:40:46 +00003760 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003761 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003762 if (Result.isNull())
3763 return QualType();
3764 }
Sean Huntc3021132010-05-05 15:23:54 +00003765
John McCalla2becad2009-10-21 00:40:46 +00003766 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3767 NewTL.setLBracketLoc(TL.getLBracketLoc());
3768 NewTL.setRBracketLoc(TL.getRBracketLoc());
3769 NewTL.setSizeExpr(Size);
3770
3771 return Result;
3772}
3773
3774template<typename Derived>
3775QualType
3776TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003777 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003778 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003779 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3780 if (ElementType.isNull())
3781 return QualType();
3782
Richard Smithf6702a32011-12-20 02:08:33 +00003783 // Array bounds are constant expressions.
3784 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3785 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003786
John McCall3b657512011-01-19 10:06:00 +00003787 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3788 Expr *origSize = TL.getSizeExpr();
3789 if (!origSize) origSize = T->getSizeExpr();
3790
3791 ExprResult sizeResult
3792 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003793 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003794 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003795 return QualType();
3796
John McCall3b657512011-01-19 10:06:00 +00003797 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003798
3799 QualType Result = TL.getType();
3800 if (getDerived().AlwaysRebuild() ||
3801 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003802 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003803 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3804 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003805 size,
John McCalla2becad2009-10-21 00:40:46 +00003806 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003807 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003808 if (Result.isNull())
3809 return QualType();
3810 }
John McCalla2becad2009-10-21 00:40:46 +00003811
3812 // We might have any sort of array type now, but fortunately they
3813 // all have the same location layout.
3814 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3815 NewTL.setLBracketLoc(TL.getLBracketLoc());
3816 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003817 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003818
3819 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003820}
Mike Stump1eb44332009-09-09 15:08:12 +00003821
3822template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003824 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003825 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003826 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829 QualType ElementType = getDerived().TransformType(T->getElementType());
3830 if (ElementType.isNull())
3831 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003832
Richard Smithf6702a32011-12-20 02:08:33 +00003833 // Vector sizes are constant expressions.
3834 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3835 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003836
John McCall60d7b3a2010-08-24 06:29:42 +00003837 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003838 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 if (Size.isInvalid())
3840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
John McCalla2becad2009-10-21 00:40:46 +00003842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003844 ElementType != T->getElementType() ||
3845 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003846 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003847 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003848 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003849 if (Result.isNull())
3850 return QualType();
3851 }
John McCalla2becad2009-10-21 00:40:46 +00003852
3853 // Result might be dependent or not.
3854 if (isa<DependentSizedExtVectorType>(Result)) {
3855 DependentSizedExtVectorTypeLoc NewTL
3856 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3857 NewTL.setNameLoc(TL.getNameLoc());
3858 } else {
3859 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3860 NewTL.setNameLoc(TL.getNameLoc());
3861 }
3862
3863 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864}
Mike Stump1eb44332009-09-09 15:08:12 +00003865
3866template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003867QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003868 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003869 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003870 QualType ElementType = getDerived().TransformType(T->getElementType());
3871 if (ElementType.isNull())
3872 return QualType();
3873
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
3876 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003877 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003878 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003879 if (Result.isNull())
3880 return QualType();
3881 }
Sean Huntc3021132010-05-05 15:23:54 +00003882
John McCalla2becad2009-10-21 00:40:46 +00003883 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3884 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003885
John McCalla2becad2009-10-21 00:40:46 +00003886 return Result;
3887}
3888
3889template<typename Derived>
3890QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003891 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003892 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003893 QualType ElementType = getDerived().TransformType(T->getElementType());
3894 if (ElementType.isNull())
3895 return QualType();
3896
3897 QualType Result = TL.getType();
3898 if (getDerived().AlwaysRebuild() ||
3899 ElementType != T->getElementType()) {
3900 Result = getDerived().RebuildExtVectorType(ElementType,
3901 T->getNumElements(),
3902 /*FIXME*/ SourceLocation());
3903 if (Result.isNull())
3904 return QualType();
3905 }
Sean Huntc3021132010-05-05 15:23:54 +00003906
John McCalla2becad2009-10-21 00:40:46 +00003907 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3908 NewTL.setNameLoc(TL.getNameLoc());
3909
3910 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911}
Mike Stump1eb44332009-09-09 15:08:12 +00003912
3913template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003914ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003916 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003917 llvm::Optional<unsigned> NumExpansions,
3918 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003919 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003920 TypeSourceInfo *NewDI = 0;
3921
3922 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3923 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003924 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003925 TypeLoc OldTL = OldDI->getTypeLoc();
3926 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3927
3928 TypeLocBuilder TLB;
3929 TypeLoc NewTL = OldDI->getTypeLoc();
3930 TLB.reserve(NewTL.getFullDataSize());
3931
3932 QualType Result = getDerived().TransformType(TLB,
3933 OldExpansionTL.getPatternLoc());
3934 if (Result.isNull())
3935 return 0;
3936
3937 Result = RebuildPackExpansionType(Result,
3938 OldExpansionTL.getPatternLoc().getSourceRange(),
3939 OldExpansionTL.getEllipsisLoc(),
3940 NumExpansions);
3941 if (Result.isNull())
3942 return 0;
3943
3944 PackExpansionTypeLoc NewExpansionTL
3945 = TLB.push<PackExpansionTypeLoc>(Result);
3946 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3947 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3948 } else
3949 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003950 if (!NewDI)
3951 return 0;
3952
John McCallfb44de92011-05-01 22:35:37 +00003953 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003954 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003955
3956 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3957 OldParm->getDeclContext(),
3958 OldParm->getInnerLocStart(),
3959 OldParm->getLocation(),
3960 OldParm->getIdentifier(),
3961 NewDI->getType(),
3962 NewDI,
3963 OldParm->getStorageClass(),
3964 OldParm->getStorageClassAsWritten(),
3965 /* DefArg */ NULL);
3966 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3967 OldParm->getFunctionScopeIndex() + indexAdjustment);
3968 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003969}
3970
3971template<typename Derived>
3972bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003973 TransformFunctionTypeParams(SourceLocation Loc,
3974 ParmVarDecl **Params, unsigned NumParams,
3975 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003976 SmallVectorImpl<QualType> &OutParamTypes,
3977 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003978 int indexAdjustment = 0;
3979
Douglas Gregora009b592011-01-07 00:20:55 +00003980 for (unsigned i = 0; i != NumParams; ++i) {
3981 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003982 assert(OldParm->getFunctionScopeIndex() == i);
3983
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003984 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003985 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003986 if (OldParm->isParameterPack()) {
3987 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003988 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003989
Douglas Gregor603cfb42011-01-05 23:12:31 +00003990 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003991 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3992 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3993 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3994 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003995 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3996
Douglas Gregor603cfb42011-01-05 23:12:31 +00003997 // Determine whether we should expand the parameter packs.
3998 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003999 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004000 llvm::Optional<unsigned> OrigNumExpansions
4001 = ExpansionTL.getTypePtr()->getNumExpansions();
4002 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004003 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4004 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004005 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004006 ShouldExpand,
4007 RetainExpansion,
4008 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004009 return true;
4010 }
4011
4012 if (ShouldExpand) {
4013 // Expand the function parameter pack into multiple, separate
4014 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004015 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004016 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004017 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4018 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004019 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004020 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004021 OrigNumExpansions,
4022 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 if (!NewParm)
4024 return true;
4025
Douglas Gregora009b592011-01-07 00:20:55 +00004026 OutParamTypes.push_back(NewParm->getType());
4027 if (PVars)
4028 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004029 }
Douglas Gregord3731192011-01-10 07:32:04 +00004030
4031 // If we're supposed to retain a pack expansion, do so by temporarily
4032 // forgetting the partially-substituted parameter pack.
4033 if (RetainExpansion) {
4034 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4035 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004036 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004037 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004038 OrigNumExpansions,
4039 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004040 if (!NewParm)
4041 return true;
4042
4043 OutParamTypes.push_back(NewParm->getType());
4044 if (PVars)
4045 PVars->push_back(NewParm);
4046 }
4047
John McCallfb44de92011-05-01 22:35:37 +00004048 // The next parameter should have the same adjustment as the
4049 // last thing we pushed, but we post-incremented indexAdjustment
4050 // on every push. Also, if we push nothing, the adjustment should
4051 // go down by one.
4052 indexAdjustment--;
4053
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // We're done with the pack expansion.
4055 continue;
4056 }
4057
4058 // We'll substitute the parameter now without expanding the pack
4059 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004060 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4061 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004062 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004063 NumExpansions,
4064 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004065 } else {
4066 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004067 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004068 llvm::Optional<unsigned>(),
4069 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071
John McCall21ef0fa2010-03-11 09:03:00 +00004072 if (!NewParm)
4073 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004074
Douglas Gregora009b592011-01-07 00:20:55 +00004075 OutParamTypes.push_back(NewParm->getType());
4076 if (PVars)
4077 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 continue;
4079 }
John McCall21ef0fa2010-03-11 09:03:00 +00004080
4081 // Deal with the possibility that we don't have a parameter
4082 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004083 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004084 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004085 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004086 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 if (const PackExpansionType *Expansion
4088 = dyn_cast<PackExpansionType>(OldType)) {
4089 // We have a function parameter pack that may need to be expanded.
4090 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004091 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4093
4094 // Determine whether we should expand the parameter packs.
4095 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004096 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004097 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004098 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004099 ShouldExpand,
4100 RetainExpansion,
4101 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004102 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 }
4104
4105 if (ShouldExpand) {
4106 // Expand the function parameter pack into multiple, separate
4107 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004108 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004109 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4110 QualType NewType = getDerived().TransformType(Pattern);
4111 if (NewType.isNull())
4112 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004113
Douglas Gregora009b592011-01-07 00:20:55 +00004114 OutParamTypes.push_back(NewType);
4115 if (PVars)
4116 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 }
4118
4119 // We're done with the pack expansion.
4120 continue;
4121 }
4122
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004123 // If we're supposed to retain a pack expansion, do so by temporarily
4124 // forgetting the partially-substituted parameter pack.
4125 if (RetainExpansion) {
4126 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4127 QualType NewType = getDerived().TransformType(Pattern);
4128 if (NewType.isNull())
4129 return true;
4130
4131 OutParamTypes.push_back(NewType);
4132 if (PVars)
4133 PVars->push_back(0);
4134 }
Douglas Gregord3731192011-01-10 07:32:04 +00004135
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 // We'll substitute the parameter now without expanding the pack
4137 // expansion.
4138 OldType = Expansion->getPattern();
4139 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4141 NewType = getDerived().TransformType(OldType);
4142 } else {
4143 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004144 }
4145
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 if (NewType.isNull())
4147 return true;
4148
4149 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004150 NewType = getSema().Context.getPackExpansionType(NewType,
4151 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152
Douglas Gregora009b592011-01-07 00:20:55 +00004153 OutParamTypes.push_back(NewType);
4154 if (PVars)
4155 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004156 }
4157
John McCallfb44de92011-05-01 22:35:37 +00004158#ifndef NDEBUG
4159 if (PVars) {
4160 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4161 if (ParmVarDecl *parm = (*PVars)[i])
4162 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 }
John McCallfb44de92011-05-01 22:35:37 +00004164#endif
4165
4166 return false;
4167}
John McCall21ef0fa2010-03-11 09:03:00 +00004168
4169template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004170QualType
John McCalla2becad2009-10-21 00:40:46 +00004171TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004172 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004173 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4174}
4175
4176template<typename Derived>
4177QualType
4178TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4179 FunctionProtoTypeLoc TL,
4180 CXXRecordDecl *ThisContext,
4181 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004182 // Transform the parameters and return type.
4183 //
Richard Smithe6975e92012-04-17 00:58:00 +00004184 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004185 // When the function has a trailing return type, we instantiate the
4186 // parameters before the return type, since the return type can then refer
4187 // to the parameters themselves (via decltype, sizeof, etc.).
4188 //
Chris Lattner686775d2011-07-20 06:58:45 +00004189 SmallVector<QualType, 4> ParamTypes;
4190 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004191 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004192
Douglas Gregordab60ad2010-10-01 18:44:50 +00004193 QualType ResultType;
4194
4195 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004196 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4197 TL.getParmArray(),
4198 TL.getNumArgs(),
4199 TL.getTypePtr()->arg_type_begin(),
4200 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004201 return QualType();
4202
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004203 {
4204 // C++11 [expr.prim.general]p3:
4205 // If a declaration declares a member function or member function
4206 // template of a class X, the expression this is a prvalue of type
4207 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
4208 // and the end of the function-definition, member-declarator, or
4209 // declarator.
4210 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
4211
4212 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4213 if (ResultType.isNull())
4214 return QualType();
4215 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004216 }
4217 else {
4218 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4219 if (ResultType.isNull())
4220 return QualType();
4221
Douglas Gregora009b592011-01-07 00:20:55 +00004222 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4223 TL.getParmArray(),
4224 TL.getNumArgs(),
4225 TL.getTypePtr()->arg_type_begin(),
4226 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004227 return QualType();
4228 }
4229
Richard Smithe6975e92012-04-17 00:58:00 +00004230 // FIXME: Need to transform the exception-specification too.
4231
John McCalla2becad2009-10-21 00:40:46 +00004232 QualType Result = TL.getType();
4233 if (getDerived().AlwaysRebuild() ||
4234 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004235 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004236 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4237 Result = getDerived().RebuildFunctionProtoType(ResultType,
4238 ParamTypes.data(),
4239 ParamTypes.size(),
4240 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004241 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004242 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004243 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004244 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004245 if (Result.isNull())
4246 return QualType();
4247 }
Mike Stump1eb44332009-09-09 15:08:12 +00004248
John McCalla2becad2009-10-21 00:40:46 +00004249 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004250 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4251 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004252 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004253 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4254 NewTL.setArg(i, ParamDecls[i]);
4255
4256 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004257}
Mike Stump1eb44332009-09-09 15:08:12 +00004258
Douglas Gregor577f75a2009-08-04 16:50:30 +00004259template<typename Derived>
4260QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004261 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004262 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004263 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004264 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4265 if (ResultType.isNull())
4266 return QualType();
4267
4268 QualType Result = TL.getType();
4269 if (getDerived().AlwaysRebuild() ||
4270 ResultType != T->getResultType())
4271 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4272
4273 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004274 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4275 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004276 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004277
4278 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004279}
Mike Stump1eb44332009-09-09 15:08:12 +00004280
John McCalled976492009-12-04 22:46:56 +00004281template<typename Derived> QualType
4282TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004283 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004284 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004285 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004286 if (!D)
4287 return QualType();
4288
4289 QualType Result = TL.getType();
4290 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4291 Result = getDerived().RebuildUnresolvedUsingType(D);
4292 if (Result.isNull())
4293 return QualType();
4294 }
4295
4296 // We might get an arbitrary type spec type back. We should at
4297 // least always get a type spec type, though.
4298 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4299 NewTL.setNameLoc(TL.getNameLoc());
4300
4301 return Result;
4302}
4303
Douglas Gregor577f75a2009-08-04 16:50:30 +00004304template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004305QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004306 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004307 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004308 TypedefNameDecl *Typedef
4309 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4310 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004311 if (!Typedef)
4312 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004313
John McCalla2becad2009-10-21 00:40:46 +00004314 QualType Result = TL.getType();
4315 if (getDerived().AlwaysRebuild() ||
4316 Typedef != T->getDecl()) {
4317 Result = getDerived().RebuildTypedefType(Typedef);
4318 if (Result.isNull())
4319 return QualType();
4320 }
Mike Stump1eb44332009-09-09 15:08:12 +00004321
John McCalla2becad2009-10-21 00:40:46 +00004322 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4323 NewTL.setNameLoc(TL.getNameLoc());
4324
4325 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004326}
Mike Stump1eb44332009-09-09 15:08:12 +00004327
Douglas Gregor577f75a2009-08-04 16:50:30 +00004328template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004329QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004330 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004331 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004332 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004333
John McCall60d7b3a2010-08-24 06:29:42 +00004334 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335 if (E.isInvalid())
4336 return QualType();
4337
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004338 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4339 if (E.isInvalid())
4340 return QualType();
4341
John McCalla2becad2009-10-21 00:40:46 +00004342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004344 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004345 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004346 if (Result.isNull())
4347 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348 }
John McCalla2becad2009-10-21 00:40:46 +00004349 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004350
John McCalla2becad2009-10-21 00:40:46 +00004351 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004352 NewTL.setTypeofLoc(TL.getTypeofLoc());
4353 NewTL.setLParenLoc(TL.getLParenLoc());
4354 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004355
4356 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357}
Mike Stump1eb44332009-09-09 15:08:12 +00004358
4359template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004360QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004361 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004362 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4363 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4364 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004366
John McCalla2becad2009-10-21 00:40:46 +00004367 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004368 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4369 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004370 if (Result.isNull())
4371 return QualType();
4372 }
Mike Stump1eb44332009-09-09 15:08:12 +00004373
John McCalla2becad2009-10-21 00:40:46 +00004374 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004375 NewTL.setTypeofLoc(TL.getTypeofLoc());
4376 NewTL.setLParenLoc(TL.getLParenLoc());
4377 NewTL.setRParenLoc(TL.getRParenLoc());
4378 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004379
4380 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381}
Mike Stump1eb44332009-09-09 15:08:12 +00004382
4383template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004384QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004385 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004386 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004387
Douglas Gregor670444e2009-08-04 22:27:00 +00004388 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4390 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCall60d7b3a2010-08-24 06:29:42 +00004392 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004393 if (E.isInvalid())
4394 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004395
Richard Smith76f3f692012-02-22 02:04:18 +00004396 E = getSema().ActOnDecltypeExpression(E.take());
4397 if (E.isInvalid())
4398 return QualType();
4399
John McCalla2becad2009-10-21 00:40:46 +00004400 QualType Result = TL.getType();
4401 if (getDerived().AlwaysRebuild() ||
4402 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004403 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004404 if (Result.isNull())
4405 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 }
John McCalla2becad2009-10-21 00:40:46 +00004407 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004408
John McCalla2becad2009-10-21 00:40:46 +00004409 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4410 NewTL.setNameLoc(TL.getNameLoc());
4411
4412 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004413}
4414
4415template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004416QualType TreeTransform<Derived>::TransformUnaryTransformType(
4417 TypeLocBuilder &TLB,
4418 UnaryTransformTypeLoc TL) {
4419 QualType Result = TL.getType();
4420 if (Result->isDependentType()) {
4421 const UnaryTransformType *T = TL.getTypePtr();
4422 QualType NewBase =
4423 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4424 Result = getDerived().RebuildUnaryTransformType(NewBase,
4425 T->getUTTKind(),
4426 TL.getKWLoc());
4427 if (Result.isNull())
4428 return QualType();
4429 }
4430
4431 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4432 NewTL.setKWLoc(TL.getKWLoc());
4433 NewTL.setParensRange(TL.getParensRange());
4434 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4435 return Result;
4436}
4437
4438template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004439QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4440 AutoTypeLoc TL) {
4441 const AutoType *T = TL.getTypePtr();
4442 QualType OldDeduced = T->getDeducedType();
4443 QualType NewDeduced;
4444 if (!OldDeduced.isNull()) {
4445 NewDeduced = getDerived().TransformType(OldDeduced);
4446 if (NewDeduced.isNull())
4447 return QualType();
4448 }
4449
4450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4452 Result = getDerived().RebuildAutoType(NewDeduced);
4453 if (Result.isNull())
4454 return QualType();
4455 }
4456
4457 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4458 NewTL.setNameLoc(TL.getNameLoc());
4459
4460 return Result;
4461}
4462
4463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004464QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004465 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004466 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004467 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004468 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4469 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004470 if (!Record)
4471 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCalla2becad2009-10-21 00:40:46 +00004473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() ||
4475 Record != T->getDecl()) {
4476 Result = getDerived().RebuildRecordType(Record);
4477 if (Result.isNull())
4478 return QualType();
4479 }
Mike Stump1eb44332009-09-09 15:08:12 +00004480
John McCalla2becad2009-10-21 00:40:46 +00004481 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004485}
Mike Stump1eb44332009-09-09 15:08:12 +00004486
4487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004489 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004490 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004491 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004492 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4493 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 if (!Enum)
4495 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCalla2becad2009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Enum != T->getDecl()) {
4500 Result = getDerived().RebuildEnumType(Enum);
4501 if (Result.isNull())
4502 return QualType();
4503 }
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4507
4508 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004509}
John McCall7da24312009-09-05 00:15:47 +00004510
John McCall3cb0ebd2010-03-10 03:28:59 +00004511template<typename Derived>
4512QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4513 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004514 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004515 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4516 TL.getTypePtr()->getDecl());
4517 if (!D) return QualType();
4518
4519 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4520 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4521 return T;
4522}
4523
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524template<typename Derived>
4525QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004526 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004527 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004528 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004529}
4530
Mike Stump1eb44332009-09-09 15:08:12 +00004531template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004532QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004533 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004534 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004535 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4536
4537 // Substitute into the replacement type, which itself might involve something
4538 // that needs to be transformed. This only tends to occur with default
4539 // template arguments of template template parameters.
4540 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4541 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4542 if (Replacement.isNull())
4543 return QualType();
4544
4545 // Always canonicalize the replacement type.
4546 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4547 QualType Result
4548 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4549 Replacement);
4550
4551 // Propagate type-source information.
4552 SubstTemplateTypeParmTypeLoc NewTL
4553 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4554 NewTL.setNameLoc(TL.getNameLoc());
4555 return Result;
4556
John McCall49a832b2009-10-18 09:09:24 +00004557}
4558
4559template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004560QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4561 TypeLocBuilder &TLB,
4562 SubstTemplateTypeParmPackTypeLoc TL) {
4563 return TransformTypeSpecType(TLB, TL);
4564}
4565
4566template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004567QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004568 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004569 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004570 const TemplateSpecializationType *T = TL.getTypePtr();
4571
Douglas Gregor1d752d72011-03-02 18:46:51 +00004572 // The nested-name-specifier never matters in a TemplateSpecializationType,
4573 // because we can't have a dependent nested-name-specifier anyway.
4574 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004575 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004576 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4577 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004578 if (Template.isNull())
4579 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004580
John McCall43fed0d2010-11-12 08:19:04 +00004581 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4582}
4583
Eli Friedmanb001de72011-10-06 23:00:33 +00004584template<typename Derived>
4585QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4586 AtomicTypeLoc TL) {
4587 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4588 if (ValueType.isNull())
4589 return QualType();
4590
4591 QualType Result = TL.getType();
4592 if (getDerived().AlwaysRebuild() ||
4593 ValueType != TL.getValueLoc().getType()) {
4594 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4595 if (Result.isNull())
4596 return QualType();
4597 }
4598
4599 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4600 NewTL.setKWLoc(TL.getKWLoc());
4601 NewTL.setLParenLoc(TL.getLParenLoc());
4602 NewTL.setRParenLoc(TL.getRParenLoc());
4603
4604 return Result;
4605}
4606
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004607namespace {
4608 /// \brief Simple iterator that traverses the template arguments in a
4609 /// container that provides a \c getArgLoc() member function.
4610 ///
4611 /// This iterator is intended to be used with the iterator form of
4612 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4613 template<typename ArgLocContainer>
4614 class TemplateArgumentLocContainerIterator {
4615 ArgLocContainer *Container;
4616 unsigned Index;
4617
4618 public:
4619 typedef TemplateArgumentLoc value_type;
4620 typedef TemplateArgumentLoc reference;
4621 typedef int difference_type;
4622 typedef std::input_iterator_tag iterator_category;
4623
4624 class pointer {
4625 TemplateArgumentLoc Arg;
4626
4627 public:
4628 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4629
4630 const TemplateArgumentLoc *operator->() const {
4631 return &Arg;
4632 }
4633 };
4634
4635
4636 TemplateArgumentLocContainerIterator() {}
4637
4638 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4639 unsigned Index)
4640 : Container(&Container), Index(Index) { }
4641
4642 TemplateArgumentLocContainerIterator &operator++() {
4643 ++Index;
4644 return *this;
4645 }
4646
4647 TemplateArgumentLocContainerIterator operator++(int) {
4648 TemplateArgumentLocContainerIterator Old(*this);
4649 ++(*this);
4650 return Old;
4651 }
4652
4653 TemplateArgumentLoc operator*() const {
4654 return Container->getArgLoc(Index);
4655 }
4656
4657 pointer operator->() const {
4658 return pointer(Container->getArgLoc(Index));
4659 }
4660
4661 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004662 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004663 return X.Container == Y.Container && X.Index == Y.Index;
4664 }
4665
4666 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004667 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004668 return !(X == Y);
4669 }
4670 };
4671}
4672
4673
John McCall43fed0d2010-11-12 08:19:04 +00004674template <typename Derived>
4675QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4676 TypeLocBuilder &TLB,
4677 TemplateSpecializationTypeLoc TL,
4678 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004679 TemplateArgumentListInfo NewTemplateArgs;
4680 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4681 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4683 ArgIterator;
4684 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4685 ArgIterator(TL, TL.getNumArgs()),
4686 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004687 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004688
John McCall833ca992009-10-29 08:12:44 +00004689 // FIXME: maybe don't rebuild if all the template arguments are the same.
4690
4691 QualType Result =
4692 getDerived().RebuildTemplateSpecializationType(Template,
4693 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004694 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004695
4696 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004697 // Specializations of template template parameters are represented as
4698 // TemplateSpecializationTypes, and substitution of type alias templates
4699 // within a dependent context can transform them into
4700 // DependentTemplateSpecializationTypes.
4701 if (isa<DependentTemplateSpecializationType>(Result)) {
4702 DependentTemplateSpecializationTypeLoc NewTL
4703 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004704 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004705 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004706 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004707 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004708 NewTL.setLAngleLoc(TL.getLAngleLoc());
4709 NewTL.setRAngleLoc(TL.getRAngleLoc());
4710 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4711 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4712 return Result;
4713 }
4714
John McCall833ca992009-10-29 08:12:44 +00004715 TemplateSpecializationTypeLoc NewTL
4716 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004717 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004718 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4719 NewTL.setLAngleLoc(TL.getLAngleLoc());
4720 NewTL.setRAngleLoc(TL.getRAngleLoc());
4721 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4722 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004723 }
Mike Stump1eb44332009-09-09 15:08:12 +00004724
John McCall833ca992009-10-29 08:12:44 +00004725 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004726}
Mike Stump1eb44332009-09-09 15:08:12 +00004727
Douglas Gregora88f09f2011-02-28 17:23:35 +00004728template <typename Derived>
4729QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4730 TypeLocBuilder &TLB,
4731 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004732 TemplateName Template,
4733 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004734 TemplateArgumentListInfo NewTemplateArgs;
4735 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4736 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4737 typedef TemplateArgumentLocContainerIterator<
4738 DependentTemplateSpecializationTypeLoc> ArgIterator;
4739 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4740 ArgIterator(TL, TL.getNumArgs()),
4741 NewTemplateArgs))
4742 return QualType();
4743
4744 // FIXME: maybe don't rebuild if all the template arguments are the same.
4745
4746 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4747 QualType Result
4748 = getSema().Context.getDependentTemplateSpecializationType(
4749 TL.getTypePtr()->getKeyword(),
4750 DTN->getQualifier(),
4751 DTN->getIdentifier(),
4752 NewTemplateArgs);
4753
4754 DependentTemplateSpecializationTypeLoc NewTL
4755 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004756 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004757 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004758 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004759 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004760 NewTL.setLAngleLoc(TL.getLAngleLoc());
4761 NewTL.setRAngleLoc(TL.getRAngleLoc());
4762 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4763 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4764 return Result;
4765 }
4766
4767 QualType Result
4768 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004770 NewTemplateArgs);
4771
4772 if (!Result.isNull()) {
4773 /// FIXME: Wrap this in an elaborated-type-specifier?
4774 TemplateSpecializationTypeLoc NewTL
4775 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004776 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 NewTL.setLAngleLoc(TL.getLAngleLoc());
4779 NewTL.setRAngleLoc(TL.getRAngleLoc());
4780 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4781 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4782 }
4783
4784 return Result;
4785}
4786
Mike Stump1eb44332009-09-09 15:08:12 +00004787template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004788QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004789TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004790 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004791 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004792
Douglas Gregor9e876872011-03-01 18:12:44 +00004793 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004794 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004795 if (TL.getQualifierLoc()) {
4796 QualifierLoc
4797 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4798 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004799 return QualType();
4800 }
Mike Stump1eb44332009-09-09 15:08:12 +00004801
John McCall43fed0d2010-11-12 08:19:04 +00004802 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4803 if (NamedT.isNull())
4804 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004805
Richard Smith3e4c6c42011-05-05 21:57:07 +00004806 // C++0x [dcl.type.elab]p2:
4807 // If the identifier resolves to a typedef-name or the simple-template-id
4808 // resolves to an alias template specialization, the
4809 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004810 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4811 if (const TemplateSpecializationType *TST =
4812 NamedT->getAs<TemplateSpecializationType>()) {
4813 TemplateName Template = TST->getTemplateName();
4814 if (TypeAliasTemplateDecl *TAT =
4815 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4816 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4817 diag::err_tag_reference_non_tag) << 4;
4818 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4819 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004820 }
4821 }
4822
John McCalla2becad2009-10-21 00:40:46 +00004823 QualType Result = TL.getType();
4824 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004825 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004826 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004827 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004828 T->getKeyword(),
4829 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004830 if (Result.isNull())
4831 return QualType();
4832 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004833
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004834 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004835 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004836 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004837 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004838}
Mike Stump1eb44332009-09-09 15:08:12 +00004839
4840template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004841QualType TreeTransform<Derived>::TransformAttributedType(
4842 TypeLocBuilder &TLB,
4843 AttributedTypeLoc TL) {
4844 const AttributedType *oldType = TL.getTypePtr();
4845 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4846 if (modifiedType.isNull())
4847 return QualType();
4848
4849 QualType result = TL.getType();
4850
4851 // FIXME: dependent operand expressions?
4852 if (getDerived().AlwaysRebuild() ||
4853 modifiedType != oldType->getModifiedType()) {
4854 // TODO: this is really lame; we should really be rebuilding the
4855 // equivalent type from first principles.
4856 QualType equivalentType
4857 = getDerived().TransformType(oldType->getEquivalentType());
4858 if (equivalentType.isNull())
4859 return QualType();
4860 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4861 modifiedType,
4862 equivalentType);
4863 }
4864
4865 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4866 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4867 if (TL.hasAttrOperand())
4868 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4869 if (TL.hasAttrExprOperand())
4870 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4871 else if (TL.hasAttrEnumOperand())
4872 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4873
4874 return result;
4875}
4876
4877template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004878QualType
4879TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4880 ParenTypeLoc TL) {
4881 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4882 if (Inner.isNull())
4883 return QualType();
4884
4885 QualType Result = TL.getType();
4886 if (getDerived().AlwaysRebuild() ||
4887 Inner != TL.getInnerLoc().getType()) {
4888 Result = getDerived().RebuildParenType(Inner);
4889 if (Result.isNull())
4890 return QualType();
4891 }
4892
4893 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4894 NewTL.setLParenLoc(TL.getLParenLoc());
4895 NewTL.setRParenLoc(TL.getRParenLoc());
4896 return Result;
4897}
4898
4899template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004900QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004901 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004902 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004903
Douglas Gregor2494dd02011-03-01 01:34:45 +00004904 NestedNameSpecifierLoc QualifierLoc
4905 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4906 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004907 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004908
John McCall33500952010-06-11 00:33:02 +00004909 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004910 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004911 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004912 QualifierLoc,
4913 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004914 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004915 if (Result.isNull())
4916 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004917
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004918 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4919 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004920 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4921
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004922 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004923 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004924 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004925 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004926 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004927 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004928 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004929 NewTL.setNameLoc(TL.getNameLoc());
4930 }
John McCalla2becad2009-10-21 00:40:46 +00004931 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004932}
Mike Stump1eb44332009-09-09 15:08:12 +00004933
Douglas Gregor577f75a2009-08-04 16:50:30 +00004934template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004935QualType TreeTransform<Derived>::
4936 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004937 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004938 NestedNameSpecifierLoc QualifierLoc;
4939 if (TL.getQualifierLoc()) {
4940 QualifierLoc
4941 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4942 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004943 return QualType();
4944 }
4945
John McCall43fed0d2010-11-12 08:19:04 +00004946 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004947 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004948}
4949
4950template<typename Derived>
4951QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004952TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4953 DependentTemplateSpecializationTypeLoc TL,
4954 NestedNameSpecifierLoc QualifierLoc) {
4955 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4956
4957 TemplateArgumentListInfo NewTemplateArgs;
4958 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4959 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4960
4961 typedef TemplateArgumentLocContainerIterator<
4962 DependentTemplateSpecializationTypeLoc> ArgIterator;
4963 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4964 ArgIterator(TL, TL.getNumArgs()),
4965 NewTemplateArgs))
4966 return QualType();
4967
4968 QualType Result
4969 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4970 QualifierLoc,
4971 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004972 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004973 NewTemplateArgs);
4974 if (Result.isNull())
4975 return QualType();
4976
4977 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4978 QualType NamedT = ElabT->getNamedType();
4979
4980 // Copy information relevant to the template specialization.
4981 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004982 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004983 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004984 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004985 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4986 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004987 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004988 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004989
4990 // Copy information relevant to the elaborated type.
4991 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004992 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004994 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4995 DependentTemplateSpecializationTypeLoc SpecTL
4996 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004997 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004998 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004999 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005000 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005001 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5002 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005003 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005004 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005005 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 TemplateSpecializationTypeLoc SpecTL
5007 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005008 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005009 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005010 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5011 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005012 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 }
5015 return Result;
5016}
5017
5018template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005019QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5020 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005021 QualType Pattern
5022 = getDerived().TransformType(TLB, TL.getPatternLoc());
5023 if (Pattern.isNull())
5024 return QualType();
5025
5026 QualType Result = TL.getType();
5027 if (getDerived().AlwaysRebuild() ||
5028 Pattern != TL.getPatternLoc().getType()) {
5029 Result = getDerived().RebuildPackExpansionType(Pattern,
5030 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005031 TL.getEllipsisLoc(),
5032 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005033 if (Result.isNull())
5034 return QualType();
5035 }
5036
5037 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5038 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5039 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005040}
5041
5042template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005043QualType
5044TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005045 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005046 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005047 TLB.pushFullCopy(TL);
5048 return TL.getType();
5049}
5050
5051template<typename Derived>
5052QualType
5053TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005054 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005055 // ObjCObjectType is never dependent.
5056 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005057 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005058}
Mike Stump1eb44332009-09-09 15:08:12 +00005059
5060template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005061QualType
5062TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005063 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005064 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005065 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005066 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005067}
5068
Douglas Gregor577f75a2009-08-04 16:50:30 +00005069//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005070// Statement transformation
5071//===----------------------------------------------------------------------===//
5072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005073StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005074TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005075 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005076}
5077
5078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005079StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005080TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5081 return getDerived().TransformCompoundStmt(S, false);
5082}
5083
5084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005085StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005086TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005088 Sema::CompoundScopeRAII CompoundScope(getSema());
5089
John McCall7114cba2010-08-27 19:56:05 +00005090 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005092 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005093 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5094 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005095 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005096 if (Result.isInvalid()) {
5097 // Immediately fail if this was a DeclStmt, since it's very
5098 // likely that this will cause problems for future statements.
5099 if (isa<DeclStmt>(*B))
5100 return StmtError();
5101
5102 // Otherwise, just keep processing substatements and fail later.
5103 SubStmtInvalid = true;
5104 continue;
5105 }
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5108 Statements.push_back(Result.takeAs<Stmt>());
5109 }
Mike Stump1eb44332009-09-09 15:08:12 +00005110
John McCall7114cba2010-08-27 19:56:05 +00005111 if (SubStmtInvalid)
5112 return StmtError();
5113
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 if (!getDerived().AlwaysRebuild() &&
5115 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005116 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005117
5118 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5119 move_arg(Statements),
5120 S->getRBracLoc(),
5121 IsStmtExpr);
5122}
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005125StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005126TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005127 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005128 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005129 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5130 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Eli Friedman264c1f82009-11-19 03:14:00 +00005132 // Transform the left-hand case value.
5133 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005134 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005135 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005136 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Eli Friedman264c1f82009-11-19 03:14:00 +00005138 // Transform the right-hand case value (for the GNU case-range extension).
5139 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005140 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005141 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005142 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005143 }
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 // Build the case statement.
5146 // Case statements are always rebuilt so that they will attached to their
5147 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005148 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005149 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005151 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005152 S->getColonLoc());
5153 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005154 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005155
Douglas Gregor43959a92009-08-20 07:17:43 +00005156 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005157 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005162 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005163}
5164
5165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005166StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005167TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005169 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005172
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 // Default statements are always rebuilt
5174 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005175 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176}
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005181 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005183 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Chris Lattner57ad3782011-02-17 20:34:02 +00005185 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5186 S->getDecl());
5187 if (!LD)
5188 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005189
5190
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005192 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005193 cast<LabelDecl>(LD), SourceLocation(),
5194 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195}
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Douglas Gregor43959a92009-08-20 07:17:43 +00005197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005198StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005199TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5200 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5201 if (SubStmt.isInvalid())
5202 return StmtError();
5203
5204 // TODO: transform attributes
5205 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5206 return S;
5207
5208 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5209 S->getAttrs(),
5210 SubStmt.get());
5211}
5212
5213template<typename Derived>
5214StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005215TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005217 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005218 VarDecl *ConditionVar = 0;
5219 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005220 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005221 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005222 getDerived().TransformDefinition(
5223 S->getConditionVariable()->getLocation(),
5224 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005225 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005226 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005227 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005228 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005229
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005230 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005231 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005232
5233 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005234 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005235 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5236 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005237 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005239
John McCall9ae2f072010-08-23 23:25:46 +00005240 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005241 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005242 }
Sean Huntc3021132010-05-05 15:23:54 +00005243
John McCall9ae2f072010-08-23 23:25:46 +00005244 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5245 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005247
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005249 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005251 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005252
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005254 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005259 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005260 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 Then.get() == S->getThen() &&
5262 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005263 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005265 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005266 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005267 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005268}
5269
5270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005271StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005272TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005274 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005275 VarDecl *ConditionVar = 0;
5276 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005277 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005278 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005279 getDerived().TransformDefinition(
5280 S->getConditionVariable()->getLocation(),
5281 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005282 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005283 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005284 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005285 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005286
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005287 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005288 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005289 }
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005292 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005293 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005294 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 if (Switch.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 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005299 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005304 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5305 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
Mike Stump1eb44332009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005312 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005313 VarDecl *ConditionVar = 0;
5314 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005315 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005316 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005317 getDerived().TransformDefinition(
5318 S->getConditionVariable()->getLocation(),
5319 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005320 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005322 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005323 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005324
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005325 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005327
5328 if (S->getCond()) {
5329 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005330 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5331 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005332 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005334 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005335 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005336 }
Mike Stump1eb44332009-09-09 15:08:12 +00005337
John McCall9ae2f072010-08-23 23:25:46 +00005338 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5339 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005340 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005341
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005343 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005348 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005351 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005353 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005354 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005355}
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005358StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005359TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005361 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005365 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005366 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005367 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005368 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (!getDerived().AlwaysRebuild() &&
5371 Cond.get() == S->getCond() &&
5372 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005373 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005374
John McCall9ae2f072010-08-23 23:25:46 +00005375 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5376 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 S->getRParenLoc());
5378}
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005381StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005382TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005384 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005389 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005390 VarDecl *ConditionVar = 0;
5391 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005392 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005393 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005394 getDerived().TransformDefinition(
5395 S->getConditionVariable()->getLocation(),
5396 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005397 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005398 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005399 } else {
5400 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005401
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005402 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005404
5405 if (S->getCond()) {
5406 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005407 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5408 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005409 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005411
John McCall9ae2f072010-08-23 23:25:46 +00005412 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005413 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005414 }
Mike Stump1eb44332009-09-09 15:08:12 +00005415
John McCall9ae2f072010-08-23 23:25:46 +00005416 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5417 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005419
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005421 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005424
John McCall9ae2f072010-08-23 23:25:46 +00005425 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5426 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005428
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005430 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregor43959a92009-08-20 07:17:43 +00005434 if (!getDerived().AlwaysRebuild() &&
5435 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005436 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 Inc.get() == S->getInc() &&
5438 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005439 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregor43959a92009-08-20 07:17:43 +00005441 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005442 Init.get(), FullCond, ConditionVar,
5443 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005444}
5445
5446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005447StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005448TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005449 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5450 S->getLabel());
5451 if (!LD)
5452 return StmtError();
5453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005455 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005456 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005457}
5458
5459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005461TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005462 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005464 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005465 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 if (!getDerived().AlwaysRebuild() &&
5468 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005470
5471 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005472 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005473}
5474
5475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005476StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005477TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005478 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005479}
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregor43959a92009-08-20 07:17:43 +00005481template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005482StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005483TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005484 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005485}
Mike Stump1eb44332009-09-09 15:08:12 +00005486
Douglas Gregor43959a92009-08-20 07:17:43 +00005487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005488StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005489TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005490 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005493
Mike Stump1eb44332009-09-09 15:08:12 +00005494 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005496 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005497}
Mike Stump1eb44332009-09-09 15:08:12 +00005498
Douglas Gregor43959a92009-08-20 07:17:43 +00005499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005500StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005501TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005503 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5505 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005506 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5507 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 if (Transformed != *D)
5512 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 Decls.push_back(Transformed);
5515 }
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005518 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005519
5520 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 S->getStartLoc(), S->getEndLoc());
5522}
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005525StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005526TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005527
John McCallca0408f2010-08-23 06:44:23 +00005528 ASTOwningVector<Expr*> Constraints(getSema());
5529 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005530 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005531
John McCall60d7b3a2010-08-24 06:29:42 +00005532 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005533 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005534
5535 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005536
Anders Carlsson703e3942010-01-24 05:50:09 +00005537 // Go through the outputs.
5538 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005539 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005540
Anders Carlsson703e3942010-01-24 05:50:09 +00005541 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005542 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005543
Anders Carlsson703e3942010-01-24 05:50:09 +00005544 // Transform the output expr.
5545 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005546 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005547 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005548 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005551
John McCall9ae2f072010-08-23 23:25:46 +00005552 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005553 }
Sean Huntc3021132010-05-05 15:23:54 +00005554
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 // Go through the inputs.
5556 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005557 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005558
Anders Carlsson703e3942010-01-24 05:50:09 +00005559 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005560 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005561
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 // Transform the input expr.
5563 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005564 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005565 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005566 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005569
John McCall9ae2f072010-08-23 23:25:46 +00005570 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 }
Sean Huntc3021132010-05-05 15:23:54 +00005572
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005574 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005575
5576 // Go through the clobbers.
5577 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005578 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005579
5580 // No need to transform the asm string literal.
5581 AsmString = SemaRef.Owned(S->getAsmString());
5582
5583 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5584 S->isSimple(),
5585 S->isVolatile(),
5586 S->getNumOutputs(),
5587 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005588 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005589 move_arg(Constraints),
5590 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005591 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005592 move_arg(Clobbers),
5593 S->getRParenLoc(),
5594 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005595}
5596
5597
5598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005599StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005600TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005601 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005602 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005603 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005604 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005605
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005606 // Transform the @catch statements (if present).
5607 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005608 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005609 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005610 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005611 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005612 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005613 if (Catch.get() != S->getCatchStmt(I))
5614 AnyCatchChanged = true;
5615 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005616 }
Sean Huntc3021132010-05-05 15:23:54 +00005617
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005618 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005619 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005620 if (S->getFinallyStmt()) {
5621 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5622 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005623 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005624 }
5625
5626 // If nothing changed, just retain this statement.
5627 if (!getDerived().AlwaysRebuild() &&
5628 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005629 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005630 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005631 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005632
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005634 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5635 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005636}
Mike Stump1eb44332009-09-09 15:08:12 +00005637
Douglas Gregor43959a92009-08-20 07:17:43 +00005638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005639StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005641 // Transform the @catch parameter, if there is one.
5642 VarDecl *Var = 0;
5643 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5644 TypeSourceInfo *TSInfo = 0;
5645 if (FromVar->getTypeSourceInfo()) {
5646 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5647 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005648 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005649 }
Sean Huntc3021132010-05-05 15:23:54 +00005650
Douglas Gregorbe270a02010-04-26 17:57:08 +00005651 QualType T;
5652 if (TSInfo)
5653 T = TSInfo->getType();
5654 else {
5655 T = getDerived().TransformType(FromVar->getType());
5656 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005657 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005658 }
Sean Huntc3021132010-05-05 15:23:54 +00005659
Douglas Gregorbe270a02010-04-26 17:57:08 +00005660 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5661 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005662 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005663 }
Sean Huntc3021132010-05-05 15:23:54 +00005664
John McCall60d7b3a2010-08-24 06:29:42 +00005665 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005668
5669 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005670 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005671 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005672}
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregor43959a92009-08-20 07:17:43 +00005674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005675StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005676TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005677 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005678 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005679 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005680 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005681
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005682 // If nothing changed, just retain this statement.
5683 if (!getDerived().AlwaysRebuild() &&
5684 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005685 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005686
5687 // Build a new statement.
5688 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005689 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005690}
Mike Stump1eb44332009-09-09 15:08:12 +00005691
Douglas Gregor43959a92009-08-20 07:17:43 +00005692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005693StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005694TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005695 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005696 if (S->getThrowExpr()) {
5697 Operand = getDerived().TransformExpr(S->getThrowExpr());
5698 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005699 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005700 }
Sean Huntc3021132010-05-05 15:23:54 +00005701
Douglas Gregord1377b22010-04-22 21:44:01 +00005702 if (!getDerived().AlwaysRebuild() &&
5703 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005704 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005705
John McCall9ae2f072010-08-23 23:25:46 +00005706 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005707}
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregor43959a92009-08-20 07:17:43 +00005709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005710StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005711TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005712 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005713 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005714 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005715 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005717 Object =
5718 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5719 Object.get());
5720 if (Object.isInvalid())
5721 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005722
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005723 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005724 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005725 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005726 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005727
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005728 // If nothing change, just retain the current statement.
5729 if (!getDerived().AlwaysRebuild() &&
5730 Object.get() == S->getSynchExpr() &&
5731 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005732 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005733
5734 // Build a new statement.
5735 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005736 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005737}
5738
5739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005740StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005741TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5742 ObjCAutoreleasePoolStmt *S) {
5743 // Transform the body.
5744 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5745 if (Body.isInvalid())
5746 return StmtError();
5747
5748 // If nothing changed, just retain this statement.
5749 if (!getDerived().AlwaysRebuild() &&
5750 Body.get() == S->getSubStmt())
5751 return SemaRef.Owned(S);
5752
5753 // Build a new statement.
5754 return getDerived().RebuildObjCAutoreleasePoolStmt(
5755 S->getAtLoc(), Body.get());
5756}
5757
5758template<typename Derived>
5759StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005760TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005761 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005762 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005763 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005764 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005765 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005766
Douglas Gregorc3203e72010-04-22 23:10:45 +00005767 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005768 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005769 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005770 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005771 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5772 Collection.take());
5773 if (Collection.isInvalid())
5774 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005775
Douglas Gregorc3203e72010-04-22 23:10:45 +00005776 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005777 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005778 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005779 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005780
Douglas Gregorc3203e72010-04-22 23:10:45 +00005781 // If nothing changed, just retain this statement.
5782 if (!getDerived().AlwaysRebuild() &&
5783 Element.get() == S->getElement() &&
5784 Collection.get() == S->getCollection() &&
5785 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005786 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005787
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 // Build a new statement.
5789 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5790 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005791 Element.get(),
5792 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005794 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005795}
5796
5797
5798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005799StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005800TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5801 // Transform the exception declaration, if any.
5802 VarDecl *Var = 0;
5803 if (S->getExceptionDecl()) {
5804 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005805 TypeSourceInfo *T = getDerived().TransformType(
5806 ExceptionDecl->getTypeSourceInfo());
5807 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005808 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Douglas Gregor83cb9422010-09-09 17:09:21 +00005810 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005811 ExceptionDecl->getInnerLocStart(),
5812 ExceptionDecl->getLocation(),
5813 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005814 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005815 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005816 }
Mike Stump1eb44332009-09-09 15:08:12 +00005817
Douglas Gregor43959a92009-08-20 07:17:43 +00005818 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005819 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005820 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
Douglas Gregor43959a92009-08-20 07:17:43 +00005823 if (!getDerived().AlwaysRebuild() &&
5824 !Var &&
5825 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005826 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005827
5828 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5829 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005830 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005831}
Mike Stump1eb44332009-09-09 15:08:12 +00005832
Douglas Gregor43959a92009-08-20 07:17:43 +00005833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005834StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005835TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5836 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005837 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005838 = getDerived().TransformCompoundStmt(S->getTryBlock());
5839 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005840 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregor43959a92009-08-20 07:17:43 +00005842 // Transform the handlers.
5843 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005844 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005845 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005846 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005847 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5848 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005849 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005850
Douglas Gregor43959a92009-08-20 07:17:43 +00005851 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5852 Handlers.push_back(Handler.takeAs<Stmt>());
5853 }
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregor43959a92009-08-20 07:17:43 +00005855 if (!getDerived().AlwaysRebuild() &&
5856 TryBlock.get() == S->getTryBlock() &&
5857 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005858 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005859
John McCall9ae2f072010-08-23 23:25:46 +00005860 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005861 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005862}
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Richard Smithad762fc2011-04-14 22:09:26 +00005864template<typename Derived>
5865StmtResult
5866TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5867 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5868 if (Range.isInvalid())
5869 return StmtError();
5870
5871 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5872 if (BeginEnd.isInvalid())
5873 return StmtError();
5874
5875 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5876 if (Cond.isInvalid())
5877 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005878 if (Cond.get())
5879 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5880 if (Cond.isInvalid())
5881 return StmtError();
5882 if (Cond.get())
5883 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005884
5885 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5886 if (Inc.isInvalid())
5887 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005888 if (Inc.get())
5889 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005890
5891 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5892 if (LoopVar.isInvalid())
5893 return StmtError();
5894
5895 StmtResult NewStmt = S;
5896 if (getDerived().AlwaysRebuild() ||
5897 Range.get() != S->getRangeStmt() ||
5898 BeginEnd.get() != S->getBeginEndStmt() ||
5899 Cond.get() != S->getCond() ||
5900 Inc.get() != S->getInc() ||
5901 LoopVar.get() != S->getLoopVarStmt())
5902 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5903 S->getColonLoc(), Range.get(),
5904 BeginEnd.get(), Cond.get(),
5905 Inc.get(), LoopVar.get(),
5906 S->getRParenLoc());
5907
5908 StmtResult Body = getDerived().TransformStmt(S->getBody());
5909 if (Body.isInvalid())
5910 return StmtError();
5911
5912 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5913 // it now so we have a new statement to attach the body to.
5914 if (Body.get() != S->getBody() && NewStmt.get() == S)
5915 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5916 S->getColonLoc(), Range.get(),
5917 BeginEnd.get(), Cond.get(),
5918 Inc.get(), LoopVar.get(),
5919 S->getRParenLoc());
5920
5921 if (NewStmt.get() == S)
5922 return SemaRef.Owned(S);
5923
5924 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5925}
5926
John Wiegley28bbe4b2011-04-28 01:08:34 +00005927template<typename Derived>
5928StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005929TreeTransform<Derived>::TransformMSDependentExistsStmt(
5930 MSDependentExistsStmt *S) {
5931 // Transform the nested-name-specifier, if any.
5932 NestedNameSpecifierLoc QualifierLoc;
5933 if (S->getQualifierLoc()) {
5934 QualifierLoc
5935 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5936 if (!QualifierLoc)
5937 return StmtError();
5938 }
5939
5940 // Transform the declaration name.
5941 DeclarationNameInfo NameInfo = S->getNameInfo();
5942 if (NameInfo.getName()) {
5943 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5944 if (!NameInfo.getName())
5945 return StmtError();
5946 }
5947
5948 // Check whether anything changed.
5949 if (!getDerived().AlwaysRebuild() &&
5950 QualifierLoc == S->getQualifierLoc() &&
5951 NameInfo.getName() == S->getNameInfo().getName())
5952 return S;
5953
5954 // Determine whether this name exists, if we can.
5955 CXXScopeSpec SS;
5956 SS.Adopt(QualifierLoc);
5957 bool Dependent = false;
5958 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5959 case Sema::IER_Exists:
5960 if (S->isIfExists())
5961 break;
5962
5963 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5964
5965 case Sema::IER_DoesNotExist:
5966 if (S->isIfNotExists())
5967 break;
5968
5969 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5970
5971 case Sema::IER_Dependent:
5972 Dependent = true;
5973 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005974
5975 case Sema::IER_Error:
5976 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005977 }
5978
5979 // We need to continue with the instantiation, so do so now.
5980 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5981 if (SubStmt.isInvalid())
5982 return StmtError();
5983
5984 // If we have resolved the name, just transform to the substatement.
5985 if (!Dependent)
5986 return SubStmt;
5987
5988 // The name is still dependent, so build a dependent expression again.
5989 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5990 S->isIfExists(),
5991 QualifierLoc,
5992 NameInfo,
5993 SubStmt.get());
5994}
5995
5996template<typename Derived>
5997StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005998TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5999 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6000 if(TryBlock.isInvalid()) return StmtError();
6001
6002 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6003 if(!getDerived().AlwaysRebuild() &&
6004 TryBlock.get() == S->getTryBlock() &&
6005 Handler.get() == S->getHandler())
6006 return SemaRef.Owned(S);
6007
6008 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6009 S->getTryLoc(),
6010 TryBlock.take(),
6011 Handler.take());
6012}
6013
6014template<typename Derived>
6015StmtResult
6016TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6017 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6018 if(Block.isInvalid()) return StmtError();
6019
6020 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6021 Block.take());
6022}
6023
6024template<typename Derived>
6025StmtResult
6026TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6027 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6028 if(FilterExpr.isInvalid()) return StmtError();
6029
6030 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6031 if(Block.isInvalid()) return StmtError();
6032
6033 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6034 FilterExpr.take(),
6035 Block.take());
6036}
6037
6038template<typename Derived>
6039StmtResult
6040TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6041 if(isa<SEHFinallyStmt>(Handler))
6042 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6043 else
6044 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6045}
6046
Douglas Gregor43959a92009-08-20 07:17:43 +00006047//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048// Expression transformation
6049//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006051ExprResult
John McCall454feb92009-12-08 09:21:05 +00006052TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006053 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054}
Mike Stump1eb44332009-09-09 15:08:12 +00006055
6056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006057ExprResult
John McCall454feb92009-12-08 09:21:05 +00006058TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006059 NestedNameSpecifierLoc QualifierLoc;
6060 if (E->getQualifierLoc()) {
6061 QualifierLoc
6062 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6063 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006064 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006065 }
John McCalldbd872f2009-12-08 09:08:17 +00006066
6067 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006068 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6069 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006071 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006072
John McCallec8045d2010-08-17 21:27:17 +00006073 DeclarationNameInfo NameInfo = E->getNameInfo();
6074 if (NameInfo.getName()) {
6075 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6076 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006077 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006078 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006079
6080 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006081 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006082 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006083 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006084 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006085
6086 // Mark it referenced in the new context regardless.
6087 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006088 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006089
John McCall3fa5cae2010-10-26 07:05:15 +00006090 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006091 }
John McCalldbd872f2009-12-08 09:08:17 +00006092
6093 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006094 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006095 TemplateArgs = &TransArgs;
6096 TransArgs.setLAngleLoc(E->getLAngleLoc());
6097 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006098 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6099 E->getNumTemplateArgs(),
6100 TransArgs))
6101 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006102 }
6103
Douglas Gregor40d96a62011-02-28 21:54:11 +00006104 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
6105 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006106}
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006109ExprResult
John McCall454feb92009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112}
Mike Stump1eb44332009-09-09 15:08:12 +00006113
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006115ExprResult
John McCall454feb92009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006117 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118}
Mike Stump1eb44332009-09-09 15:08:12 +00006119
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124}
Mike Stump1eb44332009-09-09 15:08:12 +00006125
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006136}
6137
6138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006139ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006140TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6141 return SemaRef.MaybeBindToTemporary(E);
6142}
6143
6144template<typename Derived>
6145ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006146TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6147 ExprResult ControllingExpr =
6148 getDerived().TransformExpr(E->getControllingExpr());
6149 if (ControllingExpr.isInvalid())
6150 return ExprError();
6151
Chris Lattner686775d2011-07-20 06:58:45 +00006152 SmallVector<Expr *, 4> AssocExprs;
6153 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006154 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6155 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6156 if (TS) {
6157 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6158 if (!AssocType)
6159 return ExprError();
6160 AssocTypes.push_back(AssocType);
6161 } else {
6162 AssocTypes.push_back(0);
6163 }
6164
6165 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6166 if (AssocExpr.isInvalid())
6167 return ExprError();
6168 AssocExprs.push_back(AssocExpr.release());
6169 }
6170
6171 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6172 E->getDefaultLoc(),
6173 E->getRParenLoc(),
6174 ControllingExpr.release(),
6175 AssocTypes.data(),
6176 AssocExprs.data(),
6177 E->getNumAssocs());
6178}
6179
6180template<typename Derived>
6181ExprResult
John McCall454feb92009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006183 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006185 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006186
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006188 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006189
John McCall9ae2f072010-08-23 23:25:46 +00006190 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 E->getRParen());
6192}
6193
Mike Stump1eb44332009-09-09 15:08:12 +00006194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006195ExprResult
John McCall454feb92009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006197 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006200
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006202 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6205 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006206 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207}
Mike Stump1eb44332009-09-09 15:08:12 +00006208
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006210ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006211TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6212 // Transform the type.
6213 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6214 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006215 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006216
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006217 // Transform all of the components into components similar to what the
6218 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006219 // FIXME: It would be slightly more efficient in the non-dependent case to
6220 // just map FieldDecls, rather than requiring the rebuilder to look for
6221 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006222 // template code that we don't care.
6223 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006224 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006225 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006226 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006227 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6228 const Node &ON = E->getComponent(I);
6229 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006230 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006231 Comp.LocStart = ON.getSourceRange().getBegin();
6232 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006233 switch (ON.getKind()) {
6234 case Node::Array: {
6235 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006236 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006237 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006238 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006239
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006240 ExprChanged = ExprChanged || Index.get() != FromIndex;
6241 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006242 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006243 break;
6244 }
Sean Huntc3021132010-05-05 15:23:54 +00006245
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 case Node::Field:
6247 case Node::Identifier:
6248 Comp.isBrackets = false;
6249 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006250 if (!Comp.U.IdentInfo)
6251 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006252
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253 break;
Sean Huntc3021132010-05-05 15:23:54 +00006254
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006255 case Node::Base:
6256 // Will be recomputed during the rebuild.
6257 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 }
Sean Huntc3021132010-05-05 15:23:54 +00006259
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260 Components.push_back(Comp);
6261 }
Sean Huntc3021132010-05-05 15:23:54 +00006262
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006263 // If nothing changed, retain the existing expression.
6264 if (!getDerived().AlwaysRebuild() &&
6265 Type == E->getTypeSourceInfo() &&
6266 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006267 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006268
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 // Build a new offsetof expression.
6270 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6271 Components.data(), Components.size(),
6272 E->getRParenLoc());
6273}
6274
6275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006276ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006277TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6278 assert(getDerived().AlreadyTransformed(E->getType()) &&
6279 "opaque value expression requires transformation");
6280 return SemaRef.Owned(E);
6281}
6282
6283template<typename Derived>
6284ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006285TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006286 // Rebuild the syntactic form. The original syntactic form has
6287 // opaque-value expressions in it, so strip those away and rebuild
6288 // the result. This is a really awful way of doing this, but the
6289 // better solution (rebuilding the semantic expressions and
6290 // rebinding OVEs as necessary) doesn't work; we'd need
6291 // TreeTransform to not strip away implicit conversions.
6292 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6293 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006294 if (result.isInvalid()) return ExprError();
6295
6296 // If that gives us a pseudo-object result back, the pseudo-object
6297 // expression must have been an lvalue-to-rvalue conversion which we
6298 // should reapply.
6299 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6300 result = SemaRef.checkPseudoObjectRValue(result.take());
6301
6302 return result;
6303}
6304
6305template<typename Derived>
6306ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006307TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6308 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006310 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006311
John McCalla93c9342009-12-07 02:54:59 +00006312 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006313 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006314 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006315
John McCall5ab75172009-11-04 07:28:41 +00006316 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006317 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006318
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006319 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6320 E->getKind(),
6321 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 }
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006324 // C++0x [expr.sizeof]p1:
6325 // The operand is either an expression, which is an unevaluated operand
6326 // [...]
6327 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006328
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006329 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6330 if (SubExpr.isInvalid())
6331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006333 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6334 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006336 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6337 E->getOperatorLoc(),
6338 E->getKind(),
6339 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340}
Mike Stump1eb44332009-09-09 15:08:12 +00006341
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006343ExprResult
John McCall454feb92009-12-08 09:21:05 +00006344TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006345 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006348
John McCall60d7b3a2010-08-24 06:29:42 +00006349 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006351 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006352
6353
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354 if (!getDerived().AlwaysRebuild() &&
6355 LHS.get() == E->getLHS() &&
6356 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006357 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006358
John McCall9ae2f072010-08-23 23:25:46 +00006359 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006361 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 E->getRBracketLoc());
6363}
Mike Stump1eb44332009-09-09 15:08:12 +00006364
6365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
John McCall454feb92009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006369 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006371 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372
6373 // Transform arguments.
6374 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006375 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006376 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6377 &ArgChanged))
6378 return ExprError();
6379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
6381 Callee.get() == E->getCallee() &&
6382 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006383 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006386 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006388 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 E->getRParenLoc());
6391}
Mike Stump1eb44332009-09-09 15:08:12 +00006392
6393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006394ExprResult
John McCall454feb92009-12-08 09:21:05 +00006395TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006396 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006398 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006399
Douglas Gregor40d96a62011-02-28 21:54:11 +00006400 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006401 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006402 QualifierLoc
6403 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6404
6405 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006407 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006408 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006409
Eli Friedmanf595cc42009-12-04 06:40:45 +00006410 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006411 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6412 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006414 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006415
John McCall6bb80172010-03-30 21:47:33 +00006416 NamedDecl *FoundDecl = E->getFoundDecl();
6417 if (FoundDecl == E->getMemberDecl()) {
6418 FoundDecl = Member;
6419 } else {
6420 FoundDecl = cast_or_null<NamedDecl>(
6421 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6422 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006423 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006424 }
6425
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426 if (!getDerived().AlwaysRebuild() &&
6427 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006428 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006429 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006430 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006431 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006432
Anders Carlsson1f240322009-12-22 05:24:09 +00006433 // Mark it referenced in the new context regardless.
6434 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006435 SemaRef.MarkMemberReferenced(E);
6436
John McCall3fa5cae2010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006438 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439
John McCalld5532b62009-11-23 01:53:49 +00006440 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006441 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006442 TransArgs.setLAngleLoc(E->getLAngleLoc());
6443 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006444 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6445 E->getNumTemplateArgs(),
6446 TransArgs))
6447 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006448 }
Sean Huntc3021132010-05-05 15:23:54 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 // FIXME: Bogus source location for the operator
6451 SourceLocation FakeOperatorLoc
6452 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6453
John McCallc2233c52010-01-15 08:34:02 +00006454 // FIXME: to do this check properly, we will need to preserve the
6455 // first-qualifier-in-scope here, just in case we had a dependent
6456 // base (and therefore couldn't do the check) and a
6457 // nested-name-qualifier (and therefore could do the lookup).
6458 NamedDecl *FirstQualifierInScope = 0;
6459
John McCall9ae2f072010-08-23 23:25:46 +00006460 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006462 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006463 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006464 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006465 Member,
John McCall6bb80172010-03-30 21:47:33 +00006466 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006467 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006468 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006469 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470}
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006475 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006478
John McCall60d7b3a2010-08-24 06:29:42 +00006479 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 if (!getDerived().AlwaysRebuild() &&
6484 LHS.get() == E->getLHS() &&
6485 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006487
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006489 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490}
6491
Mike Stump1eb44332009-09-09 15:08:12 +00006492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006493ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006495 CompoundAssignOperator *E) {
6496 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006500ExprResult TreeTransform<Derived>::
6501TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6502 // Just rebuild the common and RHS expressions and see whether we
6503 // get any changes.
6504
6505 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6506 if (commonExpr.isInvalid())
6507 return ExprError();
6508
6509 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6510 if (rhs.isInvalid())
6511 return ExprError();
6512
6513 if (!getDerived().AlwaysRebuild() &&
6514 commonExpr.get() == e->getCommon() &&
6515 rhs.get() == e->getFalseExpr())
6516 return SemaRef.Owned(e);
6517
6518 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6519 e->getQuestionLoc(),
6520 0,
6521 e->getColonLoc(),
6522 rhs.get());
6523}
6524
6525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006526ExprResult
John McCall454feb92009-12-08 09:21:05 +00006527TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006528 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006531
John McCall60d7b3a2010-08-24 06:29:42 +00006532 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006534 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006535
John McCall60d7b3a2010-08-24 06:29:42 +00006536 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 if (!getDerived().AlwaysRebuild() &&
6541 Cond.get() == E->getCond() &&
6542 LHS.get() == E->getLHS() &&
6543 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006544 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006545
John McCall9ae2f072010-08-23 23:25:46 +00006546 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006547 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006548 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006549 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006550 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551}
Mike Stump1eb44332009-09-09 15:08:12 +00006552
6553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006554ExprResult
John McCall454feb92009-12-08 09:21:05 +00006555TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006556 // Implicit casts are eliminated during transformation, since they
6557 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006558 return getDerived().TransformExpr(E->getSubExprAsWritten());
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>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006564 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6565 if (!Type)
6566 return ExprError();
6567
John McCall60d7b3a2010-08-24 06:29:42 +00006568 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006569 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006572
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006574 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006576 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006577
John McCall9d125032010-01-15 18:39:57 +00006578 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006579 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006581 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582}
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006585ExprResult
John McCall454feb92009-12-08 09:21:05 +00006586TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006587 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6588 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6589 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006590 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006591
John McCall60d7b3a2010-08-24 06:29:42 +00006592 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006597 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006599 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600
John McCall1d7d8d62010-01-19 22:33:45 +00006601 // Note: the expression type doesn't necessarily match the
6602 // type-as-written, but that's okay, because it should always be
6603 // derivable from the initializer.
6604
John McCall42f56b52010-01-18 19:35:47 +00006605 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006607 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608}
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006611ExprResult
John McCall454feb92009-12-08 09:21:05 +00006612TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006613 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 if (!getDerived().AlwaysRebuild() &&
6618 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006619 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006622 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006624 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 E->getAccessorLoc(),
6626 E->getAccessor());
6627}
Mike Stump1eb44332009-09-09 15:08:12 +00006628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006630ExprResult
John McCall454feb92009-12-08 09:21:05 +00006631TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006633
John McCallca0408f2010-08-23 06:44:23 +00006634 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006635 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6636 Inits, &InitChanged))
6637 return ExprError();
6638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006643 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644}
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006647ExprResult
John McCall454feb92009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregor43959a92009-08-20 07:17:43 +00006651 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006652 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregor43959a92009-08-20 07:17:43 +00006656 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006657 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 bool ExprChanged = false;
6659 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6660 DEnd = E->designators_end();
6661 D != DEnd; ++D) {
6662 if (D->isFieldDesignator()) {
6663 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6664 D->getDotLoc(),
6665 D->getFieldLoc()));
6666 continue;
6667 }
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006670 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006673
6674 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6678 ArrayExprs.push_back(Index.release());
6679 continue;
6680 }
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006683 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6685 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006687
John McCall60d7b3a2010-08-24 06:29:42 +00006688 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006691
6692 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 End.get(),
6694 D->getLBracketLoc(),
6695 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6698 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 ArrayExprs.push_back(Start.release());
6701 ArrayExprs.push_back(End.release());
6702 }
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (!getDerived().AlwaysRebuild() &&
6705 Init.get() == E->getInit() &&
6706 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006707 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6710 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006711 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712}
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006715ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006717 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006718 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006719
Douglas Gregor5557b252009-10-28 00:29:27 +00006720 // FIXME: Will we ever have proper type location here? Will we actually
6721 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 QualType T = getDerived().TransformType(E->getType());
6723 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (!getDerived().AlwaysRebuild() &&
6727 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006728 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 return getDerived().RebuildImplicitValueInitExpr(T);
6731}
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006734ExprResult
John McCall454feb92009-12-08 09:21:05 +00006735TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006736 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6737 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006739
John McCall60d7b3a2010-08-24 06:29:42 +00006740 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006742 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006745 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006747 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006748
John McCall9ae2f072010-08-23 23:25:46 +00006749 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006750 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751}
6752
6753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006754ExprResult
John McCall454feb92009-12-08 09:21:05 +00006755TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006757 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006758 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6759 &ArgumentChanged))
6760 return ExprError();
6761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6763 move_arg(Inits),
6764 E->getRParenLoc());
6765}
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767/// \brief Transform an address-of-label expression.
6768///
6769/// By default, the transformation of an address-of-label expression always
6770/// rebuilds the expression, so that the label identifier can be resolved to
6771/// the corresponding label statement by semantic analysis.
6772template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006773ExprResult
John McCall454feb92009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006775 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6776 E->getLabel());
6777 if (!LD)
6778 return ExprError();
6779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006781 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
6784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006787 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006788 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006790 if (SubStmt.isInvalid()) {
6791 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006792 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006793 }
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006796 SubStmt.get() == E->getSubStmt()) {
6797 // Calling this an 'error' is unintuitive, but it does the right thing.
6798 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006799 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006800 }
Mike Stump1eb44332009-09-09 15:08:12 +00006801
6802 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006803 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 E->getRParenLoc());
6805}
Mike Stump1eb44332009-09-09 15:08:12 +00006806
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006808ExprResult
John McCall454feb92009-12-08 09:21:05 +00006809TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006810 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006812 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006813
John McCall60d7b3a2010-08-24 06:29:42 +00006814 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006816 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006817
John McCall60d7b3a2010-08-24 06:29:42 +00006818 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (!getDerived().AlwaysRebuild() &&
6823 Cond.get() == E->getCond() &&
6824 LHS.get() == E->getLHS() &&
6825 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006826 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006827
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006829 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 E->getRParenLoc());
6831}
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006834ExprResult
John McCall454feb92009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837}
6838
6839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006840ExprResult
John McCall454feb92009-12-08 09:21:05 +00006841TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006842 switch (E->getOperator()) {
6843 case OO_New:
6844 case OO_Delete:
6845 case OO_Array_New:
6846 case OO_Array_Delete:
6847 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Sean Huntc3021132010-05-05 15:23:54 +00006848
Douglas Gregor668d6d92009-12-13 20:44:55 +00006849 case OO_Call: {
6850 // This is a call to an object's operator().
6851 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6852
6853 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006854 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006855 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006856 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006857
6858 // FIXME: Poor location information
6859 SourceLocation FakeLParenLoc
6860 = SemaRef.PP.getLocForEndOfToken(
6861 static_cast<Expr *>(Object.get())->getLocEnd());
6862
6863 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006864 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006865 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6866 Args))
6867 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006868
John McCall9ae2f072010-08-23 23:25:46 +00006869 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006870 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006871 E->getLocEnd());
6872 }
6873
6874#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6875 case OO_##Name:
6876#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6877#include "clang/Basic/OperatorKinds.def"
6878 case OO_Subscript:
6879 // Handled below.
6880 break;
6881
6882 case OO_Conditional:
6883 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884
6885 case OO_None:
6886 case NUM_OVERLOADED_OPERATORS:
6887 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006888 }
6889
John McCall60d7b3a2010-08-24 06:29:42 +00006890 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006893
John McCall60d7b3a2010-08-24 06:29:42 +00006894 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006896 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897
John McCall60d7b3a2010-08-24 06:29:42 +00006898 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (E->getNumArgs() == 2) {
6900 Second = getDerived().TransformExpr(E->getArg(1));
6901 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006902 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 }
Mike Stump1eb44332009-09-09 15:08:12 +00006904
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (!getDerived().AlwaysRebuild() &&
6906 Callee.get() == E->getCallee() &&
6907 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006908 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006909 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6912 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006913 Callee.get(),
6914 First.get(),
6915 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916}
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006919ExprResult
John McCall454feb92009-12-08 09:21:05 +00006920TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6921 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922}
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006925ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006926TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6927 // Transform the callee.
6928 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6929 if (Callee.isInvalid())
6930 return ExprError();
6931
6932 // Transform exec config.
6933 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6934 if (EC.isInvalid())
6935 return ExprError();
6936
6937 // Transform arguments.
6938 bool ArgChanged = false;
6939 ASTOwningVector<Expr*> Args(SemaRef);
6940 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6941 &ArgChanged))
6942 return ExprError();
6943
6944 if (!getDerived().AlwaysRebuild() &&
6945 Callee.get() == E->getCallee() &&
6946 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006947 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006948
6949 // FIXME: Wrong source location information for the '('.
6950 SourceLocation FakeLParenLoc
6951 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6952 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6953 move_arg(Args),
6954 E->getRParenLoc(), EC.get());
6955}
6956
6957template<typename Derived>
6958ExprResult
John McCall454feb92009-12-08 09:21:05 +00006959TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006960 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6961 if (!Type)
6962 return ExprError();
6963
John McCall60d7b3a2010-08-24 06:29:42 +00006964 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006965 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006970 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006972 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006973
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006975 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6977 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6978 SourceLocation FakeRParenLoc
6979 = SemaRef.PP.getLocForEndOfToken(
6980 E->getSubExpr()->getSourceRange().getEnd());
6981 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006982 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006984 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 FakeRAngleLoc,
6986 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006987 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 FakeRParenLoc);
6989}
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006992ExprResult
John McCall454feb92009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6994 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995}
Mike Stump1eb44332009-09-09 15:08:12 +00006996
6997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006998ExprResult
John McCall454feb92009-12-08 09:21:05 +00006999TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7000 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007001}
7002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007004ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007006 CXXReinterpretCastExpr *E) {
7007 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008}
Mike Stump1eb44332009-09-09 15:08:12 +00007009
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007011ExprResult
John McCall454feb92009-12-08 09:21:05 +00007012TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7013 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014}
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007017ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007019 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007020 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7021 if (!Type)
7022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007023
John McCall60d7b3a2010-08-24 06:29:42 +00007024 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007025 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007030 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007032 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007034 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007036 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 E->getRParenLoc());
7038}
Mike Stump1eb44332009-09-09 15:08:12 +00007039
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007041ExprResult
John McCall454feb92009-12-08 09:21:05 +00007042TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007044 TypeSourceInfo *TInfo
7045 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7046 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007047 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007050 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007053 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7054 E->getLocStart(),
7055 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 E->getLocEnd());
7057 }
Mike Stump1eb44332009-09-09 15:08:12 +00007058
Eli Friedmanef331b72012-01-20 01:26:23 +00007059 // We don't know whether the subexpression is potentially evaluated until
7060 // after we perform semantic analysis. We speculatively assume it is
7061 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007063 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007064
John McCall60d7b3a2010-08-24 06:29:42 +00007065 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007067 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 if (!getDerived().AlwaysRebuild() &&
7070 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007071 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007072
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007073 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7074 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007075 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 E->getLocEnd());
7077}
7078
7079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007080ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007081TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7082 if (E->isTypeOperand()) {
7083 TypeSourceInfo *TInfo
7084 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7085 if (!TInfo)
7086 return ExprError();
7087
7088 if (!getDerived().AlwaysRebuild() &&
7089 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007090 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007091
Douglas Gregor3c52a212011-03-06 17:40:41 +00007092 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007093 E->getLocStart(),
7094 TInfo,
7095 E->getLocEnd());
7096 }
7097
Francois Pichet01b7c302010-09-08 12:20:18 +00007098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7099
7100 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7101 if (SubExpr.isInvalid())
7102 return ExprError();
7103
7104 if (!getDerived().AlwaysRebuild() &&
7105 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007106 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007107
7108 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7109 E->getLocStart(),
7110 SubExpr.get(),
7111 E->getLocEnd());
7112}
7113
7114template<typename Derived>
7115ExprResult
John McCall454feb92009-12-08 09:21:05 +00007116TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007117 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118}
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007121ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007123 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007124 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125}
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007128ExprResult
John McCall454feb92009-12-08 09:21:05 +00007129TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007130 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007131 QualType T;
7132 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7133 T = MD->getThisType(getSema().Context);
7134 else
7135 T = getSema().Context.getPointerType(
7136 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007137
Douglas Gregorec79d872012-02-24 17:41:38 +00007138 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7139 // Make sure that we capture 'this'.
7140 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007141 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007142 }
7143
Douglas Gregor828a1972010-01-07 23:12:05 +00007144 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145}
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007148ExprResult
John McCall454feb92009-12-08 09:21:05 +00007149TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007150 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 if (SubExpr.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 if (!getDerived().AlwaysRebuild() &&
7155 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007156 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157
Douglas Gregorbca01b42011-07-06 22:04:06 +00007158 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7159 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160}
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007163ExprResult
John McCall454feb92009-12-08 09:21:05 +00007164TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007165 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007166 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7167 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007169 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007170
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007171 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007173 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007174
Douglas Gregor036aed12009-12-23 23:03:06 +00007175 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176}
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007179ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007180TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7181 CXXScalarValueInitExpr *E) {
7182 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7183 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007187 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007188 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorab6677e2010-09-08 00:15:04 +00007190 return getDerived().RebuildCXXScalarValueInitExpr(T,
7191 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007192 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193}
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007196ExprResult
John McCall454feb92009-12-08 09:21:05 +00007197TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007199 TypeSourceInfo *AllocTypeInfo
7200 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7201 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007202 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007205 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 // Transform the placement arguments (if any).
7210 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007211 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007212 if (getDerived().TransformExprs(E->getPlacementArgs(),
7213 E->getNumPlacementArgs(), true,
7214 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007216
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007217 // Transform the initializer (if any).
7218 Expr *OldInit = E->getInitializer();
7219 ExprResult NewInit;
7220 if (OldInit)
7221 NewInit = getDerived().TransformExpr(OldInit);
7222 if (NewInit.isInvalid())
7223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007224
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007225 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007226 FunctionDecl *OperatorNew = 0;
7227 if (E->getOperatorNew()) {
7228 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007229 getDerived().TransformDecl(E->getLocStart(),
7230 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007231 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007232 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007233 }
7234
7235 FunctionDecl *OperatorDelete = 0;
7236 if (E->getOperatorDelete()) {
7237 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007238 getDerived().TransformDecl(E->getLocStart(),
7239 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007240 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007242 }
Sean Huntc3021132010-05-05 15:23:54 +00007243
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007245 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007247 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007248 OperatorNew == E->getOperatorNew() &&
7249 OperatorDelete == E->getOperatorDelete() &&
7250 !ArgumentChanged) {
7251 // Mark any declarations we need as referenced.
7252 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007253 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007254 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007255 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007256 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007257
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007258 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007259 QualType ElementType
7260 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7261 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7262 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7263 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007264 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007265 }
7266 }
7267 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268
John McCall3fa5cae2010-10-26 07:05:15 +00007269 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007270 }
Mike Stump1eb44332009-09-09 15:08:12 +00007271
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007272 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007273 if (!ArraySize.get()) {
7274 // If no array size was specified, but the new expression was
7275 // instantiated with an array type (e.g., "new T" where T is
7276 // instantiated with "int[4]"), extract the outer bound from the
7277 // array type as our array size. We do this with constant and
7278 // dependently-sized array types.
7279 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7280 if (!ArrayT) {
7281 // Do nothing
7282 } else if (const ConstantArrayType *ConsArrayT
7283 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007284 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007285 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7286 ConsArrayT->getSize(),
7287 SemaRef.Context.getSizeType(),
7288 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007289 AllocType = ConsArrayT->getElementType();
7290 } else if (const DependentSizedArrayType *DepArrayT
7291 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7292 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007293 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007294 AllocType = DepArrayT->getElementType();
7295 }
7296 }
7297 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007298
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7300 E->isGlobalNew(),
7301 /*FIXME:*/E->getLocStart(),
7302 move_arg(PlacementArgs),
7303 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007304 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007306 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007307 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007308 E->getDirectInitRange(),
7309 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310}
Mike Stump1eb44332009-09-09 15:08:12 +00007311
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007313ExprResult
John McCall454feb92009-12-08 09:21:05 +00007314TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007315 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregor1af74512010-02-26 00:38:10 +00007319 // Transform the delete operator, if known.
7320 FunctionDecl *OperatorDelete = 0;
7321 if (E->getOperatorDelete()) {
7322 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007323 getDerived().TransformDecl(E->getLocStart(),
7324 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007325 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007326 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007327 }
Sean Huntc3021132010-05-05 15:23:54 +00007328
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007330 Operand.get() == E->getArgument() &&
7331 OperatorDelete == E->getOperatorDelete()) {
7332 // Mark any declarations we need as referenced.
7333 // FIXME: instantiation-specific.
7334 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007335 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007336
7337 if (!E->getArgument()->isTypeDependent()) {
7338 QualType Destroyed = SemaRef.Context.getBaseElementType(
7339 E->getDestroyedType());
7340 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7341 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007342 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7343 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007344 }
7345 }
7346
John McCall3fa5cae2010-10-26 07:05:15 +00007347 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007348 }
Mike Stump1eb44332009-09-09 15:08:12 +00007349
Douglas Gregorb98b1992009-08-11 05:31:07 +00007350 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7351 E->isGlobalDelete(),
7352 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007353 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354}
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007357ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007358TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007359 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007360 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007361 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007363
John McCallb3d87482010-08-24 05:47:05 +00007364 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007365 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007366 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007367 E->getOperatorLoc(),
7368 E->isArrow()? tok::arrow : tok::period,
7369 ObjectTypePtr,
7370 MayBePseudoDestructor);
7371 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007372 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007373
John McCallb3d87482010-08-24 05:47:05 +00007374 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007375 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7376 if (QualifierLoc) {
7377 QualifierLoc
7378 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7379 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007380 return ExprError();
7381 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007382 CXXScopeSpec SS;
7383 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007384
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007385 PseudoDestructorTypeStorage Destroyed;
7386 if (E->getDestroyedTypeInfo()) {
7387 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007388 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007389 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007390 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007391 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007392 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007393 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007394 // We aren't likely to be able to resolve the identifier down to a type
7395 // now anyway, so just retain the identifier.
7396 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7397 E->getDestroyedTypeLoc());
7398 } else {
7399 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007400 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007401 *E->getDestroyedTypeIdentifier(),
7402 E->getDestroyedTypeLoc(),
7403 /*Scope=*/0,
7404 SS, ObjectTypePtr,
7405 false);
7406 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007407 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007408
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007409 Destroyed
7410 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7411 E->getDestroyedTypeLoc());
7412 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007413
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007414 TypeSourceInfo *ScopeTypeInfo = 0;
7415 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007416 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007417 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007418 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007419 }
Sean Huntc3021132010-05-05 15:23:54 +00007420
John McCall9ae2f072010-08-23 23:25:46 +00007421 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007422 E->getOperatorLoc(),
7423 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007424 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007425 ScopeTypeInfo,
7426 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007427 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007428 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007429}
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Douglas Gregora71d8192009-09-04 17:36:40 +00007431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007432ExprResult
John McCallba135432009-11-21 08:51:07 +00007433TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007434 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007435 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7436 Sema::LookupOrdinaryName);
7437
7438 // Transform all the decls.
7439 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7440 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007441 NamedDecl *InstD = static_cast<NamedDecl*>(
7442 getDerived().TransformDecl(Old->getNameLoc(),
7443 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007444 if (!InstD) {
7445 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7446 // This can happen because of dependent hiding.
7447 if (isa<UsingShadowDecl>(*I))
7448 continue;
7449 else
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007451 }
John McCallf7a1a742009-11-24 19:00:30 +00007452
7453 // Expand using declarations.
7454 if (isa<UsingDecl>(InstD)) {
7455 UsingDecl *UD = cast<UsingDecl>(InstD);
7456 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7457 E = UD->shadow_end(); I != E; ++I)
7458 R.addDecl(*I);
7459 continue;
7460 }
7461
7462 R.addDecl(InstD);
7463 }
7464
7465 // Resolve a kind, but don't do any further analysis. If it's
7466 // ambiguous, the callee needs to deal with it.
7467 R.resolveKind();
7468
7469 // Rebuild the nested-name qualifier, if present.
7470 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007471 if (Old->getQualifierLoc()) {
7472 NestedNameSpecifierLoc QualifierLoc
7473 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7474 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007475 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007476
Douglas Gregor4c9be892011-02-28 20:01:57 +00007477 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007478 }
7479
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007480 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007481 CXXRecordDecl *NamingClass
7482 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7483 Old->getNameLoc(),
7484 Old->getNamingClass()));
7485 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007486 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007487
Douglas Gregor66c45152010-04-27 16:10:10 +00007488 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007489 }
7490
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007491 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7492
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007493 // If we have neither explicit template arguments, nor the template keyword,
7494 // it's a normal declaration name.
7495 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007496 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7497
7498 // If we have template arguments, rebuild them, then rebuild the
7499 // templateid expression.
7500 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007501 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7502 Old->getNumTemplateArgs(),
7503 TransArgs))
7504 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007505
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007506 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007507 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508}
Mike Stump1eb44332009-09-09 15:08:12 +00007509
Douglas Gregorb98b1992009-08-11 05:31:07 +00007510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007511ExprResult
John McCall454feb92009-12-08 09:21:05 +00007512TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007513 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7514 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007516
Douglas Gregorb98b1992009-08-11 05:31:07 +00007517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007518 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007519 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Mike Stump1eb44332009-09-09 15:08:12 +00007521 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523 T,
7524 E->getLocEnd());
7525}
Mike Stump1eb44332009-09-09 15:08:12 +00007526
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007528ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007529TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7530 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7531 if (!LhsT)
7532 return ExprError();
7533
7534 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7535 if (!RhsT)
7536 return ExprError();
7537
7538 if (!getDerived().AlwaysRebuild() &&
7539 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7540 return SemaRef.Owned(E);
7541
7542 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7543 E->getLocStart(),
7544 LhsT, RhsT,
7545 E->getLocEnd());
7546}
7547
7548template<typename Derived>
7549ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007550TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7551 bool ArgChanged = false;
7552 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7553 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7554 TypeSourceInfo *From = E->getArg(I);
7555 TypeLoc FromTL = From->getTypeLoc();
7556 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7557 TypeLocBuilder TLB;
7558 TLB.reserve(FromTL.getFullDataSize());
7559 QualType To = getDerived().TransformType(TLB, FromTL);
7560 if (To.isNull())
7561 return ExprError();
7562
7563 if (To == From->getType())
7564 Args.push_back(From);
7565 else {
7566 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7567 ArgChanged = true;
7568 }
7569 continue;
7570 }
7571
7572 ArgChanged = true;
7573
7574 // We have a pack expansion. Instantiate it.
7575 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
7576 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7577 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7578 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
7579
7580 // Determine whether the set of unexpanded parameter packs can and should
7581 // be expanded.
7582 bool Expand = true;
7583 bool RetainExpansion = false;
7584 llvm::Optional<unsigned> OrigNumExpansions
7585 = ExpansionTL.getTypePtr()->getNumExpansions();
7586 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7587 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7588 PatternTL.getSourceRange(),
7589 Unexpanded,
7590 Expand, RetainExpansion,
7591 NumExpansions))
7592 return ExprError();
7593
7594 if (!Expand) {
7595 // The transform has determined that we should perform a simple
7596 // transformation on the pack expansion, producing another pack
7597 // expansion.
7598 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7599
7600 TypeLocBuilder TLB;
7601 TLB.reserve(From->getTypeLoc().getFullDataSize());
7602
7603 QualType To = getDerived().TransformType(TLB, PatternTL);
7604 if (To.isNull())
7605 return ExprError();
7606
7607 To = getDerived().RebuildPackExpansionType(To,
7608 PatternTL.getSourceRange(),
7609 ExpansionTL.getEllipsisLoc(),
7610 NumExpansions);
7611 if (To.isNull())
7612 return ExprError();
7613
7614 PackExpansionTypeLoc ToExpansionTL
7615 = TLB.push<PackExpansionTypeLoc>(To);
7616 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7617 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7618 continue;
7619 }
7620
7621 // Expand the pack expansion by substituting for each argument in the
7622 // pack(s).
7623 for (unsigned I = 0; I != *NumExpansions; ++I) {
7624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7625 TypeLocBuilder TLB;
7626 TLB.reserve(PatternTL.getFullDataSize());
7627 QualType To = getDerived().TransformType(TLB, PatternTL);
7628 if (To.isNull())
7629 return ExprError();
7630
7631 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7632 }
7633
7634 if (!RetainExpansion)
7635 continue;
7636
7637 // If we're supposed to retain a pack expansion, do so by temporarily
7638 // forgetting the partially-substituted parameter pack.
7639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7640
7641 TypeLocBuilder TLB;
7642 TLB.reserve(From->getTypeLoc().getFullDataSize());
7643
7644 QualType To = getDerived().TransformType(TLB, PatternTL);
7645 if (To.isNull())
7646 return ExprError();
7647
7648 To = getDerived().RebuildPackExpansionType(To,
7649 PatternTL.getSourceRange(),
7650 ExpansionTL.getEllipsisLoc(),
7651 NumExpansions);
7652 if (To.isNull())
7653 return ExprError();
7654
7655 PackExpansionTypeLoc ToExpansionTL
7656 = TLB.push<PackExpansionTypeLoc>(To);
7657 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7658 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7659 }
7660
7661 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7662 return SemaRef.Owned(E);
7663
7664 return getDerived().RebuildTypeTrait(E->getTrait(),
7665 E->getLocStart(),
7666 Args,
7667 E->getLocEnd());
7668}
7669
7670template<typename Derived>
7671ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007672TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7673 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7674 if (!T)
7675 return ExprError();
7676
7677 if (!getDerived().AlwaysRebuild() &&
7678 T == E->getQueriedTypeSourceInfo())
7679 return SemaRef.Owned(E);
7680
7681 ExprResult SubExpr;
7682 {
7683 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7684 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7685 if (SubExpr.isInvalid())
7686 return ExprError();
7687
7688 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7689 return SemaRef.Owned(E);
7690 }
7691
7692 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7693 E->getLocStart(),
7694 T,
7695 SubExpr.get(),
7696 E->getLocEnd());
7697}
7698
7699template<typename Derived>
7700ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007701TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7702 ExprResult SubExpr;
7703 {
7704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7705 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7706 if (SubExpr.isInvalid())
7707 return ExprError();
7708
7709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7710 return SemaRef.Owned(E);
7711 }
7712
7713 return getDerived().RebuildExpressionTrait(
7714 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7715}
7716
7717template<typename Derived>
7718ExprResult
John McCall865d4472009-11-19 22:55:06 +00007719TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007720 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007721 NestedNameSpecifierLoc QualifierLoc
7722 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7723 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007724 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007725 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007726
John McCall43fed0d2010-11-12 08:19:04 +00007727 // TODO: If this is a conversion-function-id, verify that the
7728 // destination type name (if present) resolves the same way after
7729 // instantiation as it did in the local scope.
7730
Abramo Bagnara25777432010-08-11 22:01:17 +00007731 DeclarationNameInfo NameInfo
7732 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7733 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007735
John McCallf7a1a742009-11-24 19:00:30 +00007736 if (!E->hasExplicitTemplateArgs()) {
7737 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007738 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007739 // Note: it is sufficient to compare the Name component of NameInfo:
7740 // if name has not changed, DNLoc has not changed either.
7741 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007742 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007743
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007744 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007745 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007746 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007747 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007748 }
John McCalld5532b62009-11-23 01:53:49 +00007749
7750 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007751 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7752 E->getNumTemplateArgs(),
7753 TransArgs))
7754 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007755
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007756 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007757 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007758 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007759 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007760}
7761
7762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007763ExprResult
John McCall454feb92009-12-08 09:21:05 +00007764TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007765 // CXXConstructExprs are always implicit, so when we have a
7766 // 1-argument construction we just transform that argument.
7767 if (E->getNumArgs() == 1 ||
7768 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7769 return getDerived().TransformExpr(E->getArg(0));
7770
Douglas Gregorb98b1992009-08-11 05:31:07 +00007771 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7772
7773 QualType T = getDerived().TransformType(E->getType());
7774 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007775 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007776
7777 CXXConstructorDecl *Constructor
7778 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007779 getDerived().TransformDecl(E->getLocStart(),
7780 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007782 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007783
Douglas Gregorb98b1992009-08-11 05:31:07 +00007784 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007785 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007786 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7787 &ArgumentChanged))
7788 return ExprError();
7789
Douglas Gregorb98b1992009-08-11 05:31:07 +00007790 if (!getDerived().AlwaysRebuild() &&
7791 T == E->getType() &&
7792 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007793 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007794 // Mark the constructor as referenced.
7795 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007796 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007797 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007798 }
Mike Stump1eb44332009-09-09 15:08:12 +00007799
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007800 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7801 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007802 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007803 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007804 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007805 E->getConstructionKind(),
7806 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807}
Mike Stump1eb44332009-09-09 15:08:12 +00007808
Douglas Gregorb98b1992009-08-11 05:31:07 +00007809/// \brief Transform a C++ temporary-binding expression.
7810///
Douglas Gregor51326552009-12-24 18:51:59 +00007811/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7812/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007814ExprResult
John McCall454feb92009-12-08 09:21:05 +00007815TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007816 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
Mike Stump1eb44332009-09-09 15:08:12 +00007818
John McCall4765fa02010-12-06 08:20:24 +00007819/// \brief Transform a C++ expression that contains cleanups that should
7820/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821///
John McCall4765fa02010-12-06 08:20:24 +00007822/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007823/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007825ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007826TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007827 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828}
Mike Stump1eb44332009-09-09 15:08:12 +00007829
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007831ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007833 CXXTemporaryObjectExpr *E) {
7834 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7835 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007837
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838 CXXConstructorDecl *Constructor
7839 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007840 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007841 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007844
Douglas Gregorb98b1992009-08-11 05:31:07 +00007845 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007846 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007847 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007848 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7849 &ArgumentChanged))
7850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007851
Douglas Gregorb98b1992009-08-11 05:31:07 +00007852 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007853 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007855 !ArgumentChanged) {
7856 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007857 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007858 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007859 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007860
7861 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7862 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007863 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007864 E->getLocEnd());
7865}
Mike Stump1eb44332009-09-09 15:08:12 +00007866
Douglas Gregorb98b1992009-08-11 05:31:07 +00007867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007868ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007869TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007870 // Create the local class that will describe the lambda.
7871 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007872 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7873 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007874 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7875
7876 // Transform the type of the lambda parameters and start the definition of
7877 // the lambda itself.
7878 TypeSourceInfo *MethodTy
7879 = TransformType(E->getCallOperator()->getTypeSourceInfo());
7880 if (!MethodTy)
7881 return ExprError();
7882
Douglas Gregorc6889e72012-02-14 22:28:59 +00007883 // Transform lambda parameters.
7884 bool Invalid = false;
7885 llvm::SmallVector<QualType, 4> ParamTypes;
7886 llvm::SmallVector<ParmVarDecl *, 4> Params;
7887 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7888 E->getCallOperator()->param_begin(),
7889 E->getCallOperator()->param_size(),
7890 0, ParamTypes, &Params))
7891 Invalid = true;
7892
Douglas Gregordfca6f52012-02-13 22:00:16 +00007893 // Build the call operator.
Douglas Gregorf54486a2012-04-04 17:40:10 +00007894 // Note: Once a lambda mangling number and context declaration have been
7895 // assigned, they never change.
7896 unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber();
7897 Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl();
Douglas Gregordfca6f52012-02-13 22:00:16 +00007898 CXXMethodDecl *CallOperator
7899 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
7900 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007901 E->getCallOperator()->getLocEnd(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00007902 Params, ManglingNumber, ContextDecl);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007903 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
7904
Douglas Gregord5387e82012-02-14 00:00:48 +00007905 // FIXME: Instantiation-specific.
7906 CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(),
7907 TSK_ImplicitInstantiation);
7908
7909 // Introduce the context of the call operator.
7910 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7911
Douglas Gregordfca6f52012-02-13 22:00:16 +00007912 // Enter the scope of the lambda.
7913 sema::LambdaScopeInfo *LSI
7914 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7915 E->getCaptureDefault(),
7916 E->hasExplicitParameters(),
7917 E->hasExplicitResultType(),
7918 E->isMutable());
7919
7920 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00007921 bool FinishedExplicitCaptures = false;
7922 for (LambdaExpr::capture_iterator C = E->capture_begin(),
7923 CEnd = E->capture_end();
7924 C != CEnd; ++C) {
7925 // When we hit the first implicit capture, tell Sema that we've finished
7926 // the list of explicit captures.
7927 if (!FinishedExplicitCaptures && C->isImplicit()) {
7928 getSema().finishLambdaExplicitCaptures(LSI);
7929 FinishedExplicitCaptures = true;
7930 }
7931
7932 // Capturing 'this' is trivial.
7933 if (C->capturesThis()) {
7934 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7935 continue;
7936 }
7937
Douglas Gregora7365242012-02-14 19:27:52 +00007938 // Determine the capture kind for Sema.
7939 Sema::TryCaptureKind Kind
7940 = C->isImplicit()? Sema::TryCapture_Implicit
7941 : C->getCaptureKind() == LCK_ByCopy
7942 ? Sema::TryCapture_ExplicitByVal
7943 : Sema::TryCapture_ExplicitByRef;
7944 SourceLocation EllipsisLoc;
7945 if (C->isPackExpansion()) {
7946 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7947 bool ShouldExpand = false;
7948 bool RetainExpansion = false;
7949 llvm::Optional<unsigned> NumExpansions;
7950 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7951 C->getLocation(),
7952 Unexpanded,
7953 ShouldExpand, RetainExpansion,
7954 NumExpansions))
7955 return ExprError();
7956
7957 if (ShouldExpand) {
7958 // The transform has determined that we should perform an expansion;
7959 // transform and capture each of the arguments.
7960 // expansion of the pattern. Do so.
7961 VarDecl *Pack = C->getCapturedVar();
7962 for (unsigned I = 0; I != *NumExpansions; ++I) {
7963 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7964 VarDecl *CapturedVar
7965 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7966 Pack));
7967 if (!CapturedVar) {
7968 Invalid = true;
7969 continue;
7970 }
7971
7972 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007973 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregora7365242012-02-14 19:27:52 +00007974 }
7975 continue;
7976 }
7977
7978 EllipsisLoc = C->getEllipsisLoc();
7979 }
7980
Douglas Gregordfca6f52012-02-13 22:00:16 +00007981 // Transform the captured variable.
7982 VarDecl *CapturedVar
7983 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
7984 C->getCapturedVar()));
7985 if (!CapturedVar) {
7986 Invalid = true;
7987 continue;
7988 }
Douglas Gregora7365242012-02-14 19:27:52 +00007989
Douglas Gregordfca6f52012-02-13 22:00:16 +00007990 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007991 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007992 }
7993 if (!FinishedExplicitCaptures)
7994 getSema().finishLambdaExplicitCaptures(LSI);
7995
Douglas Gregordfca6f52012-02-13 22:00:16 +00007996
7997 // Enter a new evaluation context to insulate the lambda from any
7998 // cleanups from the enclosing full-expression.
7999 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
8000
8001 if (Invalid) {
8002 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8003 /*IsInstantiation=*/true);
8004 return ExprError();
8005 }
8006
8007 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008008 StmtResult Body = getDerived().TransformStmt(E->getBody());
8009 if (Body.isInvalid()) {
8010 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
8011 /*IsInstantiation=*/true);
8012 return ExprError();
8013 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008014
Douglas Gregordfca6f52012-02-13 22:00:16 +00008015 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008016 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008017}
8018
8019template<typename Derived>
8020ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008021TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008022 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008023 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8024 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008026
Douglas Gregorb98b1992009-08-11 05:31:07 +00008027 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008028 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008029 Args.reserve(E->arg_size());
8030 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
8031 &ArgumentChanged))
8032 return ExprError();
8033
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008035 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008037 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008038
Douglas Gregorb98b1992009-08-11 05:31:07 +00008039 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008040 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008041 E->getLParenLoc(),
8042 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008043 E->getRParenLoc());
8044}
Mike Stump1eb44332009-09-09 15:08:12 +00008045
Douglas Gregorb98b1992009-08-11 05:31:07 +00008046template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008047ExprResult
John McCall865d4472009-11-19 22:55:06 +00008048TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008049 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008051 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008052 Expr *OldBase;
8053 QualType BaseType;
8054 QualType ObjectType;
8055 if (!E->isImplicitAccess()) {
8056 OldBase = E->getBase();
8057 Base = getDerived().TransformExpr(OldBase);
8058 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008060
John McCallaa81e162009-12-01 22:10:20 +00008061 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008062 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008063 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008064 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008065 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008066 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008067 ObjectTy,
8068 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008069 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008070 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008071
John McCallb3d87482010-08-24 05:47:05 +00008072 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008073 BaseType = ((Expr*) Base.get())->getType();
8074 } else {
8075 OldBase = 0;
8076 BaseType = getDerived().TransformType(E->getBaseType());
8077 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8078 }
Mike Stump1eb44332009-09-09 15:08:12 +00008079
Douglas Gregor6cd21982009-10-20 05:58:46 +00008080 // Transform the first part of the nested-name-specifier that qualifies
8081 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008082 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008083 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008084 E->getFirstQualifierFoundInScope(),
8085 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008086
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008087 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008088 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008089 QualifierLoc
8090 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8091 ObjectType,
8092 FirstQualifierInScope);
8093 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008094 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008095 }
Mike Stump1eb44332009-09-09 15:08:12 +00008096
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008097 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8098
John McCall43fed0d2010-11-12 08:19:04 +00008099 // TODO: If this is a conversion-function-id, verify that the
8100 // destination type name (if present) resolves the same way after
8101 // instantiation as it did in the local scope.
8102
Abramo Bagnara25777432010-08-11 22:01:17 +00008103 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008104 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008105 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008107
John McCallaa81e162009-12-01 22:10:20 +00008108 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008109 // This is a reference to a member without an explicitly-specified
8110 // template argument list. Optimize for this common case.
8111 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008112 Base.get() == OldBase &&
8113 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008114 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008115 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008116 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008117 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008118
John McCall9ae2f072010-08-23 23:25:46 +00008119 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008120 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008121 E->isArrow(),
8122 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008123 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008124 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008125 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008126 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008127 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008128 }
8129
John McCalld5532b62009-11-23 01:53:49 +00008130 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008131 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8132 E->getNumTemplateArgs(),
8133 TransArgs))
8134 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008135
John McCall9ae2f072010-08-23 23:25:46 +00008136 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008137 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008138 E->isArrow(),
8139 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008140 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008141 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008142 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008143 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008144 &TransArgs);
8145}
8146
8147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008148ExprResult
John McCall454feb92009-12-08 09:21:05 +00008149TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008150 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008151 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008152 QualType BaseType;
8153 if (!Old->isImplicitAccess()) {
8154 Base = getDerived().TransformExpr(Old->getBase());
8155 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008156 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008157 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8158 Old->isArrow());
8159 if (Base.isInvalid())
8160 return ExprError();
8161 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008162 } else {
8163 BaseType = getDerived().TransformType(Old->getBaseType());
8164 }
John McCall129e2df2009-11-30 22:42:35 +00008165
Douglas Gregor4c9be892011-02-28 20:01:57 +00008166 NestedNameSpecifierLoc QualifierLoc;
8167 if (Old->getQualifierLoc()) {
8168 QualifierLoc
8169 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8170 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008171 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008172 }
8173
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008174 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8175
Abramo Bagnara25777432010-08-11 22:01:17 +00008176 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008177 Sema::LookupOrdinaryName);
8178
8179 // Transform all the decls.
8180 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8181 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008182 NamedDecl *InstD = static_cast<NamedDecl*>(
8183 getDerived().TransformDecl(Old->getMemberLoc(),
8184 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008185 if (!InstD) {
8186 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8187 // This can happen because of dependent hiding.
8188 if (isa<UsingShadowDecl>(*I))
8189 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008190 else {
8191 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008192 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008193 }
John McCall9f54ad42009-12-10 09:41:52 +00008194 }
John McCall129e2df2009-11-30 22:42:35 +00008195
8196 // Expand using declarations.
8197 if (isa<UsingDecl>(InstD)) {
8198 UsingDecl *UD = cast<UsingDecl>(InstD);
8199 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8200 E = UD->shadow_end(); I != E; ++I)
8201 R.addDecl(*I);
8202 continue;
8203 }
8204
8205 R.addDecl(InstD);
8206 }
8207
8208 R.resolveKind();
8209
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008210 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008211 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00008212 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008213 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008214 Old->getMemberLoc(),
8215 Old->getNamingClass()));
8216 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008217 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008218
Douglas Gregor66c45152010-04-27 16:10:10 +00008219 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008220 }
Sean Huntc3021132010-05-05 15:23:54 +00008221
John McCall129e2df2009-11-30 22:42:35 +00008222 TemplateArgumentListInfo TransArgs;
8223 if (Old->hasExplicitTemplateArgs()) {
8224 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8225 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008226 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8227 Old->getNumTemplateArgs(),
8228 TransArgs))
8229 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008230 }
John McCallc2233c52010-01-15 08:34:02 +00008231
8232 // FIXME: to do this check properly, we will need to preserve the
8233 // first-qualifier-in-scope here, just in case we had a dependent
8234 // base (and therefore couldn't do the check) and a
8235 // nested-name-qualifier (and therefore could do the lookup).
8236 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00008237
John McCall9ae2f072010-08-23 23:25:46 +00008238 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008239 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008240 Old->getOperatorLoc(),
8241 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008242 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008243 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008244 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008245 R,
8246 (Old->hasExplicitTemplateArgs()
8247 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008248}
8249
8250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008251ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008252TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008253 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008254 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8255 if (SubExpr.isInvalid())
8256 return ExprError();
8257
8258 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008259 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008260
8261 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8262}
8263
8264template<typename Derived>
8265ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008266TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008267 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8268 if (Pattern.isInvalid())
8269 return ExprError();
8270
8271 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8272 return SemaRef.Owned(E);
8273
Douglas Gregor67fd1252011-01-14 21:20:45 +00008274 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8275 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008276}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008277
8278template<typename Derived>
8279ExprResult
8280TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8281 // If E is not value-dependent, then nothing will change when we transform it.
8282 // Note: This is an instantiation-centric view.
8283 if (!E->isValueDependent())
8284 return SemaRef.Owned(E);
8285
8286 // Note: None of the implementations of TryExpandParameterPacks can ever
8287 // produce a diagnostic when given only a single unexpanded parameter pack,
8288 // so
8289 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8290 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008291 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008292 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00008293 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008294 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008295 ShouldExpand, RetainExpansion,
8296 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008297 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00008298
Douglas Gregor089e8932011-10-10 18:59:29 +00008299 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008300 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00008301
8302 NamedDecl *Pack = E->getPack();
8303 if (!ShouldExpand) {
8304 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
8305 Pack));
8306 if (!Pack)
8307 return ExprError();
8308 }
8309
Douglas Gregoree8aff02011-01-04 17:33:58 +00008310
8311 // We now know the length of the parameter pack, so build a new expression
8312 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00008313 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00008314 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008315 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008316}
8317
Douglas Gregorbe230c32011-01-03 17:17:50 +00008318template<typename Derived>
8319ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008320TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8321 SubstNonTypeTemplateParmPackExpr *E) {
8322 // Default behavior is to do nothing with this transformation.
8323 return SemaRef.Owned(E);
8324}
8325
8326template<typename Derived>
8327ExprResult
John McCall91a57552011-07-15 05:09:51 +00008328TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8329 SubstNonTypeTemplateParmExpr *E) {
8330 // Default behavior is to do nothing with this transformation.
8331 return SemaRef.Owned(E);
8332}
8333
8334template<typename Derived>
8335ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008336TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8337 MaterializeTemporaryExpr *E) {
8338 return getDerived().TransformExpr(E->GetTemporaryExpr());
8339}
8340
8341template<typename Derived>
8342ExprResult
John McCall454feb92009-12-08 09:21:05 +00008343TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008344 return SemaRef.MaybeBindToTemporary(E);
8345}
8346
8347template<typename Derived>
8348ExprResult
8349TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008350 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008351}
8352
8353template<typename Derived>
8354ExprResult
8355TreeTransform<Derived>::TransformObjCNumericLiteral(ObjCNumericLiteral *E) {
8356 return SemaRef.MaybeBindToTemporary(E);
8357}
8358
8359template<typename Derived>
8360ExprResult
8361TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8362 // Transform each of the elements.
8363 llvm::SmallVector<Expr *, 8> Elements;
8364 bool ArgChanged = false;
8365 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
8366 /*IsCall=*/false, Elements, &ArgChanged))
8367 return ExprError();
8368
8369 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8370 return SemaRef.MaybeBindToTemporary(E);
8371
8372 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8373 Elements.data(),
8374 Elements.size());
8375}
8376
8377template<typename Derived>
8378ExprResult
8379TreeTransform<Derived>::TransformObjCDictionaryLiteral(
8380 ObjCDictionaryLiteral *E) {
8381 // Transform each of the elements.
8382 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8383 bool ArgChanged = false;
8384 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8385 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
8386
8387 if (OrigElement.isPackExpansion()) {
8388 // This key/value element is a pack expansion.
8389 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8390 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8391 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8392 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8393
8394 // Determine whether the set of unexpanded parameter packs can
8395 // and should be expanded.
8396 bool Expand = true;
8397 bool RetainExpansion = false;
8398 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8399 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8400 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8401 OrigElement.Value->getLocEnd());
8402 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8403 PatternRange,
8404 Unexpanded,
8405 Expand, RetainExpansion,
8406 NumExpansions))
8407 return ExprError();
8408
8409 if (!Expand) {
8410 // The transform has determined that we should perform a simple
8411 // transformation on the pack expansion, producing another pack
8412 // expansion.
8413 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8414 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8415 if (Key.isInvalid())
8416 return ExprError();
8417
8418 if (Key.get() != OrigElement.Key)
8419 ArgChanged = true;
8420
8421 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8422 if (Value.isInvalid())
8423 return ExprError();
8424
8425 if (Value.get() != OrigElement.Value)
8426 ArgChanged = true;
8427
8428 ObjCDictionaryElement Expansion = {
8429 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8430 };
8431 Elements.push_back(Expansion);
8432 continue;
8433 }
8434
8435 // Record right away that the argument was changed. This needs
8436 // to happen even if the array expands to nothing.
8437 ArgChanged = true;
8438
8439 // The transform has determined that we should perform an elementwise
8440 // expansion of the pattern. Do so.
8441 for (unsigned I = 0; I != *NumExpansions; ++I) {
8442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8443 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8444 if (Key.isInvalid())
8445 return ExprError();
8446
8447 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8448 if (Value.isInvalid())
8449 return ExprError();
8450
8451 ObjCDictionaryElement Element = {
8452 Key.get(), Value.get(), SourceLocation(), NumExpansions
8453 };
8454
8455 // If any unexpanded parameter packs remain, we still have a
8456 // pack expansion.
8457 if (Key.get()->containsUnexpandedParameterPack() ||
8458 Value.get()->containsUnexpandedParameterPack())
8459 Element.EllipsisLoc = OrigElement.EllipsisLoc;
8460
8461 Elements.push_back(Element);
8462 }
8463
8464 // We've finished with this pack expansion.
8465 continue;
8466 }
8467
8468 // Transform and check key.
8469 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8470 if (Key.isInvalid())
8471 return ExprError();
8472
8473 if (Key.get() != OrigElement.Key)
8474 ArgChanged = true;
8475
8476 // Transform and check value.
8477 ExprResult Value
8478 = getDerived().TransformExpr(OrigElement.Value);
8479 if (Value.isInvalid())
8480 return ExprError();
8481
8482 if (Value.get() != OrigElement.Value)
8483 ArgChanged = true;
8484
8485 ObjCDictionaryElement Element = {
8486 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8487 };
8488 Elements.push_back(Element);
8489 }
8490
8491 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8492 return SemaRef.MaybeBindToTemporary(E);
8493
8494 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8495 Elements.data(),
8496 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008497}
8498
Mike Stump1eb44332009-09-09 15:08:12 +00008499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008500ExprResult
John McCall454feb92009-12-08 09:21:05 +00008501TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008502 TypeSourceInfo *EncodedTypeInfo
8503 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8504 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008506
Douglas Gregorb98b1992009-08-11 05:31:07 +00008507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008508 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008509 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008510
8511 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008512 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008513 E->getRParenLoc());
8514}
Mike Stump1eb44332009-09-09 15:08:12 +00008515
Douglas Gregorb98b1992009-08-11 05:31:07 +00008516template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008517ExprResult TreeTransform<Derived>::
8518TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8519 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8520 if (result.isInvalid()) return ExprError();
8521 Expr *subExpr = result.take();
8522
8523 if (!getDerived().AlwaysRebuild() &&
8524 subExpr == E->getSubExpr())
8525 return SemaRef.Owned(E);
8526
8527 return SemaRef.Owned(new(SemaRef.Context)
8528 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8529}
8530
8531template<typename Derived>
8532ExprResult TreeTransform<Derived>::
8533TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
8534 TypeSourceInfo *TSInfo
8535 = getDerived().TransformType(E->getTypeInfoAsWritten());
8536 if (!TSInfo)
8537 return ExprError();
8538
8539 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
8540 if (Result.isInvalid())
8541 return ExprError();
8542
8543 if (!getDerived().AlwaysRebuild() &&
8544 TSInfo == E->getTypeInfoAsWritten() &&
8545 Result.get() == E->getSubExpr())
8546 return SemaRef.Owned(E);
8547
8548 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8549 E->getBridgeKeywordLoc(), TSInfo,
8550 Result.get());
8551}
8552
8553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008554ExprResult
John McCall454feb92009-12-08 09:21:05 +00008555TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008556 // Transform arguments.
8557 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008558 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008559 Args.reserve(E->getNumArgs());
8560 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8561 &ArgChanged))
8562 return ExprError();
8563
Douglas Gregor92e986e2010-04-22 16:44:27 +00008564 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8565 // Class message: transform the receiver type.
8566 TypeSourceInfo *ReceiverTypeInfo
8567 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8568 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008569 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008570
Douglas Gregor92e986e2010-04-22 16:44:27 +00008571 // If nothing changed, just retain the existing message send.
8572 if (!getDerived().AlwaysRebuild() &&
8573 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008574 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008575
8576 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008577 SmallVector<SourceLocation, 16> SelLocs;
8578 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008579 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8580 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008581 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008582 E->getMethodDecl(),
8583 E->getLeftLoc(),
8584 move_arg(Args),
8585 E->getRightLoc());
8586 }
8587
8588 // Instance message: transform the receiver
8589 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8590 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008591 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008592 = getDerived().TransformExpr(E->getInstanceReceiver());
8593 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008594 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008595
8596 // If nothing changed, just retain the existing message send.
8597 if (!getDerived().AlwaysRebuild() &&
8598 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008599 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008600
Douglas Gregor92e986e2010-04-22 16:44:27 +00008601 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008602 SmallVector<SourceLocation, 16> SelLocs;
8603 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008604 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008605 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008606 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008607 E->getMethodDecl(),
8608 E->getLeftLoc(),
8609 move_arg(Args),
8610 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008611}
8612
Mike Stump1eb44332009-09-09 15:08:12 +00008613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008614ExprResult
John McCall454feb92009-12-08 09:21:05 +00008615TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008616 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008617}
8618
Mike Stump1eb44332009-09-09 15:08:12 +00008619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008620ExprResult
John McCall454feb92009-12-08 09:21:05 +00008621TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008622 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008623}
8624
Mike Stump1eb44332009-09-09 15:08:12 +00008625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008626ExprResult
John McCall454feb92009-12-08 09:21:05 +00008627TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008628 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008629 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008630 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008631 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008632
8633 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008634
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008635 // If nothing changed, just retain the existing expression.
8636 if (!getDerived().AlwaysRebuild() &&
8637 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008638 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008639
John McCall9ae2f072010-08-23 23:25:46 +00008640 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008641 E->getLocation(),
8642 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008643}
8644
Mike Stump1eb44332009-09-09 15:08:12 +00008645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008646ExprResult
John McCall454feb92009-12-08 09:21:05 +00008647TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008648 // 'super' and types never change. Property never changes. Just
8649 // retain the existing expression.
8650 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008651 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008652
Douglas Gregore3303542010-04-26 20:47:02 +00008653 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008654 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008655 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008656 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008657
Douglas Gregore3303542010-04-26 20:47:02 +00008658 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008659
Douglas Gregore3303542010-04-26 20:47:02 +00008660 // If nothing changed, just retain the existing expression.
8661 if (!getDerived().AlwaysRebuild() &&
8662 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008663 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664
John McCall12f78a62010-12-02 01:19:52 +00008665 if (E->isExplicitProperty())
8666 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8667 E->getExplicitProperty(),
8668 E->getLocation());
8669
8670 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008671 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008672 E->getImplicitPropertyGetter(),
8673 E->getImplicitPropertySetter(),
8674 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008675}
8676
Mike Stump1eb44332009-09-09 15:08:12 +00008677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008678ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008679TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8680 // Transform the base expression.
8681 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8682 if (Base.isInvalid())
8683 return ExprError();
8684
8685 // Transform the key expression.
8686 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8687 if (Key.isInvalid())
8688 return ExprError();
8689
8690 // If nothing changed, just retain the existing expression.
8691 if (!getDerived().AlwaysRebuild() &&
8692 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8693 return SemaRef.Owned(E);
8694
8695 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
8696 Base.get(), Key.get(),
8697 E->getAtIndexMethodDecl(),
8698 E->setAtIndexMethodDecl());
8699}
8700
8701template<typename Derived>
8702ExprResult
John McCall454feb92009-12-08 09:21:05 +00008703TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008704 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008705 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008706 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008707 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008708
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008709 // If nothing changed, just retain the existing expression.
8710 if (!getDerived().AlwaysRebuild() &&
8711 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008712 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008713
John McCall9ae2f072010-08-23 23:25:46 +00008714 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008715 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008716}
8717
Mike Stump1eb44332009-09-09 15:08:12 +00008718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008719ExprResult
John McCall454feb92009-12-08 09:21:05 +00008720TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008721 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008722 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008723 SubExprs.reserve(E->getNumSubExprs());
8724 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8725 SubExprs, &ArgumentChanged))
8726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008727
Douglas Gregorb98b1992009-08-11 05:31:07 +00008728 if (!getDerived().AlwaysRebuild() &&
8729 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008730 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008731
Douglas Gregorb98b1992009-08-11 05:31:07 +00008732 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8733 move_arg(SubExprs),
8734 E->getRParenLoc());
8735}
8736
Mike Stump1eb44332009-09-09 15:08:12 +00008737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008738ExprResult
John McCall454feb92009-12-08 09:21:05 +00008739TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008740 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008741
John McCallc6ac9c32011-02-04 18:33:18 +00008742 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8743 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8744
8745 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008746 blockScope->TheDecl->setBlockMissingReturnType(
8747 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008748
Chris Lattner686775d2011-07-20 06:58:45 +00008749 SmallVector<ParmVarDecl*, 4> params;
8750 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008751
8752 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008753 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8754 oldBlock->param_begin(),
8755 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008756 0, paramTypes, &params)) {
8757 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008758 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008759 }
John McCallc6ac9c32011-02-04 18:33:18 +00008760
8761 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008762 QualType exprResultType =
8763 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008764
8765 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008766 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008767 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008768 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008769 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008770 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008771 return ExprError();
8772 }
John McCall711c52b2011-01-05 12:14:39 +00008773
John McCallc6ac9c32011-02-04 18:33:18 +00008774 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008775 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008776 paramTypes.data(),
8777 paramTypes.size(),
8778 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008779 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008780 exprFunctionType->getExtInfo());
8781 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008782
8783 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008784 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008785 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008786
8787 if (!oldBlock->blockMissingReturnType()) {
8788 blockScope->HasImplicitReturnType = false;
8789 blockScope->ReturnType = exprResultType;
8790 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008791
John McCall711c52b2011-01-05 12:14:39 +00008792 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008793 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008794 if (body.isInvalid()) {
8795 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008796 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008797 }
John McCall711c52b2011-01-05 12:14:39 +00008798
John McCallc6ac9c32011-02-04 18:33:18 +00008799#ifndef NDEBUG
8800 // In builds with assertions, make sure that we captured everything we
8801 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008802 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8803 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8804 e = oldBlock->capture_end(); i != e; ++i) {
8805 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008806
Douglas Gregorfc921372011-05-20 15:32:55 +00008807 // Ignore parameter packs.
8808 if (isa<ParmVarDecl>(oldCapture) &&
8809 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8810 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008811
Douglas Gregorfc921372011-05-20 15:32:55 +00008812 VarDecl *newCapture =
8813 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8814 oldCapture));
8815 assert(blockScope->CaptureMap.count(newCapture));
8816 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008817 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008818 }
8819#endif
8820
8821 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8822 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008823}
8824
Mike Stump1eb44332009-09-09 15:08:12 +00008825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008826ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008827TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008828 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008829}
Eli Friedman276b0612011-10-11 02:20:01 +00008830
8831template<typename Derived>
8832ExprResult
8833TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008834 QualType RetTy = getDerived().TransformType(E->getType());
8835 bool ArgumentChanged = false;
8836 ASTOwningVector<Expr*> SubExprs(SemaRef);
8837 SubExprs.reserve(E->getNumSubExprs());
8838 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8839 SubExprs, &ArgumentChanged))
8840 return ExprError();
8841
8842 if (!getDerived().AlwaysRebuild() &&
8843 !ArgumentChanged)
8844 return SemaRef.Owned(E);
8845
8846 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8847 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008848}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008849
Douglas Gregorb98b1992009-08-11 05:31:07 +00008850//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008851// Type reconstruction
8852//===----------------------------------------------------------------------===//
8853
Mike Stump1eb44332009-09-09 15:08:12 +00008854template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008855QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8856 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008857 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008858 getDerived().getBaseEntity());
8859}
8860
Mike Stump1eb44332009-09-09 15:08:12 +00008861template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008862QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8863 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008864 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008865 getDerived().getBaseEntity());
8866}
8867
Mike Stump1eb44332009-09-09 15:08:12 +00008868template<typename Derived>
8869QualType
John McCall85737a72009-10-30 00:06:24 +00008870TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8871 bool WrittenAsLValue,
8872 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008873 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008874 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008875}
8876
8877template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008878QualType
John McCall85737a72009-10-30 00:06:24 +00008879TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8880 QualType ClassType,
8881 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008882 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008883 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008884}
8885
8886template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008887QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008888TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8889 ArrayType::ArraySizeModifier SizeMod,
8890 const llvm::APInt *Size,
8891 Expr *SizeExpr,
8892 unsigned IndexTypeQuals,
8893 SourceRange BracketsRange) {
8894 if (SizeExpr || !Size)
8895 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8896 IndexTypeQuals, BracketsRange,
8897 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008898
8899 QualType Types[] = {
8900 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8901 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8902 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008903 };
8904 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8905 QualType SizeType;
8906 for (unsigned I = 0; I != NumTypes; ++I)
8907 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8908 SizeType = Types[I];
8909 break;
8910 }
Mike Stump1eb44332009-09-09 15:08:12 +00008911
Eli Friedman01f276d2012-01-25 23:20:27 +00008912 // Note that we can return a VariableArrayType here in the case where
8913 // the element type was a dependent VariableArrayType.
8914 IntegerLiteral *ArraySize
8915 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8916 /*FIXME*/BracketsRange.getBegin());
8917 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008918 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008919 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008920}
Mike Stump1eb44332009-09-09 15:08:12 +00008921
Douglas Gregor577f75a2009-08-04 16:50:30 +00008922template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008923QualType
8924TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008925 ArrayType::ArraySizeModifier SizeMod,
8926 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008927 unsigned IndexTypeQuals,
8928 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008929 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008930 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008931}
8932
8933template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008934QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008935TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008936 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008937 unsigned IndexTypeQuals,
8938 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008939 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008940 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941}
Mike Stump1eb44332009-09-09 15:08:12 +00008942
Douglas Gregor577f75a2009-08-04 16:50:30 +00008943template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008944QualType
8945TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008946 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008947 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948 unsigned IndexTypeQuals,
8949 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008950 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008951 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952 IndexTypeQuals, BracketsRange);
8953}
8954
8955template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008956QualType
8957TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008959 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008960 unsigned IndexTypeQuals,
8961 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008962 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008963 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 IndexTypeQuals, BracketsRange);
8965}
8966
8967template<typename Derived>
8968QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008969 unsigned NumElements,
8970 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008971 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008972 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008973}
Mike Stump1eb44332009-09-09 15:08:12 +00008974
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975template<typename Derived>
8976QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8977 unsigned NumElements,
8978 SourceLocation AttributeLoc) {
8979 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8980 NumElements, true);
8981 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008982 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8983 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008984 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008985}
Mike Stump1eb44332009-09-09 15:08:12 +00008986
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008988QualType
8989TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008990 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008992 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008993}
Mike Stump1eb44332009-09-09 15:08:12 +00008994
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995template<typename Derived>
8996QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008997 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008998 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008999 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009000 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009001 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009002 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009003 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009004 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009005 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009007 getDerived().getBaseEntity(),
9008 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009}
Mike Stump1eb44332009-09-09 15:08:12 +00009010
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009012QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9013 return SemaRef.Context.getFunctionNoProtoType(T);
9014}
9015
9016template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009017QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9018 assert(D && "no decl found");
9019 if (D->isInvalidDecl()) return QualType();
9020
Douglas Gregor92e986e2010-04-22 16:44:27 +00009021 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009022 TypeDecl *Ty;
9023 if (isa<UsingDecl>(D)) {
9024 UsingDecl *Using = cast<UsingDecl>(D);
9025 assert(Using->isTypeName() &&
9026 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9027
9028 // A valid resolved using typename decl points to exactly one type decl.
9029 assert(++Using->shadow_begin() == Using->shadow_end());
9030 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00009031
John McCalled976492009-12-04 22:46:56 +00009032 } else {
9033 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9034 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9035 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9036 }
9037
9038 return SemaRef.Context.getTypeDeclType(Ty);
9039}
9040
9041template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009042QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9043 SourceLocation Loc) {
9044 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045}
9046
9047template<typename Derived>
9048QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9049 return SemaRef.Context.getTypeOfType(Underlying);
9050}
9051
9052template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009053QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9054 SourceLocation Loc) {
9055 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009056}
9057
9058template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009059QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9060 UnaryTransformType::UTTKind UKind,
9061 SourceLocation Loc) {
9062 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9063}
9064
9065template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009066QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009067 TemplateName Template,
9068 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009069 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009070 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071}
Mike Stump1eb44332009-09-09 15:08:12 +00009072
Douglas Gregordcee1a12009-08-06 05:28:30 +00009073template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009074QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9075 SourceLocation KWLoc) {
9076 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9077}
9078
9079template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009080TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009081TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009082 bool TemplateKW,
9083 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009084 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009085 Template);
9086}
9087
9088template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009089TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009090TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9091 const IdentifierInfo &Name,
9092 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009093 QualType ObjectType,
9094 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009095 UnqualifiedId TemplateName;
9096 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009097 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009098 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009099 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009100 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009101 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009102 /*EnteringContext=*/false,
9103 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009104 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009105}
Mike Stump1eb44332009-09-09 15:08:12 +00009106
Douglas Gregorb98b1992009-08-11 05:31:07 +00009107template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009108TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009109TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009110 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009111 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009112 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009113 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009114 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009115 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009116 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009117 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 Sema::TemplateTy Template;
9119 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009120 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009121 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009122 /*EnteringContext=*/false,
9123 Template);
9124 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009125}
Sean Huntc3021132010-05-05 15:23:54 +00009126
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009128ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009129TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9130 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009131 Expr *OrigCallee,
9132 Expr *First,
9133 Expr *Second) {
9134 Expr *Callee = OrigCallee->IgnoreParenCasts();
9135 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009136
Douglas Gregorb98b1992009-08-11 05:31:07 +00009137 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009138 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009139 if (!First->getType()->isOverloadableType() &&
9140 !Second->getType()->isOverloadableType())
9141 return getSema().CreateBuiltinArraySubscriptExpr(First,
9142 Callee->getLocStart(),
9143 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009144 } else if (Op == OO_Arrow) {
9145 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009146 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9147 } else if (Second == 0 || isPostIncDec) {
9148 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009149 // The argument is not of overloadable type, so try to create a
9150 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009151 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009152 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009153
John McCall9ae2f072010-08-23 23:25:46 +00009154 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009155 }
9156 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009157 if (!First->getType()->isOverloadableType() &&
9158 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009159 // Neither of the arguments is an overloadable type, so try to
9160 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009161 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009162 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009163 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009164 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009166
Douglas Gregorb98b1992009-08-11 05:31:07 +00009167 return move(Result);
9168 }
9169 }
Mike Stump1eb44332009-09-09 15:08:12 +00009170
9171 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009173 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009174
John McCall9ae2f072010-08-23 23:25:46 +00009175 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009176 assert(ULE->requiresADL());
9177
9178 // FIXME: Do we have to check
9179 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009180 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009181 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009182 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009183 }
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009186 Expr *Args[2] = { First, Second };
9187 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009188
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189 // Create the overloaded operator invocation for unary operators.
9190 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009191 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009192 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009193 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009194 }
Mike Stump1eb44332009-09-09 15:08:12 +00009195
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009196 if (Op == OO_Subscript) {
9197 SourceLocation LBrace;
9198 SourceLocation RBrace;
9199
9200 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9201 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9202 LBrace = SourceLocation::getFromRawEncoding(
9203 NameLoc.CXXOperatorName.BeginOpNameLoc);
9204 RBrace = SourceLocation::getFromRawEncoding(
9205 NameLoc.CXXOperatorName.EndOpNameLoc);
9206 } else {
9207 LBrace = Callee->getLocStart();
9208 RBrace = OpLoc;
9209 }
9210
9211 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9212 First, Second);
9213 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009214
Douglas Gregorb98b1992009-08-11 05:31:07 +00009215 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009216 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009217 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009218 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9219 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009221
Mike Stump1eb44332009-09-09 15:08:12 +00009222 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009223}
Mike Stump1eb44332009-09-09 15:08:12 +00009224
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009226ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009227TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009228 SourceLocation OperatorLoc,
9229 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009230 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009231 TypeSourceInfo *ScopeType,
9232 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009233 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009234 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009235 QualType BaseType = Base->getType();
9236 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009237 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00009238 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009239 !BaseType->getAs<PointerType>()->getPointeeType()
9240 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009241 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009242 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009243 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009244 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009245 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009246 /*FIXME?*/true);
9247 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009248
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009249 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009250 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9251 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9252 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9253 NameInfo.setNamedTypeInfo(DestroyedType);
9254
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009255 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00009256
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009257 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009258 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009260 SS, TemplateKWLoc,
9261 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009262 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009263 /*TemplateArgs*/ 0);
9264}
9265
Douglas Gregor577f75a2009-08-04 16:50:30 +00009266} // end namespace clang
9267
9268#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H