blob: 6e69bdc512870f4ed4d734aa5412f9324ed0947a [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
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCall781472f2010-08-25 08:40:02 +000041using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000042
Douglas Gregor577f75a2009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump1eb44332009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump1eb44332009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000102
Douglas Gregord3731192011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000107
Douglas Gregord3731192011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000115
Douglas Gregordfca6f52012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000124
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 }
132
John McCall60d7b3a2010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000135
Douglas Gregor577f75a2009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the location of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000150 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// provide an alternative implementation that provides better location
152 /// information.
153 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// \brief Returns the name of the entity being transformed, if that
156 /// information was not available elsewhere in the AST.
157 ///
158 /// By default, returns an empty name. Subclasses can provide an alternative
159 /// implementation with a more precise name.
160 DeclarationName getBaseEntity() { return DeclarationName(); }
161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief Sets the "base" location and entity when that
163 /// information is known based on another transformation.
164 ///
165 /// By default, the source location and entity are ignored. Subclasses can
166 /// override this function to provide a customized implementation.
167 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 /// \brief RAII object that temporarily sets the base location and entity
170 /// used for reporting diagnostics in types.
171 class TemporaryBase {
172 TreeTransform &Self;
173 SourceLocation OldLocation;
174 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 public:
177 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000178 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 OldLocation = Self.getDerived().getBaseLocation();
180 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000181
Douglas Gregorae201f72011-01-25 17:51:48 +0000182 if (Location.isValid())
183 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Douglas Gregorb98b1992009-08-11 05:31:07 +0000186 ~TemporaryBase() {
187 Self.getDerived().setBase(OldLocation, OldEntity);
188 }
189 };
Mike Stump1eb44332009-09-09 15:08:12 +0000190
191 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 /// transformed.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000195 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// not change. For example, template instantiation need not traverse
197 /// non-dependent types.
198 bool AlreadyTransformed(QualType T) {
199 return T.isNull();
200 }
201
Douglas Gregor6eef5192009-12-14 19:27:10 +0000202 /// \brief Determine whether the given call argument should be dropped, e.g.,
203 /// because it is a default argument.
204 ///
205 /// Subclasses can provide an alternative implementation of this routine to
206 /// determine which kinds of call arguments get dropped. By default,
207 /// CXXDefaultArgument nodes are dropped (prior to transformation).
208 bool DropCallArgument(Expr *E) {
209 return E->isDefaultArgument();
210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000211
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000212 /// \brief Determine whether we should expand a pack expansion with the
213 /// given set of parameter packs into separate arguments by repeatedly
214 /// transforming the pattern.
215 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000216 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000217 /// Subclasses can override this routine to provide different behavior.
218 ///
219 /// \param EllipsisLoc The location of the ellipsis that identifies the
220 /// pack expansion.
221 ///
222 /// \param PatternRange The source range that covers the entire pattern of
223 /// the pack expansion.
224 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000225 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000226 /// pattern.
227 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000228 /// \param ShouldExpand Will be set to \c true if the transformer should
229 /// expand the corresponding pack expansions into separate arguments. When
230 /// set, \c NumExpansions must also be set.
231 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000232 /// \param RetainExpansion Whether the caller should add an unexpanded
233 /// pack expansion after all of the expanded arguments. This is used
234 /// when extending explicitly-specified template argument packs per
235 /// C++0x [temp.arg.explicit]p9.
236 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000237 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000238 /// the expanded form of the corresponding pack expansion. This is both an
239 /// input and an output parameter, which can be set by the caller if the
240 /// number of expansions is known a priori (e.g., due to a prior substitution)
241 /// and will be set by the callee when the number of expansions is known.
242 /// The callee must set this value when \c ShouldExpand is \c true; it may
243 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000244 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000245 /// \returns true if an error occurred (e.g., because the parameter packs
246 /// are to be instantiated with arguments of different lengths), false
247 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 /// must be set.
249 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
250 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000251 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000253 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000254 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000255 ShouldExpand = false;
256 return false;
257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000258
Douglas Gregord3731192011-01-10 07:32:04 +0000259 /// \brief "Forget" about the partially-substituted pack template argument,
260 /// when performing an instantiation that must preserve the parameter pack
261 /// use.
262 ///
263 /// This routine is meant to be overridden by the template instantiator.
264 TemplateArgument ForgetPartiallySubstitutedPack() {
265 return TemplateArgument();
266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000267
Douglas Gregord3731192011-01-10 07:32:04 +0000268 /// \brief "Remember" the partially-substituted pack template argument
269 /// after performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000274
Douglas Gregor12c9c002011-01-07 16:43:16 +0000275 /// \brief Note to the derived class when a function parameter pack is
276 /// being expanded.
277 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transforms the given type into another type.
280 ///
John McCalla2becad2009-10-21 00:40:46 +0000281 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000282 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000283 /// function. This is expensive, but we don't mind, because
284 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000285 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000286 ///
287 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000288 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
John McCalla2becad2009-10-21 00:40:46 +0000290 /// \brief Transforms the given type-with-location into a new
291 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 ///
John McCalla2becad2009-10-21 00:40:46 +0000293 /// By default, this routine transforms a type by delegating to the
294 /// appropriate TransformXXXType to build a new type. Subclasses
295 /// may override this function (to take over all type
296 /// transformations) or some set of the TransformXXXType functions
297 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000298 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000299
300 /// \brief Transform the given type-with-location into a new
301 /// type, collecting location information in the given builder
302 /// as necessary.
303 ///
John McCall43fed0d2010-11-12 08:19:04 +0000304 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000307 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000308 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000309 /// appropriate TransformXXXStmt function to transform a specific kind of
310 /// statement or the TransformExpr() function to transform an expression.
311 /// Subclasses may override this function to transform statements using some
312 /// other mechanism.
313 ///
314 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000315 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000316
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000317 /// \brief Transform the given statement.
318 ///
319 /// By default, this routine transforms a statement by delegating to the
320 /// appropriate TransformOMPXXXClause function to transform a specific kind
321 /// of clause. Subclasses may override this function to transform statements
322 /// using some other mechanism.
323 ///
324 /// \returns the transformed OpenMP clause.
325 OMPClause *TransformOMPClause(OMPClause *S);
326
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000327 /// \brief Transform the given expression.
328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329 /// By default, this routine transforms an expression by delegating to the
330 /// appropriate TransformXXXExpr function to build a new expression.
331 /// Subclasses may override this function to transform expressions using some
332 /// other mechanism.
333 ///
334 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000335 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Richard Smithc83c2302012-12-19 01:39:02 +0000337 /// \brief Transform the given initializer.
338 ///
339 /// By default, this routine transforms an initializer by stripping off the
340 /// semantic nodes added by initialization, then passing the result to
341 /// TransformExpr or TransformExprs.
342 ///
343 /// \returns the transformed initializer.
344 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
345
Douglas Gregoraa165f82011-01-03 19:04:46 +0000346 /// \brief Transform the given list of expressions.
347 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// This routine transforms a list of expressions by invoking
349 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// support for variadic templates by expanding any pack expansions (if the
351 /// derived class permits such expansion) along the way. When pack expansions
352 /// are present, the number of outputs may not equal the number of inputs.
353 ///
354 /// \param Inputs The set of expressions to be transformed.
355 ///
356 /// \param NumInputs The number of expressions in \c Inputs.
357 ///
358 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 /// be.
361 ///
362 /// \param Outputs The transformed input expressions will be added to this
363 /// vector.
364 ///
365 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
366 /// due to transformation.
367 ///
368 /// \returns true if an error occurred, false otherwise.
369 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000370 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000371 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Transform the given declaration, which is referenced from a type
374 /// or expression.
375 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000376 /// By default, acts as the identity function on declarations, unless the
377 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000379 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 llvm::DenseMap<Decl *, Decl *>::iterator Known
381 = TransformedLocalDecls.find(D);
382 if (Known != TransformedLocalDecls.end())
383 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000384
385 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000386 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000387
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000389 /// place them on the new declaration.
390 ///
391 /// By default, this operation does nothing. Subclasses may override this
392 /// behavior to transform attributes.
393 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregordfca6f52012-02-13 22:00:16 +0000395 /// \brief Note that a local declaration has been transformed by this
396 /// transformer.
397 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
400 /// the transformer itself has to transform the declarations. This routine
401 /// can be overridden by a subclass that keeps track of such mappings.
402 void transformedLocalDecl(Decl *Old, Decl *New) {
403 TransformedLocalDecls[Old] = New;
404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000405
Douglas Gregor43959a92009-08-20 07:17:43 +0000406 /// \brief Transform the definition of the given declaration.
407 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000408 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000409 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000410 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
411 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 /// \brief Transform the given declaration, which was the first part of a
415 /// nested-name-specifier in a member access expression.
416 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000417 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// identifier in a nested-name-specifier of a member access expression, e.g.,
419 /// the \c T in \c x->T::member
420 ///
421 /// By default, invokes TransformDecl() to transform the declaration.
422 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000423 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
424 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000427 /// \brief Transform the given nested-name-specifier with source-location
428 /// information.
429 ///
430 /// By default, transforms all of the types and declarations within the
431 /// nested-name-specifier. Subclasses may override this function to provide
432 /// alternate behavior.
433 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
434 NestedNameSpecifierLoc NNS,
435 QualType ObjectType = QualType(),
436 NamedDecl *FirstQualifierInScope = 0);
437
Douglas Gregor81499bb2009-09-03 22:13:48 +0000438 /// \brief Transform the given declaration name.
439 ///
440 /// By default, transforms the types of conversion function, constructor,
441 /// and destructor names and then (if needed) rebuilds the declaration name.
442 /// Identifiers and selectors are returned unmodified. Sublcasses may
443 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000444 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000445 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000449 /// \param SS The nested-name-specifier that qualifies the template
450 /// name. This nested-name-specifier must already have been transformed.
451 ///
452 /// \param Name The template name to transform.
453 ///
454 /// \param NameLoc The source location of the template name.
455 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000456 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000457 /// access expression, this is the type of the object whose member template
458 /// is being referenced.
459 ///
460 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
461 /// also refers to a name within the current (lexical) scope, this is the
462 /// declaration it refers to.
463 ///
464 /// By default, transforms the template name by transforming the declarations
465 /// and nested-name-specifiers that occur within the template name.
466 /// Subclasses may override this function to provide alternate behavior.
467 TemplateName TransformTemplateName(CXXScopeSpec &SS,
468 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000469 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000470 QualType ObjectType = QualType(),
471 NamedDecl *FirstQualifierInScope = 0);
472
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 /// \brief Transform the given template argument.
474 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000475 /// By default, this operation transforms the type, expression, or
476 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000477 /// new template argument from the transformed result. Subclasses may
478 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000479 ///
480 /// Returns true if there was an error.
481 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
482 TemplateArgumentLoc &Output);
483
Douglas Gregorfcc12532010-12-20 17:31:10 +0000484 /// \brief Transform the given set of template arguments.
485 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000486 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000487 /// in the input set using \c TransformTemplateArgument(), and appends
488 /// the transformed arguments to the output list.
489 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000490 /// Note that this overload of \c TransformTemplateArguments() is merely
491 /// a convenience function. Subclasses that wish to override this behavior
492 /// should override the iterator-based member template version.
493 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000494 /// \param Inputs The set of template arguments to be transformed.
495 ///
496 /// \param NumInputs The number of template arguments in \p Inputs.
497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
502 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
503 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000504 TemplateArgumentListInfo &Outputs) {
505 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
506 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000507
508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000512 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000513 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000514 /// \param First An iterator to the first template argument.
515 ///
516 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
518 /// \param Outputs The set of transformed template arguments output by this
519 /// routine.
520 ///
521 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000522 template<typename InputIterator>
523 bool TransformTemplateArguments(InputIterator First,
524 InputIterator Last,
525 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000526
John McCall833ca992009-10-29 08:12:44 +0000527 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
528 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
529 TemplateArgumentLoc &ArgLoc);
530
John McCalla93c9342009-12-07 02:54:59 +0000531 /// \brief Fakes up a TypeSourceInfo for a type.
532 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
533 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000534 getDerived().getBaseLocation());
535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
John McCalla2becad2009-10-21 00:40:46 +0000537#define ABSTRACT_TYPELOC(CLASS, PARENT)
538#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000539 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000540#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000542 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
543 FunctionProtoTypeLoc TL,
544 CXXRecordDecl *ThisContext,
545 unsigned ThisTypeQuals);
546
John Wiegley28bbe4b2011-04-28 01:08:34 +0000547 StmtResult
548 TransformSEHHandler(Stmt *Handler);
549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000551 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
552 TemplateSpecializationTypeLoc TL,
553 TemplateName Template);
554
Chad Rosier4a9d7952012-08-08 18:46:20 +0000555 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000556 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
557 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000558 TemplateName Template,
559 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000560
Chad Rosier4a9d7952012-08-08 18:46:20 +0000561 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000562 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000563 DependentTemplateSpecializationTypeLoc TL,
564 NestedNameSpecifierLoc QualifierLoc);
565
John McCall21ef0fa2010-03-11 09:03:00 +0000566 /// \brief Transforms the parameters of a function type into the
567 /// given vectors.
568 ///
569 /// The result vectors should be kept in sync; null entries in the
570 /// variables vector are acceptable.
571 ///
572 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000573 bool TransformFunctionTypeParams(SourceLocation Loc,
574 ParmVarDecl **Params, unsigned NumParams,
575 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000576 SmallVectorImpl<QualType> &PTypes,
577 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000578
579 /// \brief Transforms a single function-type parameter. Return null
580 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000581 ///
582 /// \param indexAdjustment - A number to add to the parameter's
583 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000584 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000585 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000586 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000587 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000588
John McCall43fed0d2010-11-12 08:19:04 +0000589 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000590
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
592 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Richard Smith612409e2012-07-25 03:56:55 +0000594 /// \brief Transform the captures and body of a lambda expression.
595 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
596
Richard Smithefeeccf2012-10-21 03:28:35 +0000597 ExprResult TransformAddressOfOperand(Expr *E);
598 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
599 bool IsAddressOfOperand);
600
Douglas Gregor43959a92009-08-20 07:17:43 +0000601#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000602 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000603#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000604 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000605#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000606#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000608#define OPENMP_CLAUSE(Name, Class) \
609 OMPClause *Transform ## Class(Class *S);
610#include "clang/Basic/OpenMPKinds.def"
611
Douglas Gregor577f75a2009-08-04 16:50:30 +0000612 /// \brief Build a new pointer type given its pointee type.
613 ///
614 /// By default, performs semantic analysis when building the pointer type.
615 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000616 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617
618 /// \brief Build a new block pointer type given its pointee type.
619 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000620 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000622 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623
John McCall85737a72009-10-30 00:06:24 +0000624 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 ///
John McCall85737a72009-10-30 00:06:24 +0000626 /// By default, performs semantic analysis when building the
627 /// reference type. Subclasses may override this routine to provide
628 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 ///
John McCall85737a72009-10-30 00:06:24 +0000630 /// \param LValue whether the type was written with an lvalue sigil
631 /// or an rvalue sigil.
632 QualType RebuildReferenceType(QualType ReferentType,
633 bool LValue,
634 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new member pointer type given the pointee type and the
637 /// class type it refers into.
638 ///
639 /// By default, performs semantic analysis when building the member pointer
640 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000641 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
642 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new array type given the element type, size
645 /// modifier, size of the array (if known), size expression, and index type
646 /// qualifiers.
647 ///
648 /// By default, performs semantic analysis when building the array type.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000650 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 QualType RebuildArrayType(QualType ElementType,
652 ArrayType::ArraySizeModifier SizeMod,
653 const llvm::APInt *Size,
654 Expr *SizeExpr,
655 unsigned IndexTypeQuals,
656 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// \brief Build a new constant array type given the element type, size
659 /// modifier, (known) size of the array, and index type qualifiers.
660 ///
661 /// By default, performs semantic analysis when building the array type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000663 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000664 ArrayType::ArraySizeModifier SizeMod,
665 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000666 unsigned IndexTypeQuals,
667 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 /// \brief Build a new incomplete array type given the element type, size
670 /// modifier, and index type qualifiers.
671 ///
672 /// By default, performs semantic analysis when building the array type.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000674 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000675 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678
Mike Stump1eb44332009-09-09 15:08:12 +0000679 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// size modifier, size expression, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000684 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000686 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
689
Mike Stump1eb44332009-09-09 15:08:12 +0000690 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 /// size modifier, size expression, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000695 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000697 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
700
701 /// \brief Build a new vector type given the element type and
702 /// number of elements.
703 ///
704 /// By default, performs semantic analysis when building the vector type.
705 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000706 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000707 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000708
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 /// \brief Build a new extended vector type given the element type and
710 /// number of elements.
711 ///
712 /// By default, performs semantic analysis when building the vector type.
713 /// Subclasses may override this routine to provide different behavior.
714 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
715 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
717 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000718 /// given the element type and number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000722 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000723 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new function type.
727 ///
728 /// By default, performs semantic analysis when building the function type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000731 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000732 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000733
John McCalla2becad2009-10-21 00:40:46 +0000734 /// \brief Build a new unprototyped function type.
735 QualType RebuildFunctionNoProtoType(QualType ResultType);
736
John McCalled976492009-12-04 22:46:56 +0000737 /// \brief Rebuild an unresolved typename type, given the decl that
738 /// the UnresolvedUsingTypenameDecl was transformed to.
739 QualType RebuildUnresolvedUsingType(Decl *D);
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000742 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743 return SemaRef.Context.getTypeDeclType(Typedef);
744 }
745
746 /// \brief Build a new class/struct/union type.
747 QualType RebuildRecordType(RecordDecl *Record) {
748 return SemaRef.Context.getTypeDeclType(Record);
749 }
750
751 /// \brief Build a new Enum type.
752 QualType RebuildEnumType(EnumDecl *Enum) {
753 return SemaRef.Context.getTypeDeclType(Enum);
754 }
John McCall7da24312009-09-05 00:15:47 +0000755
Mike Stump1eb44332009-09-09 15:08:12 +0000756 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000757 ///
758 /// By default, performs semantic analysis when building the typeof type.
759 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000760 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761
Mike Stump1eb44332009-09-09 15:08:12 +0000762 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000763 ///
764 /// By default, builds a new TypeOfType with the given underlying type.
765 QualType RebuildTypeOfType(QualType Underlying);
766
Sean Huntca63c202011-05-24 22:41:36 +0000767 /// \brief Build a new unary transform type.
768 QualType RebuildUnaryTransformType(QualType BaseType,
769 UnaryTransformType::UTTKind UKind,
770 SourceLocation Loc);
771
Richard Smitha2c36462013-04-26 16:15:35 +0000772 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the decltype type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000776 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Richard Smitha2c36462013-04-26 16:15:35 +0000778 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000779 ///
780 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000781 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000782 // Note, IsDependent is always false here: we implicitly convert an 'auto'
783 // which has been deduced to a dependent type into an undeduced 'auto', so
784 // that we'll retry deduction after the transformation.
Faisal Valiecb58192013-08-22 01:49:11 +0000785 // FIXME: Can we assume the same about IsParameterPack?
786 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
787 /*IsDependent*/ false,
788 /*IsParameterPack*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000789 }
790
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791 /// \brief Build a new template specialization type.
792 ///
793 /// By default, performs semantic analysis when building the template
794 /// specialization type. Subclasses may override this routine to provide
795 /// different behavior.
796 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000797 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000798 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000799
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000800 /// \brief Build a new parenthesized type.
801 ///
802 /// By default, builds a new ParenType type from the inner type.
803 /// Subclasses may override this routine to provide different behavior.
804 QualType RebuildParenType(QualType InnerType) {
805 return SemaRef.Context.getParenType(InnerType);
806 }
807
Douglas Gregor577f75a2009-08-04 16:50:30 +0000808 /// \brief Build a new qualified name type.
809 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000810 /// By default, builds a new ElaboratedType type from the keyword,
811 /// the nested-name-specifier and the named type.
812 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000813 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
814 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000815 NestedNameSpecifierLoc QualifierLoc,
816 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000817 return SemaRef.Context.getElaboratedType(Keyword,
818 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000819 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000820 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000821
822 /// \brief Build a new typename type that refers to a template-id.
823 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000824 /// By default, builds a new DependentNameType type from the
825 /// nested-name-specifier and the given type. Subclasses may override
826 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000827 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000828 ElaboratedTypeKeyword Keyword,
829 NestedNameSpecifierLoc QualifierLoc,
830 const IdentifierInfo *Name,
831 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000832 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000833 // Rebuild the template name.
834 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000835 CXXScopeSpec SS;
836 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000838 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 if (InstName.isNull())
841 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000842
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 // If it's still dependent, make a dependent specialization.
844 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000845 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
847 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000848 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000849
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 // Otherwise, make an elaborated type wrapping a non-dependent
851 // specialization.
852 QualType T =
853 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
854 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000855
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000856 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
857 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000858
859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000861 T);
862 }
863
Douglas Gregor577f75a2009-08-04 16:50:30 +0000864 /// \brief Build a new typename type that refers to an identifier.
865 ///
866 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000867 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000868 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000874 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000875 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000878 // If the name is still dependent, just build a new dependent name type.
879 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000880 return SemaRef.Context.getDependentNameType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000882 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000883 }
884
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000885 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000886 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000887 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000888
889 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
890
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000891 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000892 // into a non-dependent elaborated-type-specifier. Find the tag we're
893 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000894 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000895 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
896 if (!DC)
897 return QualType();
898
John McCall56138762010-05-27 06:40:31 +0000899 if (SemaRef.RequireCompleteDeclContext(SS, DC))
900 return QualType();
901
Douglas Gregor40336422010-03-31 22:19:08 +0000902 TagDecl *Tag = 0;
903 SemaRef.LookupQualifiedName(Result, DC);
904 switch (Result.getResultKind()) {
905 case LookupResult::NotFound:
906 case LookupResult::NotFoundInCurrentInstantiation:
907 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000908
Douglas Gregor40336422010-03-31 22:19:08 +0000909 case LookupResult::Found:
910 Tag = Result.getAsSingle<TagDecl>();
911 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000912
Douglas Gregor40336422010-03-31 22:19:08 +0000913 case LookupResult::FoundOverloaded:
914 case LookupResult::FoundUnresolvedValue:
915 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000916
Douglas Gregor40336422010-03-31 22:19:08 +0000917 case LookupResult::Ambiguous:
918 // Let the LookupResult structure handle ambiguities.
919 return QualType();
920 }
921
922 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000923 // Check where the name exists but isn't a tag type and use that to emit
924 // better diagnostics.
925 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
926 SemaRef.LookupQualifiedName(Result, DC);
927 switch (Result.getResultKind()) {
928 case LookupResult::Found:
929 case LookupResult::FoundOverloaded:
930 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000931 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000932 unsigned Kind = 0;
933 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000934 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
935 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000936 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
937 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
938 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000939 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000940 default:
941 // FIXME: Would be nice to highlight just the source range.
942 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
943 << Kind << Id << DC;
944 break;
945 }
Douglas Gregor40336422010-03-31 22:19:08 +0000946 return QualType();
947 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000948
Richard Trieubbf34c02011-06-10 03:11:26 +0000949 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
950 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000951 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000952 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
953 return QualType();
954 }
955
956 // Build the elaborated-type-specifier type.
957 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000958 return SemaRef.Context.getElaboratedType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000960 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000961 }
Mike Stump1eb44332009-09-09 15:08:12 +0000962
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000963 /// \brief Build a new pack expansion type.
964 ///
965 /// By default, builds a new PackExpansionType type from the given pattern.
966 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000967 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000968 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000969 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000970 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
972 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000973 }
974
Eli Friedmanb001de72011-10-06 23:00:33 +0000975 /// \brief Build a new atomic type given its value type.
976 ///
977 /// By default, performs semantic analysis when building the atomic type.
978 /// Subclasses may override this routine to provide different behavior.
979 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
980
Douglas Gregord1067e52009-08-06 06:41:21 +0000981 /// \brief Build a new template name given a nested name specifier, a flag
982 /// indicating whether the "template" keyword was provided, and the template
983 /// that the template name refers to.
984 ///
985 /// By default, builds the new template name directly. Subclasses may override
986 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000987 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000988 bool TemplateKW,
989 TemplateDecl *Template);
990
Douglas Gregord1067e52009-08-06 06:41:21 +0000991 /// \brief Build a new template name given a nested name specifier and the
992 /// name that is referred to as a template.
993 ///
994 /// By default, performs semantic analysis to determine whether the name can
995 /// be resolved to a specific template, then builds the appropriate kind of
996 /// template name. Subclasses may override this routine to provide different
997 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000998 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
999 const IdentifierInfo &Name,
1000 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001001 QualType ObjectType,
1002 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// overloaded operator name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001012 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001015
1016 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001017 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001018 ///
1019 /// By default, performs semantic analysis to determine whether the name can
1020 /// be resolved to a specific template, then builds the appropriate kind of
1021 /// template name. Subclasses may override this routine to provide different
1022 /// behavior.
1023 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1024 const TemplateArgument &ArgPack) {
1025 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1026 }
1027
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 /// \brief Build a new compound statement.
1029 ///
1030 /// By default, performs semantic analysis to build the new statement.
1031 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001032 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 MultiStmtArg Statements,
1034 SourceLocation RBraceLoc,
1035 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001036 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 IsStmtExpr);
1038 }
1039
1040 /// \brief Build a new case statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001044 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001045 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001049 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 ColonLoc);
1051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /// \brief Attach the body to a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001058 getSema().ActOnCaseStmtBody(S, Body);
1059 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001060 }
Mike Stump1eb44332009-09-09 15:08:12 +00001061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new default statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001068 Stmt *SubStmt) {
1069 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /*CurScope=*/0);
1071 }
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 /// \brief Build a new label statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1078 SourceLocation ColonLoc, Stmt *SubStmt) {
1079 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Richard Smith534986f2012-04-14 00:33:13 +00001082 /// \brief Build a new label statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001086 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1087 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001088 Stmt *SubStmt) {
1089 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1090 }
1091
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 /// \brief Build a new "if" statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001096 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001097 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001098 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001099 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 }
Mike Stump1eb44332009-09-09 15:08:12 +00001101
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 /// \brief Start building a new switch statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001106 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001108 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001109 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Attach the body to the switch statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001117 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001118 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 }
1120
1121 /// \brief Build a new while statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001125 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1126 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001127 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001128 }
Mike Stump1eb44332009-09-09 15:08:12 +00001129
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 /// \brief Build a new do-while statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001134 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001135 SourceLocation WhileLoc, SourceLocation LParenLoc,
1136 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001137 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1138 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new for 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 RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001146 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 VarDecl *CondVar, Sema::FullExprArg Inc,
1148 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001149 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001151 }
Mike Stump1eb44332009-09-09 15:08:12 +00001152
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 /// \brief Build a new goto statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001157 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1158 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001159 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
1161
1162 /// \brief Build a new indirect goto statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001167 SourceLocation StarLoc,
1168 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001169 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 /// \brief Build a new return statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001176 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001177 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001178 }
Mike Stump1eb44332009-09-09 15:08:12 +00001179
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 /// \brief Build a new declaration statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001184 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1185 SourceLocation StartLoc, SourceLocation EndLoc) {
1186 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001187 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001188 }
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Anders Carlsson703e3942010-01-24 05:50:09 +00001190 /// \brief Build a new inline asm statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001194 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1195 bool IsVolatile, unsigned NumOutputs,
1196 unsigned NumInputs, IdentifierInfo **Names,
1197 MultiExprArg Constraints, MultiExprArg Exprs,
1198 Expr *AsmString, MultiExprArg Clobbers,
1199 SourceLocation RParenLoc) {
1200 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1201 NumInputs, Names, Constraints, Exprs,
1202 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001203 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204
Chad Rosier8cd64b42012-06-11 20:47:18 +00001205 /// \brief Build a new MS style inline asm statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001209 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001210 ArrayRef<Token> AsmToks,
1211 StringRef AsmString,
1212 unsigned NumOutputs, unsigned NumInputs,
1213 ArrayRef<StringRef> Constraints,
1214 ArrayRef<StringRef> Clobbers,
1215 ArrayRef<Expr*> Exprs,
1216 SourceLocation EndLoc) {
1217 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1218 NumOutputs, NumInputs,
1219 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001220 }
1221
James Dennett699c9042012-06-15 07:13:21 +00001222 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001228 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001230 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 }
1233
Douglas Gregorbe270a02010-04-26 17:57:08 +00001234 /// \brief Rebuild an Objective-C exception declaration.
1235 ///
1236 /// By default, performs semantic analysis to build the new declaration.
1237 /// Subclasses may override this routine to provide different behavior.
1238 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1239 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001240 return getSema().BuildObjCExceptionDecl(TInfo, T,
1241 ExceptionDecl->getInnerLocStart(),
1242 ExceptionDecl->getLocation(),
1243 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001244 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001245
James Dennett699c9042012-06-15 07:13:21 +00001246 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001247 ///
1248 /// By default, performs semantic analysis to build the new statement.
1249 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001250 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001251 SourceLocation RParenLoc,
1252 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001253 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001254 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001257
James Dennett699c9042012-06-15 07:13:21 +00001258 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001262 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001263 Stmt *Body) {
1264 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001266
James Dennett699c9042012-06-15 07:13:21 +00001267 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001268 ///
1269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001272 Expr *Operand) {
1273 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001275
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001276 /// \brief Build a new OpenMP parallel directive.
1277 ///
1278 /// By default, performs semantic analysis to build the new statement.
1279 /// Subclasses may override this routine to provide different behavior.
1280 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1281 Stmt *AStmt,
1282 SourceLocation StartLoc,
1283 SourceLocation EndLoc) {
1284 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1285 StartLoc, EndLoc);
1286 }
1287
1288 /// \brief Build a new OpenMP 'default' clause.
1289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1293 SourceLocation KindKwLoc,
1294 SourceLocation StartLoc,
1295 SourceLocation LParenLoc,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1298 StartLoc, LParenLoc, EndLoc);
1299 }
1300
1301 /// \brief Build a new OpenMP 'private' clause.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1306 SourceLocation StartLoc,
1307 SourceLocation LParenLoc,
1308 SourceLocation EndLoc) {
1309 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1310 EndLoc);
1311 }
1312
James Dennett699c9042012-06-15 07:13:21 +00001313 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1318 Expr *object) {
1319 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1320 }
1321
James Dennett699c9042012-06-15 07:13:21 +00001322 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001323 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001327 Expr *Object, Stmt *Body) {
1328 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001329 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001330
James Dennett699c9042012-06-15 07:13:21 +00001331 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1335 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1336 Stmt *Body) {
1337 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1338 }
John McCall990567c2011-07-27 01:07:15 +00001339
Douglas Gregorc3203e72010-04-22 23:10:45 +00001340 /// \brief Build a new Objective-C fast enumeration statement.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001344 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001345 Stmt *Element,
1346 Expr *Collection,
1347 SourceLocation RParenLoc,
1348 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001349 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001350 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001351 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001352 RParenLoc);
1353 if (ForEachStmt.isInvalid())
1354 return StmtError();
1355
1356 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001358
Douglas Gregor43959a92009-08-20 07:17:43 +00001359 /// \brief Build a new C++ exception declaration.
1360 ///
1361 /// By default, performs semantic analysis to build the new decaration.
1362 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001363 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001364 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001365 SourceLocation StartLoc,
1366 SourceLocation IdLoc,
1367 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001368 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1369 StartLoc, IdLoc, Id);
1370 if (Var)
1371 getSema().CurContext->addDecl(Var);
1372 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001373 }
1374
1375 /// \brief Build a new C++ catch statement.
1376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001380 VarDecl *ExceptionDecl,
1381 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001382 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1383 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001384 }
Mike Stump1eb44332009-09-09 15:08:12 +00001385
Douglas Gregor43959a92009-08-20 07:17:43 +00001386 /// \brief Build a new C++ try statement.
1387 ///
1388 /// By default, performs semantic analysis to build the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001390 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001391 Stmt *TryBlock,
1392 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001393 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001394 }
Mike Stump1eb44332009-09-09 15:08:12 +00001395
Richard Smithad762fc2011-04-14 22:09:26 +00001396 /// \brief Build a new C++0x range-based for statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
1400 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1401 SourceLocation ColonLoc,
1402 Stmt *Range, Stmt *BeginEnd,
1403 Expr *Cond, Expr *Inc,
1404 Stmt *LoopVar,
1405 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001406 // If we've just learned that the range is actually an Objective-C
1407 // collection, treat this as an Objective-C fast enumeration loop.
1408 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1409 if (RangeStmt->isSingleDecl()) {
1410 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001411 if (RangeVar->isInvalidDecl())
1412 return StmtError();
1413
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001414 Expr *RangeExpr = RangeVar->getInit();
1415 if (!RangeExpr->isTypeDependent() &&
1416 RangeExpr->getType()->isObjCObjectPointerType())
1417 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1418 RParenLoc);
1419 }
1420 }
1421 }
1422
Richard Smithad762fc2011-04-14 22:09:26 +00001423 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001424 Cond, Inc, LoopVar, RParenLoc,
1425 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001426 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001427
1428 /// \brief Build a new C++0x range-based for statement.
1429 ///
1430 /// By default, performs semantic analysis to build the new statement.
1431 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001432 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001433 bool IsIfExists,
1434 NestedNameSpecifierLoc QualifierLoc,
1435 DeclarationNameInfo NameInfo,
1436 Stmt *Nested) {
1437 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1438 QualifierLoc, NameInfo, Nested);
1439 }
1440
Richard Smithad762fc2011-04-14 22:09:26 +00001441 /// \brief Attach body to a C++0x range-based for statement.
1442 ///
1443 /// By default, performs semantic analysis to finish the new statement.
1444 /// Subclasses may override this routine to provide different behavior.
1445 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1446 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1447 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001448
John Wiegley28bbe4b2011-04-28 01:08:34 +00001449 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1450 SourceLocation TryLoc,
1451 Stmt *TryBlock,
1452 Stmt *Handler) {
1453 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1454 }
1455
1456 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1457 Expr *FilterExpr,
1458 Stmt *Block) {
1459 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1460 }
1461
1462 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1463 Stmt *Block) {
1464 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1465 }
1466
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 /// \brief Build a new expression that references a declaration.
1468 ///
1469 /// By default, performs semantic analysis to build the new expression.
1470 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001471 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001472 LookupResult &R,
1473 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001474 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1475 }
1476
1477
1478 /// \brief Build a new expression that references a declaration.
1479 ///
1480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001482 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001483 ValueDecl *VD,
1484 const DeclarationNameInfo &NameInfo,
1485 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001486 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001487 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001488
1489 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001490
1491 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 }
Mike Stump1eb44332009-09-09 15:08:12 +00001493
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001495 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001498 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001500 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
1502
Douglas Gregora71d8192009-09-04 17:36:40 +00001503 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001508 SourceLocation OperatorLoc,
1509 bool isArrow,
1510 CXXScopeSpec &SS,
1511 TypeSourceInfo *ScopeType,
1512 SourceLocation CCLoc,
1513 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001514 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001517 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001520 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001521 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001522 Expr *SubExpr) {
1523 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 }
Mike Stump1eb44332009-09-09 15:08:12 +00001525
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001526 /// \brief Build a new builtin offsetof expression.
1527 ///
1528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001530 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001531 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001532 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001533 unsigned NumComponents,
1534 SourceLocation RParenLoc) {
1535 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1536 NumComponents, RParenLoc);
1537 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001538
1539 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001540 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001541 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// By default, performs semantic analysis to build the new expression.
1543 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001544 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1545 SourceLocation OpLoc,
1546 UnaryExprOrTypeTrait ExprKind,
1547 SourceRange R) {
1548 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 }
1550
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001551 /// \brief Build a new sizeof, alignof or vec step expression with an
1552 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001553 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// By default, performs semantic analysis to build the new expression.
1555 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001556 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1557 UnaryExprOrTypeTrait ExprKind,
1558 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001559 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001560 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001563
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001564 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001573 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001575 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1576 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 RBracketLoc);
1578 }
1579
1580 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001586 SourceLocation RParenLoc,
1587 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001588 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001589 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
1591
1592 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001597 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001598 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001599 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001600 const DeclarationNameInfo &MemberNameInfo,
1601 ValueDecl *Member,
1602 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001603 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001604 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001605 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1606 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001607 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001608 // We have a reference to an unnamed field. This is always the
1609 // base of an anonymous struct/union member access, i.e. the
1610 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001611 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001612 assert(Member->getType()->isRecordType() &&
1613 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Richard Smith9138b4e2011-10-26 19:06:56 +00001615 BaseResult =
1616 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001617 QualifierLoc.getNestedNameSpecifier(),
1618 FoundDecl, Member);
1619 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001620 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001621 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001622 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001623 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001624 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001625 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001626 cast<FieldDecl>(Member)->getType(),
1627 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001628 return getSema().Owned(ME);
1629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001631 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001632 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001633
John Wiegley429bb272011-04-08 18:41:53 +00001634 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001635 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001636
John McCall6bb80172010-03-30 21:47:33 +00001637 // FIXME: this involves duplicating earlier analysis in a lot of
1638 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001639 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001640 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001641 R.resolveKind();
1642
John McCall9ae2f072010-08-23 23:25:46 +00001643 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001644 SS, TemplateKWLoc,
1645 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001646 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 }
Mike Stump1eb44332009-09-09 15:08:12 +00001648
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001650 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001653 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001654 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001655 Expr *LHS, Expr *RHS) {
1656 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 }
1658
1659 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001660 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// By default, performs semantic analysis to build the new expression.
1662 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001663 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001664 SourceLocation QuestionLoc,
1665 Expr *LHS,
1666 SourceLocation ColonLoc,
1667 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001668 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1669 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 }
1671
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001673 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// By default, performs semantic analysis to build the new expression.
1675 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001676 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001680 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001681 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001689 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001692 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001693 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001697 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001700 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 SourceLocation OpLoc,
1702 SourceLocation AccessorLoc,
1703 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001704
John McCall129e2df2009-11-30 22:42:35 +00001705 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001706 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001707 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001708 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001709 SS, SourceLocation(),
1710 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001711 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001712 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 }
Mike Stump1eb44332009-09-09 15:08:12 +00001714
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001716 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001720 MultiExprArg Inits,
1721 SourceLocation RBraceLoc,
1722 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001723 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001724 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001725 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001726 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001727
Douglas Gregore48319a2009-11-09 17:16:50 +00001728 // Patch in the result type we were given, which may have been computed
1729 // when the initial InitListExpr was built.
1730 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1731 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001732 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 }
Mike Stump1eb44332009-09-09 15:08:12 +00001734
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001736 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001739 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 MultiExprArg ArrayExprs,
1741 SourceLocation EqualOrColonLoc,
1742 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001743 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001744 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001746 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001750 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 }
Mike Stump1eb44332009-09-09 15:08:12 +00001752
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001754 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// By default, builds the implicit value initialization without performing
1756 /// any semantic analysis. Subclasses may override this routine to provide
1757 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001758 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001763 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001767 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001768 SourceLocation RParenLoc) {
1769 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001770 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001771 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 }
1773
1774 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001775 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001778 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001779 MultiExprArg SubExprs,
1780 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001781 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 }
Mike Stump1eb44332009-09-09 15:08:12 +00001783
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001785 ///
1786 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 /// rather than attempting to map the label statement itself.
1788 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001789 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001790 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001791 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
Mike Stump1eb44332009-09-09 15:08:12 +00001793
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001795 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001799 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001801 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// \brief Build a new __builtin_choose_expr expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001808 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001809 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
1811 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 RParenLoc);
1814 }
Mike Stump1eb44332009-09-09 15:08:12 +00001815
Peter Collingbournef111d932011-04-15 00:35:48 +00001816 /// \brief Build a new generic selection expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
1820 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1821 SourceLocation DefaultLoc,
1822 SourceLocation RParenLoc,
1823 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001824 ArrayRef<TypeSourceInfo *> Types,
1825 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001826 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001827 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001828 }
1829
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 /// \brief Build a new overloaded operator call expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// The semantic analysis provides the behavior of template instantiation,
1834 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001835 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 /// argument-dependent lookup, etc. Subclasses may override this routine to
1837 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001838 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001840 Expr *Callee,
1841 Expr *First,
1842 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001843
1844 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 /// reinterpret_cast.
1846 ///
1847 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001848 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001850 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 Stmt::StmtClass Class,
1852 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001853 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 SourceLocation RAngleLoc,
1855 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001856 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 SourceLocation RParenLoc) {
1858 switch (Class) {
1859 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001860 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001861 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001862 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863
1864 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001865 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001866 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001867 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001870 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001871 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001872 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001874
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001876 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001877 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001878 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001879
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001881 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 }
Mike Stump1eb44332009-09-09 15:08:12 +00001884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 /// \brief Build a new C++ static_cast expression.
1886 ///
1887 /// By default, performs semantic analysis to build the new expression.
1888 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001889 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001891 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RAngleLoc,
1893 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001894 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001896 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001897 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001898 SourceRange(LAngleLoc, RAngleLoc),
1899 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new C++ dynamic_cast expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001908 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RAngleLoc,
1910 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001913 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001914 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001915 SourceRange(LAngleLoc, RAngleLoc),
1916 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new C++ reinterpret_cast expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001925 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SourceLocation RAngleLoc,
1927 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001928 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001930 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001931 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001932 SourceRange(LAngleLoc, RAngleLoc),
1933 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 }
1935
1936 /// \brief Build a new C++ const_cast expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001942 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 SourceLocation RAngleLoc,
1944 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001945 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001947 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001948 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001949 SourceRange(LAngleLoc, RAngleLoc),
1950 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
Mike Stump1eb44332009-09-09 15:08:12 +00001952
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 /// \brief Build a new C++ functional-style cast expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001957 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1958 SourceLocation LParenLoc,
1959 Expr *Sub,
1960 SourceLocation RParenLoc) {
1961 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001962 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 RParenLoc);
1964 }
Mike Stump1eb44332009-09-09 15:08:12 +00001965
Douglas Gregorb98b1992009-08-11 05:31:07 +00001966 /// \brief Build a new C++ typeid(type) expression.
1967 ///
1968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001970 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001971 SourceLocation TypeidLoc,
1972 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001974 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001975 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 }
Mike Stump1eb44332009-09-09 15:08:12 +00001977
Francois Pichet01b7c302010-09-08 12:20:18 +00001978
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 /// \brief Build a new C++ typeid(expr) expression.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001983 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001984 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001985 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001987 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001988 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001989 }
1990
Francois Pichet01b7c302010-09-08 12:20:18 +00001991 /// \brief Build a new C++ __uuidof(type) expression.
1992 ///
1993 /// By default, performs semantic analysis to build the new expression.
1994 /// Subclasses may override this routine to provide different behavior.
1995 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1996 SourceLocation TypeidLoc,
1997 TypeSourceInfo *Operand,
1998 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001999 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002000 RParenLoc);
2001 }
2002
2003 /// \brief Build a new C++ __uuidof(expr) expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
2007 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2008 SourceLocation TypeidLoc,
2009 Expr *Operand,
2010 SourceLocation RParenLoc) {
2011 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2012 RParenLoc);
2013 }
2014
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 /// \brief Build a new C++ "this" expression.
2016 ///
2017 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002018 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002020 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002021 QualType ThisType,
2022 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002023 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002025 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2026 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002027 }
2028
2029 /// \brief Build a new C++ throw expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002033 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2034 bool IsThrownVariableInScope) {
2035 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 }
2037
2038 /// \brief Build a new C++ default-argument expression.
2039 ///
2040 /// By default, builds a new default-argument expression, which does not
2041 /// require any semantic analysis. Subclasses may override this routine to
2042 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002043 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002044 ParmVarDecl *Param) {
2045 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2046 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 }
2048
Richard Smithc3bf52c2013-04-20 22:23:05 +00002049 /// \brief Build a new C++11 default-initialization expression.
2050 ///
2051 /// By default, builds a new default field initialization expression, which
2052 /// does not require any semantic analysis. Subclasses may override this
2053 /// routine to provide different behavior.
2054 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2055 FieldDecl *Field) {
2056 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2057 Field));
2058 }
2059
Douglas Gregorb98b1992009-08-11 05:31:07 +00002060 /// \brief Build a new C++ zero-initialization expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002064 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2066 SourceLocation RParenLoc) {
2067 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002068 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 }
Mike Stump1eb44332009-09-09 15:08:12 +00002070
Douglas Gregorb98b1992009-08-11 05:31:07 +00002071 /// \brief Build a new C++ "new" expression.
2072 ///
2073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002075 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002076 bool UseGlobal,
2077 SourceLocation PlacementLParen,
2078 MultiExprArg PlacementArgs,
2079 SourceLocation PlacementRParen,
2080 SourceRange TypeIdParens,
2081 QualType AllocatedType,
2082 TypeSourceInfo *AllocatedTypeInfo,
2083 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002084 SourceRange DirectInitRange,
2085 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002086 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002087 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002088 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002089 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002090 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002091 AllocatedType,
2092 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002093 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002094 DirectInitRange,
2095 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 }
Mike Stump1eb44332009-09-09 15:08:12 +00002097
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 /// \brief Build a new C++ "delete" expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002102 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002103 bool IsGlobalDelete,
2104 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002105 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002107 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 }
Mike Stump1eb44332009-09-09 15:08:12 +00002109
Douglas Gregorb98b1992009-08-11 05:31:07 +00002110 /// \brief Build a new unary type trait expression.
2111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002114 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002115 SourceLocation StartLoc,
2116 TypeSourceInfo *T,
2117 SourceLocation RParenLoc) {
2118 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002119 }
2120
Francois Pichet6ad6f282010-12-07 00:08:36 +00002121 /// \brief Build a new binary type trait expression.
2122 ///
2123 /// By default, performs semantic analysis to build the new expression.
2124 /// Subclasses may override this routine to provide different behavior.
2125 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2126 SourceLocation StartLoc,
2127 TypeSourceInfo *LhsT,
2128 TypeSourceInfo *RhsT,
2129 SourceLocation RParenLoc) {
2130 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2131 }
2132
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002133 /// \brief Build a new type trait expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
2137 ExprResult RebuildTypeTrait(TypeTrait Trait,
2138 SourceLocation StartLoc,
2139 ArrayRef<TypeSourceInfo *> Args,
2140 SourceLocation RParenLoc) {
2141 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2142 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002143
John Wiegley21ff2e52011-04-28 00:16:57 +00002144 /// \brief Build a new array type trait expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
2148 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2149 SourceLocation StartLoc,
2150 TypeSourceInfo *TSInfo,
2151 Expr *DimExpr,
2152 SourceLocation RParenLoc) {
2153 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2154 }
2155
John Wiegley55262202011-04-25 06:54:41 +00002156 /// \brief Build a new expression trait expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
2160 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2161 SourceLocation StartLoc,
2162 Expr *Queried,
2163 SourceLocation RParenLoc) {
2164 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2165 }
2166
Mike Stump1eb44332009-09-09 15:08:12 +00002167 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002168 /// expression.
2169 ///
2170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002172 ExprResult RebuildDependentScopeDeclRefExpr(
2173 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002174 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002175 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002176 const TemplateArgumentListInfo *TemplateArgs,
2177 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002179 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002180
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002181 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002182 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002183 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002184
Richard Smithefeeccf2012-10-21 03:28:35 +00002185 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2186 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002187 }
2188
2189 /// \brief Build a new template-id expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002193 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002194 SourceLocation TemplateKWLoc,
2195 LookupResult &R,
2196 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002197 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002198 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2199 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 }
2201
2202 /// \brief Build a new object-construction expression.
2203 ///
2204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002206 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002207 SourceLocation Loc,
2208 CXXConstructorDecl *Constructor,
2209 bool IsElidable,
2210 MultiExprArg Args,
2211 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002212 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002213 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002214 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002215 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002216 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002217 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002218 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002219 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002220
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002221 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002222 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002223 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002224 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002225 RequiresZeroInit, ConstructKind,
2226 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002227 }
2228
2229 /// \brief Build a new object-construction expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002233 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2234 SourceLocation LParenLoc,
2235 MultiExprArg Args,
2236 SourceLocation RParenLoc) {
2237 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002238 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002239 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002240 RParenLoc);
2241 }
2242
2243 /// \brief Build a new object-construction expression.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002247 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2248 SourceLocation LParenLoc,
2249 MultiExprArg Args,
2250 SourceLocation RParenLoc) {
2251 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002253 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002254 RParenLoc);
2255 }
Mike Stump1eb44332009-09-09 15:08:12 +00002256
Douglas Gregorb98b1992009-08-11 05:31:07 +00002257 /// \brief Build a new member reference expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002262 QualType BaseType,
2263 bool IsArrow,
2264 SourceLocation OperatorLoc,
2265 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002266 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002267 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002268 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002269 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002271 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002272
John McCall9ae2f072010-08-23 23:25:46 +00002273 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002274 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002275 SS, TemplateKWLoc,
2276 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002277 MemberNameInfo,
2278 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 }
2280
John McCall129e2df2009-11-30 22:42:35 +00002281 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002285 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2286 SourceLocation OperatorLoc,
2287 bool IsArrow,
2288 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002289 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002290 NamedDecl *FirstQualifierInScope,
2291 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002292 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002293 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002294 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002295
John McCall9ae2f072010-08-23 23:25:46 +00002296 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002297 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002298 SS, TemplateKWLoc,
2299 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002300 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002301 }
Mike Stump1eb44332009-09-09 15:08:12 +00002302
Sebastian Redl2e156222010-09-10 20:55:43 +00002303 /// \brief Build a new noexcept expression.
2304 ///
2305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
2307 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2308 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2309 }
2310
Douglas Gregoree8aff02011-01-04 17:33:58 +00002311 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002312 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2313 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002314 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002315 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002316 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002317 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2318 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002319 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002320
2321 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2322 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002323 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002324 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002325
Patrick Beardeb382ec2012-04-19 00:25:12 +00002326 /// \brief Build a new Objective-C boxed expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
2330 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2331 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2332 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002334 /// \brief Build a new Objective-C array literal.
2335 ///
2336 /// By default, performs semantic analysis to build the new expression.
2337 /// Subclasses may override this routine to provide different behavior.
2338 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2339 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002340 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002341 MultiExprArg(Elements, NumElements));
2342 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002343
2344 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002345 Expr *Base, Expr *Key,
2346 ObjCMethodDecl *getterMethod,
2347 ObjCMethodDecl *setterMethod) {
2348 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2349 getterMethod, setterMethod);
2350 }
2351
2352 /// \brief Build a new Objective-C dictionary literal.
2353 ///
2354 /// By default, performs semantic analysis to build the new expression.
2355 /// Subclasses may override this routine to provide different behavior.
2356 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2357 ObjCDictionaryElement *Elements,
2358 unsigned NumElements) {
2359 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361
James Dennett699c9042012-06-15 07:13:21 +00002362 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002366 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002367 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002368 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002369 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002370 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002371 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002372
Douglas Gregor92e986e2010-04-22 16:44:27 +00002373 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002374 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002375 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002376 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002377 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002378 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002379 MultiExprArg Args,
2380 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002381 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2382 ReceiverTypeInfo->getType(),
2383 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002384 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002385 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002386 }
2387
2388 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002389 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002391 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002392 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002393 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002394 MultiExprArg Args,
2395 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002396 return SemaRef.BuildInstanceMessage(Receiver,
2397 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002398 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002399 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002400 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002401 }
2402
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 /// \brief Build a new Objective-C ivar reference expression.
2404 ///
2405 /// By default, performs semantic analysis to build the new expression.
2406 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002407 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002408 SourceLocation IvarLoc,
2409 bool IsArrow, bool IsFreeIvar) {
2410 // FIXME: We lose track of the IsFreeIvar bit.
2411 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002412 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002413 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2414 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002415 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002416 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002417 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002418 false);
John Wiegley429bb272011-04-08 18:41:53 +00002419 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002420 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002421
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002422 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002423 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002424
John Wiegley429bb272011-04-08 18:41:53 +00002425 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002426 /*FIXME:*/IvarLoc, IsArrow,
2427 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002428 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002429 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 /*TemplateArgs=*/0);
2431 }
Douglas Gregore3303542010-04-26 20:47:02 +00002432
2433 /// \brief Build a new Objective-C property reference expression.
2434 ///
2435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002437 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002438 ObjCPropertyDecl *Property,
2439 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002440 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002441 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002442 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2443 Sema::LookupMemberName);
2444 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002445 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002446 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002447 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002448 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002449 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450
Douglas Gregore3303542010-04-26 20:47:02 +00002451 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002452 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002453
John Wiegley429bb272011-04-08 18:41:53 +00002454 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002456 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002457 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002458 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002459 /*TemplateArgs=*/0);
2460 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002461
John McCall12f78a62010-12-02 01:19:52 +00002462 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002463 ///
2464 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002465 /// Subclasses may override this routine to provide different behavior.
2466 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2467 ObjCMethodDecl *Getter,
2468 ObjCMethodDecl *Setter,
2469 SourceLocation PropertyLoc) {
2470 // Since these expressions can only be value-dependent, we do not
2471 // need to perform semantic analysis again.
2472 return Owned(
2473 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2474 VK_LValue, OK_ObjCProperty,
2475 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002476 }
2477
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002478 /// \brief Build a new Objective-C "isa" expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002482 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002483 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002484 bool IsArrow) {
2485 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002486 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002487 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2488 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002489 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002490 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002491 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002492 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002493 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002494
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002495 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002496 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002497
John Wiegley429bb272011-04-08 18:41:53 +00002498 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002499 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002500 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002501 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002502 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002503 /*TemplateArgs=*/0);
2504 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002505
Douglas Gregorb98b1992009-08-11 05:31:07 +00002506 /// \brief Build a new shuffle vector expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002510 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002511 MultiExprArg SubExprs,
2512 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002513 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002514 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002515 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2516 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2517 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002518 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002519
Douglas Gregorb98b1992009-08-11 05:31:07 +00002520 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002521 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002522 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2523 SemaRef.Context.BuiltinFnTy,
2524 VK_RValue, BuiltinLoc);
2525 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2526 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2527 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002528
2529 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002530 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002531 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002532 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002533 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002534 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002535
Douglas Gregorb98b1992009-08-11 05:31:07 +00002536 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002537 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002538 }
John McCall43fed0d2010-11-12 08:19:04 +00002539
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002540 /// \brief Build a new template argument pack expansion.
2541 ///
2542 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002543 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002544 /// different behavior.
2545 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002546 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002547 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002548 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002549 case TemplateArgument::Expression: {
2550 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002551 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2552 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002553 if (Result.isInvalid())
2554 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002555
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002556 return TemplateArgumentLoc(Result.get(), Result.get());
2557 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002558
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002559 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002560 return TemplateArgumentLoc(TemplateArgument(
2561 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002562 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002563 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002564 Pattern.getTemplateNameLoc(),
2565 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002566
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002567 case TemplateArgument::Null:
2568 case TemplateArgument::Integral:
2569 case TemplateArgument::Declaration:
2570 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002571 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002572 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002573 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002574
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002575 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002576 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002577 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002578 EllipsisLoc,
2579 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002580 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2581 Expansion);
2582 break;
2583 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002584
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002585 return TemplateArgumentLoc();
2586 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002587
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002588 /// \brief Build a new expression pack expansion.
2589 ///
2590 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002592 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002593 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002594 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002595 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002596 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002597
2598 /// \brief Build a new atomic operation expression.
2599 ///
2600 /// By default, performs semantic analysis to build the new expression.
2601 /// Subclasses may override this routine to provide different behavior.
2602 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2603 MultiExprArg SubExprs,
2604 QualType RetTy,
2605 AtomicExpr::AtomicOp Op,
2606 SourceLocation RParenLoc) {
2607 // Just create the expression; there is not any interesting semantic
2608 // analysis here because we can't actually build an AtomicExpr until
2609 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002610 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002611 RParenLoc);
2612 }
2613
John McCall43fed0d2010-11-12 08:19:04 +00002614private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002615 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2616 QualType ObjectType,
2617 NamedDecl *FirstQualifierInScope,
2618 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002619
2620 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2621 QualType ObjectType,
2622 NamedDecl *FirstQualifierInScope,
2623 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002624};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002625
Douglas Gregor43959a92009-08-20 07:17:43 +00002626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002627StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002628 if (!S)
2629 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002630
Douglas Gregor43959a92009-08-20 07:17:43 +00002631 switch (S->getStmtClass()) {
2632 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002633
Douglas Gregor43959a92009-08-20 07:17:43 +00002634 // Transform individual statement nodes
2635#define STMT(Node, Parent) \
2636 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002637#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002638#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002639#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002640
Douglas Gregor43959a92009-08-20 07:17:43 +00002641 // Transform expressions by calling TransformExpr.
2642#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002643#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002644#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002645#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002646 {
John McCall60d7b3a2010-08-24 06:29:42 +00002647 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002648 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002649 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002650
Richard Smith41956372013-01-14 22:39:08 +00002651 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002652 }
Mike Stump1eb44332009-09-09 15:08:12 +00002653 }
2654
John McCall3fa5cae2010-10-26 07:05:15 +00002655 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002656}
Mike Stump1eb44332009-09-09 15:08:12 +00002657
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002658template<typename Derived>
2659OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2660 if (!S)
2661 return S;
2662
2663 switch (S->getClauseKind()) {
2664 default: break;
2665 // Transform individual clause nodes
2666#define OPENMP_CLAUSE(Name, Class) \
2667 case OMPC_ ## Name : \
2668 return getDerived().Transform ## Class(cast<Class>(S));
2669#include "clang/Basic/OpenMPKinds.def"
2670 }
2671
2672 return S;
2673}
2674
Mike Stump1eb44332009-09-09 15:08:12 +00002675
Douglas Gregor670444e2009-08-04 22:27:00 +00002676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002677ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002678 if (!E)
2679 return SemaRef.Owned(E);
2680
2681 switch (E->getStmtClass()) {
2682 case Stmt::NoStmtClass: break;
2683#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002684#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002685#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002686 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002687#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002688 }
2689
John McCall3fa5cae2010-10-26 07:05:15 +00002690 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002691}
2692
2693template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002694ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2695 bool CXXDirectInit) {
2696 // Initializers are instantiated like expressions, except that various outer
2697 // layers are stripped.
2698 if (!Init)
2699 return SemaRef.Owned(Init);
2700
2701 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2702 Init = ExprTemp->getSubExpr();
2703
Richard Smith858c2c32013-05-30 22:40:16 +00002704 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2705 Init = MTE->GetTemporaryExpr();
2706
Richard Smithc83c2302012-12-19 01:39:02 +00002707 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2708 Init = Binder->getSubExpr();
2709
2710 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2711 Init = ICE->getSubExprAsWritten();
2712
Richard Smith7c3e6152013-06-12 22:31:48 +00002713 if (CXXStdInitializerListExpr *ILE =
2714 dyn_cast<CXXStdInitializerListExpr>(Init))
2715 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2716
Richard Smith5cf15892012-12-21 08:13:35 +00002717 // If this is not a direct-initializer, we only need to reconstruct
2718 // InitListExprs. Other forms of copy-initialization will be a no-op if
2719 // the initializer is already the right type.
2720 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2721 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2722 return getDerived().TransformExpr(Init);
2723
2724 // Revert value-initialization back to empty parens.
2725 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2726 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002727 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002728 Parens.getEnd());
2729 }
2730
2731 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2732 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002733 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002734 SourceLocation());
2735
2736 // Revert initialization by constructor back to a parenthesized or braced list
2737 // of expressions. Any other form of initializer can just be reused directly.
2738 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002739 return getDerived().TransformExpr(Init);
2740
2741 SmallVector<Expr*, 8> NewArgs;
2742 bool ArgChanged = false;
2743 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2744 /*IsCall*/true, NewArgs, &ArgChanged))
2745 return ExprError();
2746
2747 // If this was list initialization, revert to list form.
2748 if (Construct->isListInitialization())
2749 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2750 Construct->getLocEnd(),
2751 Construct->getType());
2752
Richard Smithc83c2302012-12-19 01:39:02 +00002753 // Build a ParenListExpr to represent anything else.
2754 SourceRange Parens = Construct->getParenRange();
2755 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2756 Parens.getEnd());
2757}
2758
2759template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2761 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002762 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002763 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002764 bool *ArgChanged) {
2765 for (unsigned I = 0; I != NumInputs; ++I) {
2766 // If requested, drop call arguments that need to be dropped.
2767 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2768 if (ArgChanged)
2769 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
Douglas Gregoraa165f82011-01-03 19:04:46 +00002771 break;
2772 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002774 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2775 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
Chris Lattner686775d2011-07-20 06:58:45 +00002777 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002778 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2779 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002780
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002781 // Determine whether the set of unexpanded parameter packs can and should
2782 // be expanded.
2783 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002784 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002785 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2786 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002787 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2788 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002789 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002790 Expand, RetainExpansion,
2791 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002792 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002794 if (!Expand) {
2795 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002796 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002797 // expansion.
2798 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2799 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2800 if (OutPattern.isInvalid())
2801 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802
2803 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002804 Expansion->getEllipsisLoc(),
2805 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002806 if (Out.isInvalid())
2807 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002809 if (ArgChanged)
2810 *ArgChanged = true;
2811 Outputs.push_back(Out.get());
2812 continue;
2813 }
John McCallc8fc90a2011-07-06 07:30:07 +00002814
2815 // Record right away that the argument was changed. This needs
2816 // to happen even if the array expands to nothing.
2817 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002819 // The transform has determined that we should perform an elementwise
2820 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002821 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002822 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2823 ExprResult Out = getDerived().TransformExpr(Pattern);
2824 if (Out.isInvalid())
2825 return true;
2826
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002827 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002828 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2829 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002830 if (Out.isInvalid())
2831 return true;
2832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002834 Outputs.push_back(Out.get());
2835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002837 continue;
2838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002839
Richard Smithc83c2302012-12-19 01:39:02 +00002840 ExprResult Result =
2841 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2842 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002843 if (Result.isInvalid())
2844 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
Douglas Gregoraa165f82011-01-03 19:04:46 +00002846 if (Result.get() != Inputs[I] && ArgChanged)
2847 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
2849 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002850 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002851
Douglas Gregoraa165f82011-01-03 19:04:46 +00002852 return false;
2853}
2854
2855template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002856NestedNameSpecifierLoc
2857TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2858 NestedNameSpecifierLoc NNS,
2859 QualType ObjectType,
2860 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002861 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002863 Qualifier = Qualifier.getPrefix())
2864 Qualifiers.push_back(Qualifier);
2865
2866 CXXScopeSpec SS;
2867 while (!Qualifiers.empty()) {
2868 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2869 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002871 switch (QNNS->getKind()) {
2872 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002874 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002876 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002877 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002878 FirstQualifierInScope, false))
2879 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002882
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002883 case NestedNameSpecifier::Namespace: {
2884 NamespaceDecl *NS
2885 = cast_or_null<NamespaceDecl>(
2886 getDerived().TransformDecl(
2887 Q.getLocalBeginLoc(),
2888 QNNS->getAsNamespace()));
2889 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2890 break;
2891 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002892
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002893 case NestedNameSpecifier::NamespaceAlias: {
2894 NamespaceAliasDecl *Alias
2895 = cast_or_null<NamespaceAliasDecl>(
2896 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2897 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 Q.getLocalEndLoc());
2900 break;
2901 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002902
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002903 case NestedNameSpecifier::Global:
2904 // There is no meaningful transformation that one could perform on the
2905 // global scope.
2906 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2907 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002908
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002909 case NestedNameSpecifier::TypeSpecWithTemplate:
2910 case NestedNameSpecifier::TypeSpec: {
2911 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2912 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002913
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002914 if (!TL)
2915 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002917 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002918 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002919 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002920 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002921 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002922 if (TL.getType()->isEnumeralType())
2923 SemaRef.Diag(TL.getBeginLoc(),
2924 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002925 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2926 Q.getLocalEndLoc());
2927 break;
2928 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002929 // If the nested-name-specifier is an invalid type def, don't emit an
2930 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002931 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2932 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002934 << TL.getType() << SS.getRange();
2935 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002936 return NestedNameSpecifierLoc();
2937 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002938 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002939
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002940 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002941 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002942 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002943 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002945 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002947 !getDerived().AlwaysRebuild())
2948 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
2950 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002951 // nested-name-specifier, do so.
2952 if (SS.location_size() == NNS.getDataLength() &&
2953 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2954 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2955
2956 // Allocate new nested-name-specifier location information.
2957 return SS.getWithLocInContext(SemaRef.Context);
2958}
2959
2960template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002961DeclarationNameInfo
2962TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002963::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002964 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002965 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002966 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002967
2968 switch (Name.getNameKind()) {
2969 case DeclarationName::Identifier:
2970 case DeclarationName::ObjCZeroArgSelector:
2971 case DeclarationName::ObjCOneArgSelector:
2972 case DeclarationName::ObjCMultiArgSelector:
2973 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002974 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002975 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002976 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002977
Douglas Gregor81499bb2009-09-03 22:13:48 +00002978 case DeclarationName::CXXConstructorName:
2979 case DeclarationName::CXXDestructorName:
2980 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002981 TypeSourceInfo *NewTInfo;
2982 CanQualType NewCanTy;
2983 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002984 NewTInfo = getDerived().TransformType(OldTInfo);
2985 if (!NewTInfo)
2986 return DeclarationNameInfo();
2987 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002988 }
2989 else {
2990 NewTInfo = 0;
2991 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002992 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002993 if (NewT.isNull())
2994 return DeclarationNameInfo();
2995 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2996 }
Mike Stump1eb44332009-09-09 15:08:12 +00002997
Abramo Bagnara25777432010-08-11 22:01:17 +00002998 DeclarationName NewName
2999 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3000 NewCanTy);
3001 DeclarationNameInfo NewNameInfo(NameInfo);
3002 NewNameInfo.setName(NewName);
3003 NewNameInfo.setNamedTypeInfo(NewTInfo);
3004 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003005 }
Mike Stump1eb44332009-09-09 15:08:12 +00003006 }
3007
David Blaikieb219cfc2011-09-23 05:06:16 +00003008 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003009}
3010
3011template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003012TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003013TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3014 TemplateName Name,
3015 SourceLocation NameLoc,
3016 QualType ObjectType,
3017 NamedDecl *FirstQualifierInScope) {
3018 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3019 TemplateDecl *Template = QTN->getTemplateDecl();
3020 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003021
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003022 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003023 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003024 Template));
3025 if (!TransTemplate)
3026 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003027
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003028 if (!getDerived().AlwaysRebuild() &&
3029 SS.getScopeRep() == QTN->getQualifier() &&
3030 TransTemplate == Template)
3031 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003033 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3034 TransTemplate);
3035 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003036
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003037 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3038 if (SS.getScopeRep()) {
3039 // These apply to the scope specifier, not the template.
3040 ObjectType = QualType();
3041 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003042 }
3043
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003044 if (!getDerived().AlwaysRebuild() &&
3045 SS.getScopeRep() == DTN->getQualifier() &&
3046 ObjectType.isNull())
3047 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003048
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003049 if (DTN->isIdentifier()) {
3050 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003051 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003052 NameLoc,
3053 ObjectType,
3054 FirstQualifierInScope);
3055 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003056
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003057 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3058 ObjectType);
3059 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003060
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003061 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3062 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003063 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003064 Template));
3065 if (!TransTemplate)
3066 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003067
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003068 if (!getDerived().AlwaysRebuild() &&
3069 TransTemplate == Template)
3070 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003071
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003072 return TemplateName(TransTemplate);
3073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003074
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003075 if (SubstTemplateTemplateParmPackStorage *SubstPack
3076 = Name.getAsSubstTemplateTemplateParmPack()) {
3077 TemplateTemplateParmDecl *TransParam
3078 = cast_or_null<TemplateTemplateParmDecl>(
3079 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3080 if (!TransParam)
3081 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003082
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003083 if (!getDerived().AlwaysRebuild() &&
3084 TransParam == SubstPack->getParameterPack())
3085 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003086
3087 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003088 SubstPack->getArgumentPack());
3089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003090
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003091 // These should be getting filtered out before they reach the AST.
3092 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003093}
3094
3095template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003096void TreeTransform<Derived>::InventTemplateArgumentLoc(
3097 const TemplateArgument &Arg,
3098 TemplateArgumentLoc &Output) {
3099 SourceLocation Loc = getDerived().getBaseLocation();
3100 switch (Arg.getKind()) {
3101 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003102 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003103 break;
3104
3105 case TemplateArgument::Type:
3106 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003107 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
John McCall833ca992009-10-29 08:12:44 +00003109 break;
3110
Douglas Gregor788cd062009-11-11 01:00:40 +00003111 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003112 case TemplateArgument::TemplateExpansion: {
3113 NestedNameSpecifierLocBuilder Builder;
3114 TemplateName Template = Arg.getAsTemplate();
3115 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3116 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3117 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3118 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003120 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003122 Builder.getWithLocInContext(SemaRef.Context),
3123 Loc);
3124 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003126 Builder.getWithLocInContext(SemaRef.Context),
3127 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003128
Douglas Gregor788cd062009-11-11 01:00:40 +00003129 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003130 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003131
John McCall833ca992009-10-29 08:12:44 +00003132 case TemplateArgument::Expression:
3133 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3134 break;
3135
3136 case TemplateArgument::Declaration:
3137 case TemplateArgument::Integral:
3138 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003139 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003140 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003141 break;
3142 }
3143}
3144
3145template<typename Derived>
3146bool TreeTransform<Derived>::TransformTemplateArgument(
3147 const TemplateArgumentLoc &Input,
3148 TemplateArgumentLoc &Output) {
3149 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003150 switch (Arg.getKind()) {
3151 case TemplateArgument::Null:
3152 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003153 case TemplateArgument::Pack:
3154 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003155 case TemplateArgument::NullPtr:
3156 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003157
Douglas Gregor670444e2009-08-04 22:27:00 +00003158 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003159 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003160 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003161 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003162
3163 DI = getDerived().TransformType(DI);
3164 if (!DI) return true;
3165
3166 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3167 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003168 }
Mike Stump1eb44332009-09-09 15:08:12 +00003169
Douglas Gregor788cd062009-11-11 01:00:40 +00003170 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003171 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3172 if (QualifierLoc) {
3173 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3174 if (!QualifierLoc)
3175 return true;
3176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003177
Douglas Gregor1d752d72011-03-02 18:46:51 +00003178 CXXScopeSpec SS;
3179 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003180 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003181 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3182 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003183 if (Template.isNull())
3184 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003186 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003187 Input.getTemplateNameLoc());
3188 return false;
3189 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003190
3191 case TemplateArgument::TemplateExpansion:
3192 llvm_unreachable("Caller should expand pack expansions");
3193
Douglas Gregor670444e2009-08-04 22:27:00 +00003194 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003195 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003196 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003197 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003198
John McCall833ca992009-10-29 08:12:44 +00003199 Expr *InputExpr = Input.getSourceExpression();
3200 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3201
Chris Lattner223de242011-04-25 20:37:58 +00003202 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003203 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003204 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003205 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003206 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003207 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003208 }
Mike Stump1eb44332009-09-09 15:08:12 +00003209
Douglas Gregor670444e2009-08-04 22:27:00 +00003210 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003211 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003212}
3213
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003214/// \brief Iterator adaptor that invents template argument location information
3215/// for each of the template arguments in its underlying iterator.
3216template<typename Derived, typename InputIterator>
3217class TemplateArgumentLocInventIterator {
3218 TreeTransform<Derived> &Self;
3219 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003221public:
3222 typedef TemplateArgumentLoc value_type;
3223 typedef TemplateArgumentLoc reference;
3224 typedef typename std::iterator_traits<InputIterator>::difference_type
3225 difference_type;
3226 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003227
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003228 class pointer {
3229 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003230
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003231 public:
3232 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003234 const TemplateArgumentLoc *operator->() const { return &Arg; }
3235 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003237 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003239 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3240 InputIterator Iter)
3241 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003243 TemplateArgumentLocInventIterator &operator++() {
3244 ++Iter;
3245 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003248 TemplateArgumentLocInventIterator operator++(int) {
3249 TemplateArgumentLocInventIterator Old(*this);
3250 ++(*this);
3251 return Old;
3252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003254 reference operator*() const {
3255 TemplateArgumentLoc Result;
3256 Self.InventTemplateArgumentLoc(*Iter, Result);
3257 return Result;
3258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003260 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003262 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3263 const TemplateArgumentLocInventIterator &Y) {
3264 return X.Iter == Y.Iter;
3265 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003266
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003267 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3268 const TemplateArgumentLocInventIterator &Y) {
3269 return X.Iter != Y.Iter;
3270 }
3271};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003273template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003274template<typename InputIterator>
3275bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3276 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003277 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003278 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003279 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003280 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003282 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3283 // Unpack argument packs, which we translate them into separate
3284 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003285 // FIXME: We could do much better if we could guarantee that the
3286 // TemplateArgumentLocInfo for the pack expansion would be usable for
3287 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003289 TemplateArgument::pack_iterator>
3290 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003292 In.getArgument().pack_begin()),
3293 PackLocIterator(*this,
3294 In.getArgument().pack_end()),
3295 Outputs))
3296 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003298 continue;
3299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003300
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003301 if (In.getArgument().isPackExpansion()) {
3302 // We have a pack expansion, for which we will be substituting into
3303 // the pattern.
3304 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003305 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003306 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003307 = getSema().getTemplateArgumentPackExpansionPattern(
3308 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003309
Chris Lattner686775d2011-07-20 06:58:45 +00003310 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003311 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3312 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003314 // Determine whether the set of unexpanded parameter packs can and should
3315 // be expanded.
3316 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003317 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003318 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003319 if (getDerived().TryExpandParameterPacks(Ellipsis,
3320 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003321 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003323 RetainExpansion,
3324 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003325 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003326
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003327 if (!Expand) {
3328 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003329 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003330 // expansion.
3331 TemplateArgumentLoc OutPattern;
3332 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3333 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3334 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003335
Douglas Gregorcded4f62011-01-14 17:04:44 +00003336 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3337 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003338 if (Out.getArgument().isNull())
3339 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003340
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003341 Outputs.addArgument(Out);
3342 continue;
3343 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003345 // The transform has determined that we should perform an elementwise
3346 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003347 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003348 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3349
3350 if (getDerived().TransformTemplateArgument(Pattern, Out))
3351 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003353 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003354 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3355 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003356 if (Out.getArgument().isNull())
3357 return true;
3358 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003359
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003360 Outputs.addArgument(Out);
3361 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003362
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003363 // If we're supposed to retain a pack expansion, do so by temporarily
3364 // forgetting the partially-substituted parameter pack.
3365 if (RetainExpansion) {
3366 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003367
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003368 if (getDerived().TransformTemplateArgument(Pattern, Out))
3369 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregorcded4f62011-01-14 17:04:44 +00003371 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3372 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003373 if (Out.getArgument().isNull())
3374 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003375
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003376 Outputs.addArgument(Out);
3377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003379 continue;
3380 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003381
3382 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003383 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003384 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003385
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003386 Outputs.addArgument(Out);
3387 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003388
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003389 return false;
3390
3391}
3392
Douglas Gregor577f75a2009-08-04 16:50:30 +00003393//===----------------------------------------------------------------------===//
3394// Type transformation
3395//===----------------------------------------------------------------------===//
3396
3397template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003398QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003399 if (getDerived().AlreadyTransformed(T))
3400 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003401
John McCalla2becad2009-10-21 00:40:46 +00003402 // Temporary workaround. All of these transformations should
3403 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003404 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3405 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
John McCall43fed0d2010-11-12 08:19:04 +00003407 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003408
John McCalla2becad2009-10-21 00:40:46 +00003409 if (!NewDI)
3410 return QualType();
3411
3412 return NewDI->getType();
3413}
3414
3415template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003416TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003417 // Refine the base location to the type's location.
3418 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3419 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003420 if (getDerived().AlreadyTransformed(DI->getType()))
3421 return DI;
3422
3423 TypeLocBuilder TLB;
3424
3425 TypeLoc TL = DI->getTypeLoc();
3426 TLB.reserve(TL.getFullDataSize());
3427
John McCall43fed0d2010-11-12 08:19:04 +00003428 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003429 if (Result.isNull())
3430 return 0;
3431
John McCalla93c9342009-12-07 02:54:59 +00003432 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003433}
3434
3435template<typename Derived>
3436QualType
John McCall43fed0d2010-11-12 08:19:04 +00003437TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003438 switch (T.getTypeLocClass()) {
3439#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003440#define TYPELOC(CLASS, PARENT) \
3441 case TypeLoc::CLASS: \
3442 return getDerived().Transform##CLASS##Type(TLB, \
3443 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003444#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003445 }
Mike Stump1eb44332009-09-09 15:08:12 +00003446
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003447 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003448}
3449
3450/// FIXME: By default, this routine adds type qualifiers only to types
3451/// that can have qualifiers, and silently suppresses those qualifiers
3452/// that are not permitted (e.g., qualifiers on reference or function
3453/// types). This is the right thing for template instantiation, but
3454/// probably not for other clients.
3455template<typename Derived>
3456QualType
3457TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003458 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003459 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003460
John McCall43fed0d2010-11-12 08:19:04 +00003461 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003462 if (Result.isNull())
3463 return QualType();
3464
3465 // Silently suppress qualifiers if the result type can't be qualified.
3466 // FIXME: this is the right thing for template instantiation, but
3467 // probably not for other clients.
3468 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003469 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003470
John McCallf85e1932011-06-15 23:02:42 +00003471 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003472 // resulting type.
3473 if (Quals.hasObjCLifetime()) {
3474 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3475 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003476 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003478 // A lifetime qualifier applied to a substituted template parameter
3479 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003480 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003481 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003482 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3483 QualType Replacement = SubstTypeParam->getReplacementType();
3484 Qualifiers Qs = Replacement.getQualifiers();
3485 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003486 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003487 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3488 Qs);
3489 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003491 Replacement);
3492 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003493 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3494 // 'auto' types behave the same way as template parameters.
3495 QualType Deduced = AutoTy->getDeducedType();
3496 Qualifiers Qs = Deduced.getQualifiers();
3497 Qs.removeObjCLifetime();
3498 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3499 Qs);
Faisal Valiecb58192013-08-22 01:49:11 +00003500 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3501 AutoTy->isDependentType(),
3502 AutoTy->containsUnexpandedParameterPack());
Douglas Gregor92d13872013-01-17 23:59:28 +00003503 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003504 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003505 // Otherwise, complain about the addition of a qualifier to an
3506 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003507 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003508 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003509 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003510
Douglas Gregore559ca12011-06-17 22:11:49 +00003511 Quals.removeObjCLifetime();
3512 }
3513 }
3514 }
John McCall28654742010-06-05 06:41:15 +00003515 if (!Quals.empty()) {
3516 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003517 // BuildQualifiedType might not add qualifiers if they are invalid.
3518 if (Result.hasLocalQualifiers())
3519 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003520 // No location information to preserve.
3521 }
John McCalla2becad2009-10-21 00:40:46 +00003522
3523 return Result;
3524}
3525
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003526template<typename Derived>
3527TypeLoc
3528TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3529 QualType ObjectType,
3530 NamedDecl *UnqualLookup,
3531 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003532 QualType T = TL.getType();
3533 if (getDerived().AlreadyTransformed(T))
3534 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003535
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003536 TypeLocBuilder TLB;
3537 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003539 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003540 TemplateSpecializationTypeLoc SpecTL =
3541 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003542
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003543 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003544 getDerived().TransformTemplateName(SS,
3545 SpecTL.getTypePtr()->getTemplateName(),
3546 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003547 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003548 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003549 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
3551 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003552 Template);
3553 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003554 DependentTemplateSpecializationTypeLoc SpecTL =
3555 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003556
Douglas Gregora88f09f2011-02-28 17:23:35 +00003557 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003558 = getDerived().RebuildTemplateName(SS,
3559 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003560 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003561 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003562 if (Template.isNull())
3563 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003564
3565 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003566 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003567 Template,
3568 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003569 } else {
3570 // Nothing special needs to be done for these.
3571 Result = getDerived().TransformType(TLB, TL);
3572 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003573
3574 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003575 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003576
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003577 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3578}
3579
Douglas Gregorb71d8212011-03-02 18:32:08 +00003580template<typename Derived>
3581TypeSourceInfo *
3582TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3583 QualType ObjectType,
3584 NamedDecl *UnqualLookup,
3585 CXXScopeSpec &SS) {
3586 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003587
Douglas Gregorb71d8212011-03-02 18:32:08 +00003588 QualType T = TSInfo->getType();
3589 if (getDerived().AlreadyTransformed(T))
3590 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003591
Douglas Gregorb71d8212011-03-02 18:32:08 +00003592 TypeLocBuilder TLB;
3593 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003594
Douglas Gregorb71d8212011-03-02 18:32:08 +00003595 TypeLoc TL = TSInfo->getTypeLoc();
3596 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003597 TemplateSpecializationTypeLoc SpecTL =
3598 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003599
Douglas Gregorb71d8212011-03-02 18:32:08 +00003600 TemplateName Template
3601 = getDerived().TransformTemplateName(SS,
3602 SpecTL.getTypePtr()->getTemplateName(),
3603 SpecTL.getTemplateNameLoc(),
3604 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003605 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003606 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003607
3608 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003609 Template);
3610 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003611 DependentTemplateSpecializationTypeLoc SpecTL =
3612 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003613
Douglas Gregorb71d8212011-03-02 18:32:08 +00003614 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615 = getDerived().RebuildTemplateName(SS,
3616 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003617 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003618 ObjectType, UnqualLookup);
3619 if (Template.isNull())
3620 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003621
3622 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003623 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003624 Template,
3625 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003626 } else {
3627 // Nothing special needs to be done for these.
3628 Result = getDerived().TransformType(TLB, TL);
3629 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003630
3631 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003632 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003633
Douglas Gregorb71d8212011-03-02 18:32:08 +00003634 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3635}
3636
John McCalla2becad2009-10-21 00:40:46 +00003637template <class TyLoc> static inline
3638QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3639 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3640 NewT.setNameLoc(T.getNameLoc());
3641 return T.getType();
3642}
3643
John McCalla2becad2009-10-21 00:40:46 +00003644template<typename Derived>
3645QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003646 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003647 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3648 NewT.setBuiltinLoc(T.getBuiltinLoc());
3649 if (T.needsExtraLocalData())
3650 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3651 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003652}
Mike Stump1eb44332009-09-09 15:08:12 +00003653
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003655QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003656 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003657 // FIXME: recurse?
3658 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659}
Mike Stump1eb44332009-09-09 15:08:12 +00003660
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003662QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3663 DecayedTypeLoc TL) {
3664 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3665 if (OriginalType.isNull())
3666 return QualType();
3667
3668 QualType Result = TL.getType();
3669 if (getDerived().AlwaysRebuild() ||
3670 OriginalType != TL.getOriginalLoc().getType())
3671 Result = SemaRef.Context.getDecayedType(OriginalType);
3672 TLB.push<DecayedTypeLoc>(Result);
3673 // Nothing to set for DecayedTypeLoc.
3674 return Result;
3675}
3676
3677template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003678QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003679 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003680 QualType PointeeType
3681 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003682 if (PointeeType.isNull())
3683 return QualType();
3684
3685 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003686 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003687 // A dependent pointer type 'T *' has is being transformed such
3688 // that an Objective-C class type is being replaced for 'T'. The
3689 // resulting pointer type is an ObjCObjectPointerType, not a
3690 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003691 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003692
John McCallc12c5bb2010-05-15 11:32:37 +00003693 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3694 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003695 return Result;
3696 }
John McCall43fed0d2010-11-12 08:19:04 +00003697
Douglas Gregor92e986e2010-04-22 16:44:27 +00003698 if (getDerived().AlwaysRebuild() ||
3699 PointeeType != TL.getPointeeLoc().getType()) {
3700 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3701 if (Result.isNull())
3702 return QualType();
3703 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003704
John McCallf85e1932011-06-15 23:02:42 +00003705 // Objective-C ARC can add lifetime qualifiers to the type that we're
3706 // pointing to.
3707 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003708
Douglas Gregor92e986e2010-04-22 16:44:27 +00003709 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3710 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003711 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003712}
Mike Stump1eb44332009-09-09 15:08:12 +00003713
3714template<typename Derived>
3715QualType
John McCalla2becad2009-10-21 00:40:46 +00003716TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003717 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003718 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003719 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3720 if (PointeeType.isNull())
3721 return QualType();
3722
3723 QualType Result = TL.getType();
3724 if (getDerived().AlwaysRebuild() ||
3725 PointeeType != TL.getPointeeLoc().getType()) {
3726 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003727 TL.getSigilLoc());
3728 if (Result.isNull())
3729 return QualType();
3730 }
3731
Douglas Gregor39968ad2010-04-22 16:50:51 +00003732 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003733 NewT.setSigilLoc(TL.getSigilLoc());
3734 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003735}
3736
John McCall85737a72009-10-30 00:06:24 +00003737/// Transforms a reference type. Note that somewhat paradoxically we
3738/// don't care whether the type itself is an l-value type or an r-value
3739/// type; we only care if the type was *written* as an l-value type
3740/// or an r-value type.
3741template<typename Derived>
3742QualType
3743TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003744 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003745 const ReferenceType *T = TL.getTypePtr();
3746
3747 // Note that this works with the pointee-as-written.
3748 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3749 if (PointeeType.isNull())
3750 return QualType();
3751
3752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 PointeeType != T->getPointeeTypeAsWritten()) {
3755 Result = getDerived().RebuildReferenceType(PointeeType,
3756 T->isSpelledAsLValue(),
3757 TL.getSigilLoc());
3758 if (Result.isNull())
3759 return QualType();
3760 }
3761
John McCallf85e1932011-06-15 23:02:42 +00003762 // Objective-C ARC can add lifetime qualifiers to the type that we're
3763 // referring to.
3764 TLB.TypeWasModifiedSafely(
3765 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3766
John McCall85737a72009-10-30 00:06:24 +00003767 // r-value references can be rebuilt as l-value references.
3768 ReferenceTypeLoc NewTL;
3769 if (isa<LValueReferenceType>(Result))
3770 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3771 else
3772 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3773 NewTL.setSigilLoc(TL.getSigilLoc());
3774
3775 return Result;
3776}
3777
Mike Stump1eb44332009-09-09 15:08:12 +00003778template<typename Derived>
3779QualType
John McCalla2becad2009-10-21 00:40:46 +00003780TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003781 LValueReferenceTypeLoc TL) {
3782 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003783}
3784
Mike Stump1eb44332009-09-09 15:08:12 +00003785template<typename Derived>
3786QualType
John McCalla2becad2009-10-21 00:40:46 +00003787TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003788 RValueReferenceTypeLoc TL) {
3789 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003790}
Mike Stump1eb44332009-09-09 15:08:12 +00003791
Douglas Gregor577f75a2009-08-04 16:50:30 +00003792template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003793QualType
John McCalla2becad2009-10-21 00:40:46 +00003794TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003795 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003796 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003797 if (PointeeType.isNull())
3798 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003799
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003800 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3801 TypeSourceInfo* NewClsTInfo = 0;
3802 if (OldClsTInfo) {
3803 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3804 if (!NewClsTInfo)
3805 return QualType();
3806 }
3807
3808 const MemberPointerType *T = TL.getTypePtr();
3809 QualType OldClsType = QualType(T->getClass(), 0);
3810 QualType NewClsType;
3811 if (NewClsTInfo)
3812 NewClsType = NewClsTInfo->getType();
3813 else {
3814 NewClsType = getDerived().TransformType(OldClsType);
3815 if (NewClsType.isNull())
3816 return QualType();
3817 }
Mike Stump1eb44332009-09-09 15:08:12 +00003818
John McCalla2becad2009-10-21 00:40:46 +00003819 QualType Result = TL.getType();
3820 if (getDerived().AlwaysRebuild() ||
3821 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003822 NewClsType != OldClsType) {
3823 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003824 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003825 if (Result.isNull())
3826 return QualType();
3827 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003828
John McCalla2becad2009-10-21 00:40:46 +00003829 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3830 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003831 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003832
3833 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834}
3835
Mike Stump1eb44332009-09-09 15:08:12 +00003836template<typename Derived>
3837QualType
John McCalla2becad2009-10-21 00:40:46 +00003838TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003839 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003840 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003841 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003842 if (ElementType.isNull())
3843 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003844
John McCalla2becad2009-10-21 00:40:46 +00003845 QualType Result = TL.getType();
3846 if (getDerived().AlwaysRebuild() ||
3847 ElementType != T->getElementType()) {
3848 Result = getDerived().RebuildConstantArrayType(ElementType,
3849 T->getSizeModifier(),
3850 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003851 T->getIndexTypeCVRQualifiers(),
3852 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003853 if (Result.isNull())
3854 return QualType();
3855 }
Eli Friedman457a3772012-01-25 22:19:07 +00003856
3857 // We might have either a ConstantArrayType or a VariableArrayType now:
3858 // a ConstantArrayType is allowed to have an element type which is a
3859 // VariableArrayType if the type is dependent. Fortunately, all array
3860 // types have the same location layout.
3861 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003862 NewTL.setLBracketLoc(TL.getLBracketLoc());
3863 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003864
John McCalla2becad2009-10-21 00:40:46 +00003865 Expr *Size = TL.getSizeExpr();
3866 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003867 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3868 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003869 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003870 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003871 }
3872 NewTL.setSizeExpr(Size);
3873
3874 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875}
Mike Stump1eb44332009-09-09 15:08:12 +00003876
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003879 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003880 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003881 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003882 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883 if (ElementType.isNull())
3884 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003885
John McCalla2becad2009-10-21 00:40:46 +00003886 QualType Result = TL.getType();
3887 if (getDerived().AlwaysRebuild() ||
3888 ElementType != T->getElementType()) {
3889 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003890 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003891 T->getIndexTypeCVRQualifiers(),
3892 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003893 if (Result.isNull())
3894 return QualType();
3895 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003896
John McCalla2becad2009-10-21 00:40:46 +00003897 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3898 NewTL.setLBracketLoc(TL.getLBracketLoc());
3899 NewTL.setRBracketLoc(TL.getRBracketLoc());
3900 NewTL.setSizeExpr(0);
3901
3902 return Result;
3903}
3904
3905template<typename Derived>
3906QualType
3907TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003908 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003909 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003910 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3911 if (ElementType.isNull())
3912 return QualType();
3913
John McCall60d7b3a2010-08-24 06:29:42 +00003914 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003915 = getDerived().TransformExpr(T->getSizeExpr());
3916 if (SizeResult.isInvalid())
3917 return QualType();
3918
John McCall9ae2f072010-08-23 23:25:46 +00003919 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003920
3921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
3923 ElementType != T->getElementType() ||
3924 Size != T->getSizeExpr()) {
3925 Result = getDerived().RebuildVariableArrayType(ElementType,
3926 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003927 Size,
John McCalla2becad2009-10-21 00:40:46 +00003928 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003929 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003930 if (Result.isNull())
3931 return QualType();
3932 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003933
John McCalla2becad2009-10-21 00:40:46 +00003934 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3935 NewTL.setLBracketLoc(TL.getLBracketLoc());
3936 NewTL.setRBracketLoc(TL.getRBracketLoc());
3937 NewTL.setSizeExpr(Size);
3938
3939 return Result;
3940}
3941
3942template<typename Derived>
3943QualType
3944TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003945 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003946 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003947 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3948 if (ElementType.isNull())
3949 return QualType();
3950
Richard Smithf6702a32011-12-20 02:08:33 +00003951 // Array bounds are constant expressions.
3952 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3953 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003954
John McCall3b657512011-01-19 10:06:00 +00003955 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3956 Expr *origSize = TL.getSizeExpr();
3957 if (!origSize) origSize = T->getSizeExpr();
3958
3959 ExprResult sizeResult
3960 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003961 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003962 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003963 return QualType();
3964
John McCall3b657512011-01-19 10:06:00 +00003965 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003966
3967 QualType Result = TL.getType();
3968 if (getDerived().AlwaysRebuild() ||
3969 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003970 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003971 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3972 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003973 size,
John McCalla2becad2009-10-21 00:40:46 +00003974 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003975 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003976 if (Result.isNull())
3977 return QualType();
3978 }
John McCalla2becad2009-10-21 00:40:46 +00003979
3980 // We might have any sort of array type now, but fortunately they
3981 // all have the same location layout.
3982 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3983 NewTL.setLBracketLoc(TL.getLBracketLoc());
3984 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003985 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003986
3987 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003988}
Mike Stump1eb44332009-09-09 15:08:12 +00003989
3990template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003991QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003992 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003993 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003994 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003995
3996 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003997 QualType ElementType = getDerived().TransformType(T->getElementType());
3998 if (ElementType.isNull())
3999 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004000
Richard Smithf6702a32011-12-20 02:08:33 +00004001 // Vector sizes are constant expressions.
4002 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4003 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004004
John McCall60d7b3a2010-08-24 06:29:42 +00004005 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004006 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004007 if (Size.isInvalid())
4008 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004009
John McCalla2becad2009-10-21 00:40:46 +00004010 QualType Result = TL.getType();
4011 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004012 ElementType != T->getElementType() ||
4013 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004014 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004015 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004016 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004017 if (Result.isNull())
4018 return QualType();
4019 }
John McCalla2becad2009-10-21 00:40:46 +00004020
4021 // Result might be dependent or not.
4022 if (isa<DependentSizedExtVectorType>(Result)) {
4023 DependentSizedExtVectorTypeLoc NewTL
4024 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4025 NewTL.setNameLoc(TL.getNameLoc());
4026 } else {
4027 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4028 NewTL.setNameLoc(TL.getNameLoc());
4029 }
4030
4031 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004032}
Mike Stump1eb44332009-09-09 15:08:12 +00004033
4034template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004035QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004036 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004037 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004038 QualType ElementType = getDerived().TransformType(T->getElementType());
4039 if (ElementType.isNull())
4040 return QualType();
4041
John McCalla2becad2009-10-21 00:40:46 +00004042 QualType Result = TL.getType();
4043 if (getDerived().AlwaysRebuild() ||
4044 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004045 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004046 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004047 if (Result.isNull())
4048 return QualType();
4049 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004050
John McCalla2becad2009-10-21 00:40:46 +00004051 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4052 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004053
John McCalla2becad2009-10-21 00:40:46 +00004054 return Result;
4055}
4056
4057template<typename Derived>
4058QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004059 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004060 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004061 QualType ElementType = getDerived().TransformType(T->getElementType());
4062 if (ElementType.isNull())
4063 return QualType();
4064
4065 QualType Result = TL.getType();
4066 if (getDerived().AlwaysRebuild() ||
4067 ElementType != T->getElementType()) {
4068 Result = getDerived().RebuildExtVectorType(ElementType,
4069 T->getNumElements(),
4070 /*FIXME*/ SourceLocation());
4071 if (Result.isNull())
4072 return QualType();
4073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074
John McCalla2becad2009-10-21 00:40:46 +00004075 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4076 NewTL.setNameLoc(TL.getNameLoc());
4077
4078 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004079}
Mike Stump1eb44332009-09-09 15:08:12 +00004080
David Blaikiedc84cd52013-02-20 22:23:23 +00004081template <typename Derived>
4082ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4083 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4084 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004085 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004086 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004088 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004089 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004090 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004091 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004092 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004093
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004094 TypeLocBuilder TLB;
4095 TypeLoc NewTL = OldDI->getTypeLoc();
4096 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097
4098 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004099 OldExpansionTL.getPatternLoc());
4100 if (Result.isNull())
4101 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
4103 Result = RebuildPackExpansionType(Result,
4104 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004105 OldExpansionTL.getEllipsisLoc(),
4106 NumExpansions);
4107 if (Result.isNull())
4108 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004109
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004110 PackExpansionTypeLoc NewExpansionTL
4111 = TLB.push<PackExpansionTypeLoc>(Result);
4112 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4113 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4114 } else
4115 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004116 if (!NewDI)
4117 return 0;
4118
John McCallfb44de92011-05-01 22:35:37 +00004119 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004120 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004121
4122 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4123 OldParm->getDeclContext(),
4124 OldParm->getInnerLocStart(),
4125 OldParm->getLocation(),
4126 OldParm->getIdentifier(),
4127 NewDI->getType(),
4128 NewDI,
4129 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004130 /* DefArg */ NULL);
4131 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4132 OldParm->getFunctionScopeIndex() + indexAdjustment);
4133 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004134}
4135
4136template<typename Derived>
4137bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004138 TransformFunctionTypeParams(SourceLocation Loc,
4139 ParmVarDecl **Params, unsigned NumParams,
4140 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004141 SmallVectorImpl<QualType> &OutParamTypes,
4142 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004143 int indexAdjustment = 0;
4144
Douglas Gregora009b592011-01-07 00:20:55 +00004145 for (unsigned i = 0; i != NumParams; ++i) {
4146 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004147 assert(OldParm->getFunctionScopeIndex() == i);
4148
David Blaikiedc84cd52013-02-20 22:23:23 +00004149 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004150 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 if (OldParm->isParameterPack()) {
4152 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004153 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004154
Douglas Gregor603cfb42011-01-05 23:12:31 +00004155 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004156 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004157 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004158 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4159 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004160 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4161
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 // Determine whether we should expand the parameter packs.
4163 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004164 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004165 Optional<unsigned> OrigNumExpansions =
4166 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004167 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004168 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4169 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004170 Unexpanded,
4171 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004172 RetainExpansion,
4173 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 return true;
4175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 if (ShouldExpand) {
4178 // Expand the function parameter pack into multiple, separate
4179 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004180 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004181 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004182 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004183 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004184 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004185 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004186 OrigNumExpansions,
4187 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004188 if (!NewParm)
4189 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004190
Douglas Gregora009b592011-01-07 00:20:55 +00004191 OutParamTypes.push_back(NewParm->getType());
4192 if (PVars)
4193 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004194 }
Douglas Gregord3731192011-01-10 07:32:04 +00004195
4196 // If we're supposed to retain a pack expansion, do so by temporarily
4197 // forgetting the partially-substituted parameter pack.
4198 if (RetainExpansion) {
4199 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004201 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004202 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004203 OrigNumExpansions,
4204 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004205 if (!NewParm)
4206 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207
Douglas Gregord3731192011-01-10 07:32:04 +00004208 OutParamTypes.push_back(NewParm->getType());
4209 if (PVars)
4210 PVars->push_back(NewParm);
4211 }
4212
John McCallfb44de92011-05-01 22:35:37 +00004213 // The next parameter should have the same adjustment as the
4214 // last thing we pushed, but we post-incremented indexAdjustment
4215 // on every push. Also, if we push nothing, the adjustment should
4216 // go down by one.
4217 indexAdjustment--;
4218
Douglas Gregor603cfb42011-01-05 23:12:31 +00004219 // We're done with the pack expansion.
4220 continue;
4221 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222
4223 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004224 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004225 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4226 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004227 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004228 NumExpansions,
4229 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004230 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004231 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004232 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004233 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004234
John McCall21ef0fa2010-03-11 09:03:00 +00004235 if (!NewParm)
4236 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004237
Douglas Gregora009b592011-01-07 00:20:55 +00004238 OutParamTypes.push_back(NewParm->getType());
4239 if (PVars)
4240 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004241 continue;
4242 }
John McCall21ef0fa2010-03-11 09:03:00 +00004243
4244 // Deal with the possibility that we don't have a parameter
4245 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004246 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004247 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004248 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004249 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004250 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004251 = dyn_cast<PackExpansionType>(OldType)) {
4252 // We have a function parameter pack that may need to be expanded.
4253 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004254 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004255 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004256
Douglas Gregor603cfb42011-01-05 23:12:31 +00004257 // Determine whether we should expand the parameter packs.
4258 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004259 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004260 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004261 Unexpanded,
4262 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004263 RetainExpansion,
4264 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004265 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004267
Douglas Gregor603cfb42011-01-05 23:12:31 +00004268 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004269 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004270 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004271 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004272 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4273 QualType NewType = getDerived().TransformType(Pattern);
4274 if (NewType.isNull())
4275 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004276
Douglas Gregora009b592011-01-07 00:20:55 +00004277 OutParamTypes.push_back(NewType);
4278 if (PVars)
4279 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004280 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004281
Douglas Gregor603cfb42011-01-05 23:12:31 +00004282 // We're done with the pack expansion.
4283 continue;
4284 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004286 // If we're supposed to retain a pack expansion, do so by temporarily
4287 // forgetting the partially-substituted parameter pack.
4288 if (RetainExpansion) {
4289 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4290 QualType NewType = getDerived().TransformType(Pattern);
4291 if (NewType.isNull())
4292 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004293
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004294 OutParamTypes.push_back(NewType);
4295 if (PVars)
4296 PVars->push_back(0);
4297 }
Douglas Gregord3731192011-01-10 07:32:04 +00004298
Chad Rosier4a9d7952012-08-08 18:46:20 +00004299 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004300 // expansion.
4301 OldType = Expansion->getPattern();
4302 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004303 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4304 NewType = getDerived().TransformType(OldType);
4305 } else {
4306 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004307 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004308
Douglas Gregor603cfb42011-01-05 23:12:31 +00004309 if (NewType.isNull())
4310 return true;
4311
4312 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004313 NewType = getSema().Context.getPackExpansionType(NewType,
4314 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004315
Douglas Gregora009b592011-01-07 00:20:55 +00004316 OutParamTypes.push_back(NewType);
4317 if (PVars)
4318 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004319 }
4320
John McCallfb44de92011-05-01 22:35:37 +00004321#ifndef NDEBUG
4322 if (PVars) {
4323 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4324 if (ParmVarDecl *parm = (*PVars)[i])
4325 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004326 }
John McCallfb44de92011-05-01 22:35:37 +00004327#endif
4328
4329 return false;
4330}
John McCall21ef0fa2010-03-11 09:03:00 +00004331
4332template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004333QualType
John McCalla2becad2009-10-21 00:40:46 +00004334TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004335 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004336 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4337}
4338
4339template<typename Derived>
4340QualType
4341TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4342 FunctionProtoTypeLoc TL,
4343 CXXRecordDecl *ThisContext,
4344 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004345 // Transform the parameters and return type.
4346 //
Richard Smithe6975e92012-04-17 00:58:00 +00004347 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004348 // When the function has a trailing return type, we instantiate the
4349 // parameters before the return type, since the return type can then refer
4350 // to the parameters themselves (via decltype, sizeof, etc.).
4351 //
Chris Lattner686775d2011-07-20 06:58:45 +00004352 SmallVector<QualType, 4> ParamTypes;
4353 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004354 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004355
Douglas Gregordab60ad2010-10-01 18:44:50 +00004356 QualType ResultType;
4357
Richard Smith9fbf3272012-08-14 22:51:13 +00004358 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004359 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004360 TL.getParmArray(),
4361 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004362 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004363 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004364 return QualType();
4365
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004366 {
4367 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004368 // If a declaration declares a member function or member function
4369 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004370 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004371 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004372 // declarator.
4373 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004374
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004375 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4376 if (ResultType.isNull())
4377 return QualType();
4378 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004379 }
4380 else {
4381 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4382 if (ResultType.isNull())
4383 return QualType();
4384
Chad Rosier4a9d7952012-08-08 18:46:20 +00004385 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004386 TL.getParmArray(),
4387 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004388 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004389 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004390 return QualType();
4391 }
4392
Richard Smithe6975e92012-04-17 00:58:00 +00004393 // FIXME: Need to transform the exception-specification too.
4394
John McCalla2becad2009-10-21 00:40:46 +00004395 QualType Result = TL.getType();
4396 if (getDerived().AlwaysRebuild() ||
4397 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004398 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004399 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004400 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004401 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004402 if (Result.isNull())
4403 return QualType();
4404 }
Mike Stump1eb44332009-09-09 15:08:12 +00004405
John McCalla2becad2009-10-21 00:40:46 +00004406 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004407 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004408 NewTL.setLParenLoc(TL.getLParenLoc());
4409 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004410 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004411 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4412 NewTL.setArg(i, ParamDecls[i]);
4413
4414 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415}
Mike Stump1eb44332009-09-09 15:08:12 +00004416
Douglas Gregor577f75a2009-08-04 16:50:30 +00004417template<typename Derived>
4418QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004419 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004420 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004421 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004422 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4423 if (ResultType.isNull())
4424 return QualType();
4425
4426 QualType Result = TL.getType();
4427 if (getDerived().AlwaysRebuild() ||
4428 ResultType != T->getResultType())
4429 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4430
4431 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004432 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004433 NewTL.setLParenLoc(TL.getLParenLoc());
4434 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004435 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004436
4437 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004438}
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalled976492009-12-04 22:46:56 +00004440template<typename Derived> QualType
4441TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004442 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004443 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004444 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004445 if (!D)
4446 return QualType();
4447
4448 QualType Result = TL.getType();
4449 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4450 Result = getDerived().RebuildUnresolvedUsingType(D);
4451 if (Result.isNull())
4452 return QualType();
4453 }
4454
4455 // We might get an arbitrary type spec type back. We should at
4456 // least always get a type spec type, though.
4457 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4458 NewTL.setNameLoc(TL.getNameLoc());
4459
4460 return Result;
4461}
4462
Douglas Gregor577f75a2009-08-04 16:50:30 +00004463template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004464QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004465 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004466 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004467 TypedefNameDecl *Typedef
4468 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4469 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004470 if (!Typedef)
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 Typedef != T->getDecl()) {
4476 Result = getDerived().RebuildTypedefType(Typedef);
4477 if (Result.isNull())
4478 return QualType();
4479 }
Mike Stump1eb44332009-09-09 15:08:12 +00004480
John McCalla2becad2009-10-21 00:40:46 +00004481 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(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
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004489 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004490 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004491 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4492 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004493
John McCall60d7b3a2010-08-24 06:29:42 +00004494 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004495 if (E.isInvalid())
4496 return QualType();
4497
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004498 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4499 if (E.isInvalid())
4500 return QualType();
4501
John McCalla2becad2009-10-21 00:40:46 +00004502 QualType Result = TL.getType();
4503 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004504 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004505 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004506 if (Result.isNull())
4507 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004508 }
John McCalla2becad2009-10-21 00:40:46 +00004509 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004510
John McCalla2becad2009-10-21 00:40:46 +00004511 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004512 NewTL.setTypeofLoc(TL.getTypeofLoc());
4513 NewTL.setLParenLoc(TL.getLParenLoc());
4514 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004515
4516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517}
Mike Stump1eb44332009-09-09 15:08:12 +00004518
4519template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004520QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004521 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004522 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4523 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4524 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004525 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004526
John McCalla2becad2009-10-21 00:40:46 +00004527 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004528 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4529 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
4532 }
Mike Stump1eb44332009-09-09 15:08:12 +00004533
John McCalla2becad2009-10-21 00:40:46 +00004534 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004535 NewTL.setTypeofLoc(TL.getTypeofLoc());
4536 NewTL.setLParenLoc(TL.getLParenLoc());
4537 NewTL.setRParenLoc(TL.getRParenLoc());
4538 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004546 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004547
Douglas Gregor670444e2009-08-04 22:27:00 +00004548 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004549 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4550 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004551
John McCall60d7b3a2010-08-24 06:29:42 +00004552 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004553 if (E.isInvalid())
4554 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Richard Smith76f3f692012-02-22 02:04:18 +00004556 E = getSema().ActOnDecltypeExpression(E.take());
4557 if (E.isInvalid())
4558 return QualType();
4559
John McCalla2becad2009-10-21 00:40:46 +00004560 QualType Result = TL.getType();
4561 if (getDerived().AlwaysRebuild() ||
4562 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004563 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004566 }
John McCalla2becad2009-10-21 00:40:46 +00004567 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCalla2becad2009-10-21 00:40:46 +00004569 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4570 NewTL.setNameLoc(TL.getNameLoc());
4571
4572 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004573}
4574
4575template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004576QualType TreeTransform<Derived>::TransformUnaryTransformType(
4577 TypeLocBuilder &TLB,
4578 UnaryTransformTypeLoc TL) {
4579 QualType Result = TL.getType();
4580 if (Result->isDependentType()) {
4581 const UnaryTransformType *T = TL.getTypePtr();
4582 QualType NewBase =
4583 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4584 Result = getDerived().RebuildUnaryTransformType(NewBase,
4585 T->getUTTKind(),
4586 TL.getKWLoc());
4587 if (Result.isNull())
4588 return QualType();
4589 }
4590
4591 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4592 NewTL.setKWLoc(TL.getKWLoc());
4593 NewTL.setParensRange(TL.getParensRange());
4594 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4595 return Result;
4596}
4597
4598template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004599QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4600 AutoTypeLoc TL) {
4601 const AutoType *T = TL.getTypePtr();
4602 QualType OldDeduced = T->getDeducedType();
4603 QualType NewDeduced;
4604 if (!OldDeduced.isNull()) {
4605 NewDeduced = getDerived().TransformType(OldDeduced);
4606 if (NewDeduced.isNull())
4607 return QualType();
4608 }
4609
4610 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004611 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4612 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004613 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004614 if (Result.isNull())
4615 return QualType();
4616 }
4617
4618 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4619 NewTL.setNameLoc(TL.getNameLoc());
4620
4621 return Result;
4622}
4623
4624template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004625QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004626 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004627 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004628 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004629 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4630 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004631 if (!Record)
4632 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004633
John McCalla2becad2009-10-21 00:40:46 +00004634 QualType Result = TL.getType();
4635 if (getDerived().AlwaysRebuild() ||
4636 Record != T->getDecl()) {
4637 Result = getDerived().RebuildRecordType(Record);
4638 if (Result.isNull())
4639 return QualType();
4640 }
Mike Stump1eb44332009-09-09 15:08:12 +00004641
John McCalla2becad2009-10-21 00:40:46 +00004642 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004646}
Mike Stump1eb44332009-09-09 15:08:12 +00004647
4648template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004650 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004651 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004652 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004653 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004655 if (!Enum)
4656 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004657
John McCalla2becad2009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Enum != T->getDecl()) {
4661 Result = getDerived().RebuildEnumType(Enum);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump1eb44332009-09-09 15:08:12 +00004665
John McCalla2becad2009-10-21 00:40:46 +00004666 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004670}
John McCall7da24312009-09-05 00:15:47 +00004671
John McCall3cb0ebd2010-03-10 03:28:59 +00004672template<typename Derived>
4673QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4674 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004675 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004676 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4677 TL.getTypePtr()->getDecl());
4678 if (!D) return QualType();
4679
4680 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4681 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4682 return T;
4683}
4684
Douglas Gregor577f75a2009-08-04 16:50:30 +00004685template<typename Derived>
4686QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004687 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004688 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004689 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004690}
4691
Mike Stump1eb44332009-09-09 15:08:12 +00004692template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004693QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004694 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004695 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004696 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004698 // Substitute into the replacement type, which itself might involve something
4699 // that needs to be transformed. This only tends to occur with default
4700 // template arguments of template template parameters.
4701 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4702 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4703 if (Replacement.isNull())
4704 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004705
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004706 // Always canonicalize the replacement type.
4707 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4708 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004709 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004710 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004711
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004712 // Propagate type-source information.
4713 SubstTemplateTypeParmTypeLoc NewTL
4714 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4715 NewTL.setNameLoc(TL.getNameLoc());
4716 return Result;
4717
John McCall49a832b2009-10-18 09:09:24 +00004718}
4719
4720template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004721QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4722 TypeLocBuilder &TLB,
4723 SubstTemplateTypeParmPackTypeLoc TL) {
4724 return TransformTypeSpecType(TLB, TL);
4725}
4726
4727template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004728QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004729 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004730 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004731 const TemplateSpecializationType *T = TL.getTypePtr();
4732
Douglas Gregor1d752d72011-03-02 18:46:51 +00004733 // The nested-name-specifier never matters in a TemplateSpecializationType,
4734 // because we can't have a dependent nested-name-specifier anyway.
4735 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004736 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004737 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4738 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004739 if (Template.isNull())
4740 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004741
John McCall43fed0d2010-11-12 08:19:04 +00004742 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4743}
4744
Eli Friedmanb001de72011-10-06 23:00:33 +00004745template<typename Derived>
4746QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4747 AtomicTypeLoc TL) {
4748 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4749 if (ValueType.isNull())
4750 return QualType();
4751
4752 QualType Result = TL.getType();
4753 if (getDerived().AlwaysRebuild() ||
4754 ValueType != TL.getValueLoc().getType()) {
4755 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4756 if (Result.isNull())
4757 return QualType();
4758 }
4759
4760 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4761 NewTL.setKWLoc(TL.getKWLoc());
4762 NewTL.setLParenLoc(TL.getLParenLoc());
4763 NewTL.setRParenLoc(TL.getRParenLoc());
4764
4765 return Result;
4766}
4767
Chad Rosier4a9d7952012-08-08 18:46:20 +00004768 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004769 /// container that provides a \c getArgLoc() member function.
4770 ///
4771 /// This iterator is intended to be used with the iterator form of
4772 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4773 template<typename ArgLocContainer>
4774 class TemplateArgumentLocContainerIterator {
4775 ArgLocContainer *Container;
4776 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004777
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004778 public:
4779 typedef TemplateArgumentLoc value_type;
4780 typedef TemplateArgumentLoc reference;
4781 typedef int difference_type;
4782 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004783
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004784 class pointer {
4785 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004786
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004787 public:
4788 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004789
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004790 const TemplateArgumentLoc *operator->() const {
4791 return &Arg;
4792 }
4793 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004794
4795
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004796 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004797
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004798 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4799 unsigned Index)
4800 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 TemplateArgumentLocContainerIterator &operator++() {
4803 ++Index;
4804 return *this;
4805 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004807 TemplateArgumentLocContainerIterator operator++(int) {
4808 TemplateArgumentLocContainerIterator Old(*this);
4809 ++(*this);
4810 return Old;
4811 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004812
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004813 TemplateArgumentLoc operator*() const {
4814 return Container->getArgLoc(Index);
4815 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004817 pointer operator->() const {
4818 return pointer(Container->getArgLoc(Index));
4819 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004820
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004821 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004822 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004823 return X.Container == Y.Container && X.Index == Y.Index;
4824 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004826 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004827 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004828 return !(X == Y);
4829 }
4830 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004831
4832
John McCall43fed0d2010-11-12 08:19:04 +00004833template <typename Derived>
4834QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4835 TypeLocBuilder &TLB,
4836 TemplateSpecializationTypeLoc TL,
4837 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004838 TemplateArgumentListInfo NewTemplateArgs;
4839 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4840 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004841 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4842 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004843 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004844 ArgIterator(TL, TL.getNumArgs()),
4845 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004846 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004847
John McCall833ca992009-10-29 08:12:44 +00004848 // FIXME: maybe don't rebuild if all the template arguments are the same.
4849
4850 QualType Result =
4851 getDerived().RebuildTemplateSpecializationType(Template,
4852 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004853 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004854
4855 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004856 // Specializations of template template parameters are represented as
4857 // TemplateSpecializationTypes, and substitution of type alias templates
4858 // within a dependent context can transform them into
4859 // DependentTemplateSpecializationTypes.
4860 if (isa<DependentTemplateSpecializationType>(Result)) {
4861 DependentTemplateSpecializationTypeLoc NewTL
4862 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004863 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004864 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004865 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004866 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004867 NewTL.setLAngleLoc(TL.getLAngleLoc());
4868 NewTL.setRAngleLoc(TL.getRAngleLoc());
4869 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4870 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4871 return Result;
4872 }
4873
John McCall833ca992009-10-29 08:12:44 +00004874 TemplateSpecializationTypeLoc NewTL
4875 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004876 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004877 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4878 NewTL.setLAngleLoc(TL.getLAngleLoc());
4879 NewTL.setRAngleLoc(TL.getRAngleLoc());
4880 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4881 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004882 }
Mike Stump1eb44332009-09-09 15:08:12 +00004883
John McCall833ca992009-10-29 08:12:44 +00004884 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004885}
Mike Stump1eb44332009-09-09 15:08:12 +00004886
Douglas Gregora88f09f2011-02-28 17:23:35 +00004887template <typename Derived>
4888QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4889 TypeLocBuilder &TLB,
4890 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004891 TemplateName Template,
4892 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004893 TemplateArgumentListInfo NewTemplateArgs;
4894 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4895 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4896 typedef TemplateArgumentLocContainerIterator<
4897 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004898 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004899 ArgIterator(TL, TL.getNumArgs()),
4900 NewTemplateArgs))
4901 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004902
Douglas Gregora88f09f2011-02-28 17:23:35 +00004903 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004904
Douglas Gregora88f09f2011-02-28 17:23:35 +00004905 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4906 QualType Result
4907 = getSema().Context.getDependentTemplateSpecializationType(
4908 TL.getTypePtr()->getKeyword(),
4909 DTN->getQualifier(),
4910 DTN->getIdentifier(),
4911 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004912
Douglas Gregora88f09f2011-02-28 17:23:35 +00004913 DependentTemplateSpecializationTypeLoc NewTL
4914 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004915 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004916 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004917 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004918 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004919 NewTL.setLAngleLoc(TL.getLAngleLoc());
4920 NewTL.setRAngleLoc(TL.getRAngleLoc());
4921 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4922 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4923 return Result;
4924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004925
4926 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004927 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004928 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004929 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004930
Douglas Gregora88f09f2011-02-28 17:23:35 +00004931 if (!Result.isNull()) {
4932 /// FIXME: Wrap this in an elaborated-type-specifier?
4933 TemplateSpecializationTypeLoc NewTL
4934 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004935 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004936 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004937 NewTL.setLAngleLoc(TL.getLAngleLoc());
4938 NewTL.setRAngleLoc(TL.getRAngleLoc());
4939 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4940 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4941 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004942
Douglas Gregora88f09f2011-02-28 17:23:35 +00004943 return Result;
4944}
4945
Mike Stump1eb44332009-09-09 15:08:12 +00004946template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004947QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004948TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004949 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004950 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004951
Douglas Gregor9e876872011-03-01 18:12:44 +00004952 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004953 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004954 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004955 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004956 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4957 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004958 return QualType();
4959 }
Mike Stump1eb44332009-09-09 15:08:12 +00004960
John McCall43fed0d2010-11-12 08:19:04 +00004961 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4962 if (NamedT.isNull())
4963 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004964
Richard Smith3e4c6c42011-05-05 21:57:07 +00004965 // C++0x [dcl.type.elab]p2:
4966 // If the identifier resolves to a typedef-name or the simple-template-id
4967 // resolves to an alias template specialization, the
4968 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004969 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4970 if (const TemplateSpecializationType *TST =
4971 NamedT->getAs<TemplateSpecializationType>()) {
4972 TemplateName Template = TST->getTemplateName();
4973 if (TypeAliasTemplateDecl *TAT =
4974 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4975 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4976 diag::err_tag_reference_non_tag) << 4;
4977 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4978 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004979 }
4980 }
4981
John McCalla2becad2009-10-21 00:40:46 +00004982 QualType Result = TL.getType();
4983 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004984 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004985 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004986 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004987 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004988 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004989 if (Result.isNull())
4990 return QualType();
4991 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004992
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004993 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004994 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004995 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004996 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004997}
Mike Stump1eb44332009-09-09 15:08:12 +00004998
4999template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005000QualType TreeTransform<Derived>::TransformAttributedType(
5001 TypeLocBuilder &TLB,
5002 AttributedTypeLoc TL) {
5003 const AttributedType *oldType = TL.getTypePtr();
5004 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5005 if (modifiedType.isNull())
5006 return QualType();
5007
5008 QualType result = TL.getType();
5009
5010 // FIXME: dependent operand expressions?
5011 if (getDerived().AlwaysRebuild() ||
5012 modifiedType != oldType->getModifiedType()) {
5013 // TODO: this is really lame; we should really be rebuilding the
5014 // equivalent type from first principles.
5015 QualType equivalentType
5016 = getDerived().TransformType(oldType->getEquivalentType());
5017 if (equivalentType.isNull())
5018 return QualType();
5019 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5020 modifiedType,
5021 equivalentType);
5022 }
5023
5024 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5025 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5026 if (TL.hasAttrOperand())
5027 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5028 if (TL.hasAttrExprOperand())
5029 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5030 else if (TL.hasAttrEnumOperand())
5031 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5032
5033 return result;
5034}
5035
5036template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005037QualType
5038TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5039 ParenTypeLoc TL) {
5040 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5041 if (Inner.isNull())
5042 return QualType();
5043
5044 QualType Result = TL.getType();
5045 if (getDerived().AlwaysRebuild() ||
5046 Inner != TL.getInnerLoc().getType()) {
5047 Result = getDerived().RebuildParenType(Inner);
5048 if (Result.isNull())
5049 return QualType();
5050 }
5051
5052 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5053 NewTL.setLParenLoc(TL.getLParenLoc());
5054 NewTL.setRParenLoc(TL.getRParenLoc());
5055 return Result;
5056}
5057
5058template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005059QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005060 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005061 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005062
Douglas Gregor2494dd02011-03-01 01:34:45 +00005063 NestedNameSpecifierLoc QualifierLoc
5064 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5065 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005066 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005067
John McCall33500952010-06-11 00:33:02 +00005068 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005069 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005070 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005071 QualifierLoc,
5072 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005073 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005074 if (Result.isNull())
5075 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005076
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005077 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5078 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005079 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5080
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005081 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005082 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005083 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005084 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005085 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005086 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005087 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005088 NewTL.setNameLoc(TL.getNameLoc());
5089 }
John McCalla2becad2009-10-21 00:40:46 +00005090 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005091}
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregor577f75a2009-08-04 16:50:30 +00005093template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005094QualType TreeTransform<Derived>::
5095 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005096 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005097 NestedNameSpecifierLoc QualifierLoc;
5098 if (TL.getQualifierLoc()) {
5099 QualifierLoc
5100 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5101 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005102 return QualType();
5103 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005104
John McCall43fed0d2010-11-12 08:19:04 +00005105 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005106 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005107}
5108
5109template<typename Derived>
5110QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005111TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5112 DependentTemplateSpecializationTypeLoc TL,
5113 NestedNameSpecifierLoc QualifierLoc) {
5114 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005115
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005116 TemplateArgumentListInfo NewTemplateArgs;
5117 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5118 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005119
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005120 typedef TemplateArgumentLocContainerIterator<
5121 DependentTemplateSpecializationTypeLoc> ArgIterator;
5122 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5123 ArgIterator(TL, TL.getNumArgs()),
5124 NewTemplateArgs))
5125 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005126
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005127 QualType Result
5128 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5129 QualifierLoc,
5130 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005131 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005132 NewTemplateArgs);
5133 if (Result.isNull())
5134 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005135
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005136 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5137 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005138
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005139 // Copy information relevant to the template specialization.
5140 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005141 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005142 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005143 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5145 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005146 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005147 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005148
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005149 // Copy information relevant to the elaborated type.
5150 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005151 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005152 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005153 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5154 DependentTemplateSpecializationTypeLoc SpecTL
5155 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005156 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005157 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005158 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005159 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005160 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5161 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005162 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005163 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005164 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005165 TemplateSpecializationTypeLoc SpecTL
5166 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005167 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005168 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005169 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5170 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005171 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005172 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005173 }
5174 return Result;
5175}
5176
5177template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005178QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5179 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005180 QualType Pattern
5181 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005182 if (Pattern.isNull())
5183 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005184
5185 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005186 if (getDerived().AlwaysRebuild() ||
5187 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005188 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005189 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005190 TL.getEllipsisLoc(),
5191 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005192 if (Result.isNull())
5193 return QualType();
5194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005195
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005196 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5197 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5198 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005199}
5200
5201template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005202QualType
5203TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005204 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005205 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005206 TLB.pushFullCopy(TL);
5207 return TL.getType();
5208}
5209
5210template<typename Derived>
5211QualType
5212TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005213 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005214 // ObjCObjectType is never dependent.
5215 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005216 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005217}
Mike Stump1eb44332009-09-09 15:08:12 +00005218
5219template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005220QualType
5221TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005222 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005223 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005224 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005225 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005226}
5227
Douglas Gregor577f75a2009-08-04 16:50:30 +00005228//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005229// Statement transformation
5230//===----------------------------------------------------------------------===//
5231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005233TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005234 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005235}
5236
5237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005238StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005239TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5240 return getDerived().TransformCompoundStmt(S, false);
5241}
5242
5243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005244StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005247 Sema::CompoundScopeRAII CompoundScope(getSema());
5248
John McCall7114cba2010-08-27 19:56:05 +00005249 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005251 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5253 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005254 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005255 if (Result.isInvalid()) {
5256 // Immediately fail if this was a DeclStmt, since it's very
5257 // likely that this will cause problems for future statements.
5258 if (isa<DeclStmt>(*B))
5259 return StmtError();
5260
5261 // Otherwise, just keep processing substatements and fail later.
5262 SubStmtInvalid = true;
5263 continue;
5264 }
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5267 Statements.push_back(Result.takeAs<Stmt>());
5268 }
Mike Stump1eb44332009-09-09 15:08:12 +00005269
John McCall7114cba2010-08-27 19:56:05 +00005270 if (SubStmtInvalid)
5271 return StmtError();
5272
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 if (!getDerived().AlwaysRebuild() &&
5274 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005276
5277 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005278 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 S->getRBracLoc(),
5280 IsStmtExpr);
5281}
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005286 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005287 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005288 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5289 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Eli Friedman264c1f82009-11-19 03:14:00 +00005291 // Transform the left-hand case value.
5292 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005293 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005294 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005296
Eli Friedman264c1f82009-11-19 03:14:00 +00005297 // Transform the right-hand case value (for the GNU case-range extension).
5298 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005299 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005300 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005302 }
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 // Build the case statement.
5305 // Case statements are always rebuilt so that they will attached to their
5306 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005308 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005310 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 S->getColonLoc());
5312 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005316 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005317 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005318 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005321 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005322}
5323
5324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005325StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005326TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005328 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 // Default statements are always rebuilt
5333 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005334 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005335}
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005338StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005339TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Chris Lattner57ad3782011-02-17 20:34:02 +00005344 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5345 S->getDecl());
5346 if (!LD)
5347 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005348
5349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005351 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005352 cast<LabelDecl>(LD), SourceLocation(),
5353 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354}
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005357StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005358TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5359 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5360 if (SubStmt.isInvalid())
5361 return StmtError();
5362
5363 // TODO: transform attributes
5364 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5365 return S;
5366
5367 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5368 S->getAttrs(),
5369 SubStmt.get());
5370}
5371
5372template<typename Derived>
5373StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005374TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005376 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005377 VarDecl *ConditionVar = 0;
5378 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005379 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005380 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005381 getDerived().TransformDefinition(
5382 S->getConditionVariable()->getLocation(),
5383 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005384 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005385 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005386 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005387 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005388
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005389 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005391
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005392 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005393 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005394 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005395 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005396 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005398
John McCall9ae2f072010-08-23 23:25:46 +00005399 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005400 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005402
John McCall9ae2f072010-08-23 23:25:46 +00005403 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5404 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005405 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005406
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005408 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005411
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005413 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005416
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005418 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 Then.get() == S->getThen() &&
5421 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005422 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005424 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005425 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005426 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005427}
5428
5429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005430StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005431TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005433 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005434 VarDecl *ConditionVar = 0;
5435 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005436 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005437 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005438 getDerived().TransformDefinition(
5439 S->getConditionVariable()->getLocation(),
5440 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005441 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005444 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005445
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005446 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005448 }
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005451 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005452 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005453 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005458 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005463 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5464 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005471 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005472 VarDecl *ConditionVar = 0;
5473 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005474 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005475 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005476 getDerived().TransformDefinition(
5477 S->getConditionVariable()->getLocation(),
5478 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005479 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005481 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005482 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005483
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005484 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005485 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005486
5487 if (S->getCond()) {
5488 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005489 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005490 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005491 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005493 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005494 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005495 }
Mike Stump1eb44332009-09-09 15:08:12 +00005496
John McCall9ae2f072010-08-23 23:25:46 +00005497 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5498 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005499 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005500
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005502 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005507 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005508 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005510 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005512 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005513 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005518TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005520 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005524 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005525 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005526 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005528
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 if (!getDerived().AlwaysRebuild() &&
5530 Cond.get() == S->getCond() &&
5531 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005533
John McCall9ae2f072010-08-23 23:25:46 +00005534 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5535 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 S->getRParenLoc());
5537}
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregor43959a92009-08-20 07:17:43 +00005539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005540StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005541TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005542 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005543 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005544 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005545 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregor43959a92009-08-20 07:17:43 +00005547 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005548 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005549 VarDecl *ConditionVar = 0;
5550 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005551 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005552 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005553 getDerived().TransformDefinition(
5554 S->getConditionVariable()->getLocation(),
5555 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005556 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005557 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005558 } else {
5559 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005560
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005561 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005562 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005563
5564 if (S->getCond()) {
5565 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005567 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005568 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005570
John McCall9ae2f072010-08-23 23:25:46 +00005571 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005572 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005573 }
Mike Stump1eb44332009-09-09 15:08:12 +00005574
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005576 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005577 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005578
Douglas Gregor43959a92009-08-20 07:17:43 +00005579 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005580 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005581 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005582 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005583
Richard Smith41956372013-01-14 22:39:08 +00005584 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005585 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005587
Douglas Gregor43959a92009-08-20 07:17:43 +00005588 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005589 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005590 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005591 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005592
Douglas Gregor43959a92009-08-20 07:17:43 +00005593 if (!getDerived().AlwaysRebuild() &&
5594 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005595 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005596 Inc.get() == S->getInc() &&
5597 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005598 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005599
Douglas Gregor43959a92009-08-20 07:17:43 +00005600 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005601 Init.get(), FullCond, ConditionVar,
5602 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005603}
5604
5605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005606StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005607TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005608 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5609 S->getLabel());
5610 if (!LD)
5611 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005612
Douglas Gregor43959a92009-08-20 07:17:43 +00005613 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005614 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005615 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005616}
5617
5618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005619StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005620TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005621 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005622 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005623 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005624 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005625
Douglas Gregor43959a92009-08-20 07:17:43 +00005626 if (!getDerived().AlwaysRebuild() &&
5627 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005629
5630 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005631 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005632}
5633
5634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005635StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005636TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005637 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005638}
Mike Stump1eb44332009-09-09 15:08:12 +00005639
Douglas Gregor43959a92009-08-20 07:17:43 +00005640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005642TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005643 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005644}
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregor43959a92009-08-20 07:17:43 +00005646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005647StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005648TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005649 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005650 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005651 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005652
Mike Stump1eb44332009-09-09 15:08:12 +00005653 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005654 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005655 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005656}
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregor43959a92009-08-20 07:17:43 +00005658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005661 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005662 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005663 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5664 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005665 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5666 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005667 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005668 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005669
Douglas Gregor43959a92009-08-20 07:17:43 +00005670 if (Transformed != *D)
5671 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor43959a92009-08-20 07:17:43 +00005673 Decls.push_back(Transformed);
5674 }
Mike Stump1eb44332009-09-09 15:08:12 +00005675
Douglas Gregor43959a92009-08-20 07:17:43 +00005676 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005677 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005679 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005680}
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregor43959a92009-08-20 07:17:43 +00005682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005683StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005684TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005685
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005686 SmallVector<Expr*, 8> Constraints;
5687 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005688 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005689
John McCall60d7b3a2010-08-24 06:29:42 +00005690 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005691 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005692
5693 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
Anders Carlsson703e3942010-01-24 05:50:09 +00005695 // Go through the outputs.
5696 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005697 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005698
Anders Carlsson703e3942010-01-24 05:50:09 +00005699 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005700 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005701
Anders Carlsson703e3942010-01-24 05:50:09 +00005702 // Transform the output expr.
5703 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005704 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005705 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005706 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005707
Anders Carlsson703e3942010-01-24 05:50:09 +00005708 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005709
John McCall9ae2f072010-08-23 23:25:46 +00005710 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005712
Anders Carlsson703e3942010-01-24 05:50:09 +00005713 // Go through the inputs.
5714 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005715 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
Anders Carlsson703e3942010-01-24 05:50:09 +00005717 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005718 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
Anders Carlsson703e3942010-01-24 05:50:09 +00005720 // Transform the input expr.
5721 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005722 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005723 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005724 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Anders Carlsson703e3942010-01-24 05:50:09 +00005726 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005727
John McCall9ae2f072010-08-23 23:25:46 +00005728 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005729 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005730
Anders Carlsson703e3942010-01-24 05:50:09 +00005731 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005732 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005733
5734 // Go through the clobbers.
5735 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005736 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005737
5738 // No need to transform the asm string literal.
5739 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005740 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5741 S->isVolatile(), S->getNumOutputs(),
5742 S->getNumInputs(), Names.data(),
5743 Constraints, Exprs, AsmString.get(),
5744 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005745}
5746
Chad Rosier8cd64b42012-06-11 20:47:18 +00005747template<typename Derived>
5748StmtResult
5749TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005750 ArrayRef<Token> AsmToks =
5751 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005752
John McCallaeeacf72013-05-03 00:10:13 +00005753 bool HadError = false, HadChange = false;
5754
5755 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5756 SmallVector<Expr*, 8> TransformedExprs;
5757 TransformedExprs.reserve(SrcExprs.size());
5758 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5759 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5760 if (!Result.isUsable()) {
5761 HadError = true;
5762 } else {
5763 HadChange |= (Result.get() != SrcExprs[i]);
5764 TransformedExprs.push_back(Result.take());
5765 }
5766 }
5767
5768 if (HadError) return StmtError();
5769 if (!HadChange && !getDerived().AlwaysRebuild())
5770 return Owned(S);
5771
Chad Rosier7bd092b2012-08-15 16:53:30 +00005772 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005773 AsmToks, S->getAsmString(),
5774 S->getNumOutputs(), S->getNumInputs(),
5775 S->getAllConstraints(), S->getClobbers(),
5776 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005777}
Douglas Gregor43959a92009-08-20 07:17:43 +00005778
5779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005780StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005781TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005782 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005783 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005784 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005785 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005786
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005787 // Transform the @catch statements (if present).
5788 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005789 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005790 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005791 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005792 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005793 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005794 if (Catch.get() != S->getCatchStmt(I))
5795 AnyCatchChanged = true;
5796 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005797 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005798
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005799 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005800 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005801 if (S->getFinallyStmt()) {
5802 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5803 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005805 }
5806
5807 // If nothing changed, just retain this statement.
5808 if (!getDerived().AlwaysRebuild() &&
5809 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005810 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005811 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005812 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005813
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005814 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005815 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005816 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005817}
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregor43959a92009-08-20 07:17:43 +00005819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005820StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005821TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005822 // Transform the @catch parameter, if there is one.
5823 VarDecl *Var = 0;
5824 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5825 TypeSourceInfo *TSInfo = 0;
5826 if (FromVar->getTypeSourceInfo()) {
5827 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5828 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005831
Douglas Gregorbe270a02010-04-26 17:57:08 +00005832 QualType T;
5833 if (TSInfo)
5834 T = TSInfo->getType();
5835 else {
5836 T = getDerived().TransformType(FromVar->getType());
5837 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005838 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005840
Douglas Gregorbe270a02010-04-26 17:57:08 +00005841 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5842 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005843 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005845
John McCall60d7b3a2010-08-24 06:29:42 +00005846 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005847 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005848 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005849
5850 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005851 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005852 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005853}
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregor43959a92009-08-20 07:17:43 +00005855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005856StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005857TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005858 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005859 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005860 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005862
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005863 // If nothing changed, just retain this statement.
5864 if (!getDerived().AlwaysRebuild() &&
5865 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005866 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005867
5868 // Build a new statement.
5869 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005870 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005871}
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Douglas Gregor43959a92009-08-20 07:17:43 +00005873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005874StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005875TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005876 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005877 if (S->getThrowExpr()) {
5878 Operand = getDerived().TransformExpr(S->getThrowExpr());
5879 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005880 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005881 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005882
Douglas Gregord1377b22010-04-22 21:44:01 +00005883 if (!getDerived().AlwaysRebuild() &&
5884 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005885 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005886
John McCall9ae2f072010-08-23 23:25:46 +00005887 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005888}
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Douglas Gregor43959a92009-08-20 07:17:43 +00005890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005891StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005892TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005893 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005894 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005895 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005896 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005897 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005898 Object =
5899 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5900 Object.get());
5901 if (Object.isInvalid())
5902 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005903
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005904 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005905 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005906 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005907 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005908
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005909 // If nothing change, just retain the current statement.
5910 if (!getDerived().AlwaysRebuild() &&
5911 Object.get() == S->getSynchExpr() &&
5912 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005913 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005914
5915 // Build a new statement.
5916 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005917 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005918}
5919
5920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005921StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005922TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5923 ObjCAutoreleasePoolStmt *S) {
5924 // Transform the body.
5925 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5926 if (Body.isInvalid())
5927 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005928
John McCallf85e1932011-06-15 23:02:42 +00005929 // If nothing changed, just retain this statement.
5930 if (!getDerived().AlwaysRebuild() &&
5931 Body.get() == S->getSubStmt())
5932 return SemaRef.Owned(S);
5933
5934 // Build a new statement.
5935 return getDerived().RebuildObjCAutoreleasePoolStmt(
5936 S->getAtLoc(), Body.get());
5937}
5938
5939template<typename Derived>
5940StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005941TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005942 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005943 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005944 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005945 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005946 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005947
Douglas Gregorc3203e72010-04-22 23:10:45 +00005948 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005949 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005950 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005951 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005952
Douglas Gregorc3203e72010-04-22 23:10:45 +00005953 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005954 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005955 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005956 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005957
Douglas Gregorc3203e72010-04-22 23:10:45 +00005958 // If nothing changed, just retain this statement.
5959 if (!getDerived().AlwaysRebuild() &&
5960 Element.get() == S->getElement() &&
5961 Collection.get() == S->getCollection() &&
5962 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005963 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005964
Douglas Gregorc3203e72010-04-22 23:10:45 +00005965 // Build a new statement.
5966 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005967 Element.get(),
5968 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005969 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005970 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005971}
5972
5973
5974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005975StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005976TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5977 // Transform the exception declaration, if any.
5978 VarDecl *Var = 0;
5979 if (S->getExceptionDecl()) {
5980 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005981 TypeSourceInfo *T = getDerived().TransformType(
5982 ExceptionDecl->getTypeSourceInfo());
5983 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005984 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005985
Douglas Gregor83cb9422010-09-09 17:09:21 +00005986 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005987 ExceptionDecl->getInnerLocStart(),
5988 ExceptionDecl->getLocation(),
5989 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005990 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005991 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005992 }
Mike Stump1eb44332009-09-09 15:08:12 +00005993
Douglas Gregor43959a92009-08-20 07:17:43 +00005994 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005995 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005996 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005997 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005998
Douglas Gregor43959a92009-08-20 07:17:43 +00005999 if (!getDerived().AlwaysRebuild() &&
6000 !Var &&
6001 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006002 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006003
6004 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6005 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006006 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006007}
Mike Stump1eb44332009-09-09 15:08:12 +00006008
Douglas Gregor43959a92009-08-20 07:17:43 +00006009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006010StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006011TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6012 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006013 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006014 = getDerived().TransformCompoundStmt(S->getTryBlock());
6015 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006016 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006017
Douglas Gregor43959a92009-08-20 07:17:43 +00006018 // Transform the handlers.
6019 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006020 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006021 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006022 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006023 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6024 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006025 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006026
Douglas Gregor43959a92009-08-20 07:17:43 +00006027 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6028 Handlers.push_back(Handler.takeAs<Stmt>());
6029 }
Mike Stump1eb44332009-09-09 15:08:12 +00006030
Douglas Gregor43959a92009-08-20 07:17:43 +00006031 if (!getDerived().AlwaysRebuild() &&
6032 TryBlock.get() == S->getTryBlock() &&
6033 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006034 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006035
John McCall9ae2f072010-08-23 23:25:46 +00006036 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006037 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006038}
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Richard Smithad762fc2011-04-14 22:09:26 +00006040template<typename Derived>
6041StmtResult
6042TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6043 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6044 if (Range.isInvalid())
6045 return StmtError();
6046
6047 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6048 if (BeginEnd.isInvalid())
6049 return StmtError();
6050
6051 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6052 if (Cond.isInvalid())
6053 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006054 if (Cond.get())
6055 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6056 if (Cond.isInvalid())
6057 return StmtError();
6058 if (Cond.get())
6059 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006060
6061 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6062 if (Inc.isInvalid())
6063 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006064 if (Inc.get())
6065 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006066
6067 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6068 if (LoopVar.isInvalid())
6069 return StmtError();
6070
6071 StmtResult NewStmt = S;
6072 if (getDerived().AlwaysRebuild() ||
6073 Range.get() != S->getRangeStmt() ||
6074 BeginEnd.get() != S->getBeginEndStmt() ||
6075 Cond.get() != S->getCond() ||
6076 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006077 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006078 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6079 S->getColonLoc(), Range.get(),
6080 BeginEnd.get(), Cond.get(),
6081 Inc.get(), LoopVar.get(),
6082 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006083 if (NewStmt.isInvalid())
6084 return StmtError();
6085 }
Richard Smithad762fc2011-04-14 22:09:26 +00006086
6087 StmtResult Body = getDerived().TransformStmt(S->getBody());
6088 if (Body.isInvalid())
6089 return StmtError();
6090
6091 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6092 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006093 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006094 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6095 S->getColonLoc(), Range.get(),
6096 BeginEnd.get(), Cond.get(),
6097 Inc.get(), LoopVar.get(),
6098 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006099 if (NewStmt.isInvalid())
6100 return StmtError();
6101 }
Richard Smithad762fc2011-04-14 22:09:26 +00006102
6103 if (NewStmt.get() == S)
6104 return SemaRef.Owned(S);
6105
6106 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6107}
6108
John Wiegley28bbe4b2011-04-28 01:08:34 +00006109template<typename Derived>
6110StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006111TreeTransform<Derived>::TransformMSDependentExistsStmt(
6112 MSDependentExistsStmt *S) {
6113 // Transform the nested-name-specifier, if any.
6114 NestedNameSpecifierLoc QualifierLoc;
6115 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006116 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006117 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6118 if (!QualifierLoc)
6119 return StmtError();
6120 }
6121
6122 // Transform the declaration name.
6123 DeclarationNameInfo NameInfo = S->getNameInfo();
6124 if (NameInfo.getName()) {
6125 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6126 if (!NameInfo.getName())
6127 return StmtError();
6128 }
6129
6130 // Check whether anything changed.
6131 if (!getDerived().AlwaysRebuild() &&
6132 QualifierLoc == S->getQualifierLoc() &&
6133 NameInfo.getName() == S->getNameInfo().getName())
6134 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006135
Douglas Gregorba0513d2011-10-25 01:33:02 +00006136 // Determine whether this name exists, if we can.
6137 CXXScopeSpec SS;
6138 SS.Adopt(QualifierLoc);
6139 bool Dependent = false;
6140 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6141 case Sema::IER_Exists:
6142 if (S->isIfExists())
6143 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006144
Douglas Gregorba0513d2011-10-25 01:33:02 +00006145 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6146
6147 case Sema::IER_DoesNotExist:
6148 if (S->isIfNotExists())
6149 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006150
Douglas Gregorba0513d2011-10-25 01:33:02 +00006151 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006152
Douglas Gregorba0513d2011-10-25 01:33:02 +00006153 case Sema::IER_Dependent:
6154 Dependent = true;
6155 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006156
Douglas Gregor65019ac2011-10-25 03:44:56 +00006157 case Sema::IER_Error:
6158 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006159 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006160
Douglas Gregorba0513d2011-10-25 01:33:02 +00006161 // We need to continue with the instantiation, so do so now.
6162 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6163 if (SubStmt.isInvalid())
6164 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006165
Douglas Gregorba0513d2011-10-25 01:33:02 +00006166 // If we have resolved the name, just transform to the substatement.
6167 if (!Dependent)
6168 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006169
Douglas Gregorba0513d2011-10-25 01:33:02 +00006170 // The name is still dependent, so build a dependent expression again.
6171 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6172 S->isIfExists(),
6173 QualifierLoc,
6174 NameInfo,
6175 SubStmt.get());
6176}
6177
6178template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006179ExprResult
6180TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6181 NestedNameSpecifierLoc QualifierLoc;
6182 if (E->getQualifierLoc()) {
6183 QualifierLoc
6184 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6185 if (!QualifierLoc)
6186 return ExprError();
6187 }
6188
6189 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6190 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6191 if (!PD)
6192 return ExprError();
6193
6194 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6195 if (Base.isInvalid())
6196 return ExprError();
6197
6198 return new (SemaRef.getASTContext())
6199 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6200 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6201 QualifierLoc, E->getMemberLoc());
6202}
6203
6204template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006205StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006206TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6207 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6208 if(TryBlock.isInvalid()) return StmtError();
6209
6210 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6211 if(!getDerived().AlwaysRebuild() &&
6212 TryBlock.get() == S->getTryBlock() &&
6213 Handler.get() == S->getHandler())
6214 return SemaRef.Owned(S);
6215
6216 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6217 S->getTryLoc(),
6218 TryBlock.take(),
6219 Handler.take());
6220}
6221
6222template<typename Derived>
6223StmtResult
6224TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6225 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6226 if(Block.isInvalid()) return StmtError();
6227
6228 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6229 Block.take());
6230}
6231
6232template<typename Derived>
6233StmtResult
6234TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6235 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6236 if(FilterExpr.isInvalid()) return StmtError();
6237
6238 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6239 if(Block.isInvalid()) return StmtError();
6240
6241 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6242 FilterExpr.take(),
6243 Block.take());
6244}
6245
6246template<typename Derived>
6247StmtResult
6248TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6249 if(isa<SEHFinallyStmt>(Handler))
6250 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6251 else
6252 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6253}
6254
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006255template<typename Derived>
6256StmtResult
6257TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6258 // Transform the clauses
Robert Wilhelme7205c02013-08-10 12:33:24 +00006259 SmallVector<OMPClause *, 5> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006260 ArrayRef<OMPClause *> Clauses = D->clauses();
6261 TClauses.reserve(Clauses.size());
6262 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6263 I != E; ++I) {
6264 if (*I) {
6265 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6266 if (!Clause)
6267 return StmtError();
6268 TClauses.push_back(Clause);
6269 }
6270 else {
6271 TClauses.push_back(0);
6272 }
6273 }
6274 if (!D->getAssociatedStmt())
6275 return StmtError();
6276 StmtResult AssociatedStmt =
6277 getDerived().TransformStmt(D->getAssociatedStmt());
6278 if (AssociatedStmt.isInvalid())
6279 return StmtError();
6280
6281 return getDerived().RebuildOMPParallelDirective(TClauses,
6282 AssociatedStmt.take(),
6283 D->getLocStart(),
6284 D->getLocEnd());
6285}
6286
6287template<typename Derived>
6288OMPClause *
6289TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6290 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6291 C->getDefaultKindKwLoc(),
6292 C->getLocStart(),
6293 C->getLParenLoc(),
6294 C->getLocEnd());
6295}
6296
6297template<typename Derived>
6298OMPClause *
6299TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Robert Wilhelme7205c02013-08-10 12:33:24 +00006300 SmallVector<Expr *, 5> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006301 Vars.reserve(C->varlist_size());
6302 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6303 E = C->varlist_end();
6304 I != E; ++I) {
6305 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6306 if (EVar.isInvalid())
6307 return 0;
6308 Vars.push_back(EVar.take());
6309 }
6310 return getDerived().RebuildOMPPrivateClause(Vars,
6311 C->getLocStart(),
6312 C->getLParenLoc(),
6313 C->getLocEnd());
6314}
6315
Douglas Gregor43959a92009-08-20 07:17:43 +00006316//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317// Expression transformation
6318//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006320ExprResult
John McCall454feb92009-12-08 09:21:05 +00006321TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006322 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323}
Mike Stump1eb44332009-09-09 15:08:12 +00006324
6325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006326ExprResult
John McCall454feb92009-12-08 09:21:05 +00006327TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006328 NestedNameSpecifierLoc QualifierLoc;
6329 if (E->getQualifierLoc()) {
6330 QualifierLoc
6331 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6332 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006333 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006334 }
John McCalldbd872f2009-12-08 09:08:17 +00006335
6336 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006337 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6338 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006341
John McCallec8045d2010-08-17 21:27:17 +00006342 DeclarationNameInfo NameInfo = E->getNameInfo();
6343 if (NameInfo.getName()) {
6344 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6345 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006346 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006347 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006348
6349 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006350 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006351 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006352 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006353 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006354
6355 // Mark it referenced in the new context regardless.
6356 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006357 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006358
John McCall3fa5cae2010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006360 }
John McCalldbd872f2009-12-08 09:08:17 +00006361
6362 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006363 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006364 TemplateArgs = &TransArgs;
6365 TransArgs.setLAngleLoc(E->getLAngleLoc());
6366 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006367 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6368 E->getNumTemplateArgs(),
6369 TransArgs))
6370 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006371 }
6372
Chad Rosier4a9d7952012-08-08 18:46:20 +00006373 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006374 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006380 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381}
Mike Stump1eb44332009-09-09 15:08:12 +00006382
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006384ExprResult
John McCall454feb92009-12-08 09:21:05 +00006385TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006386 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387}
Mike Stump1eb44332009-09-09 15:08:12 +00006388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006390ExprResult
John McCall454feb92009-12-08 09:21:05 +00006391TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393}
Mike Stump1eb44332009-09-09 15:08:12 +00006394
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006396ExprResult
John McCall454feb92009-12-08 09:21:05 +00006397TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006398 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399}
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006402ExprResult
John McCall454feb92009-12-08 09:21:05 +00006403TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006404 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006405}
6406
6407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006408ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006409TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006410 if (FunctionDecl *FD = E->getDirectCallee())
6411 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006412 return SemaRef.MaybeBindToTemporary(E);
6413}
6414
6415template<typename Derived>
6416ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006417TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6418 ExprResult ControllingExpr =
6419 getDerived().TransformExpr(E->getControllingExpr());
6420 if (ControllingExpr.isInvalid())
6421 return ExprError();
6422
Chris Lattner686775d2011-07-20 06:58:45 +00006423 SmallVector<Expr *, 4> AssocExprs;
6424 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006425 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6426 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6427 if (TS) {
6428 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6429 if (!AssocType)
6430 return ExprError();
6431 AssocTypes.push_back(AssocType);
6432 } else {
6433 AssocTypes.push_back(0);
6434 }
6435
6436 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6437 if (AssocExpr.isInvalid())
6438 return ExprError();
6439 AssocExprs.push_back(AssocExpr.release());
6440 }
6441
6442 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6443 E->getDefaultLoc(),
6444 E->getRParenLoc(),
6445 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006446 AssocTypes,
6447 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006448}
6449
6450template<typename Derived>
6451ExprResult
John McCall454feb92009-12-08 09:21:05 +00006452TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006453 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006459
John McCall9ae2f072010-08-23 23:25:46 +00006460 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 E->getRParen());
6462}
6463
Richard Smithefeeccf2012-10-21 03:28:35 +00006464/// \brief The operand of a unary address-of operator has special rules: it's
6465/// allowed to refer to a non-static member of a class even if there's no 'this'
6466/// object available.
6467template<typename Derived>
6468ExprResult
6469TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6470 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6471 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6472 else
6473 return getDerived().TransformExpr(E);
6474}
6475
Mike Stump1eb44332009-09-09 15:08:12 +00006476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006477ExprResult
John McCall454feb92009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006479 ExprResult SubExpr;
6480 if (E->getOpcode() == UO_AddrOf)
6481 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6482 else
6483 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6491 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006492 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493}
Mike Stump1eb44332009-09-09 15:08:12 +00006494
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006496ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006497TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6498 // Transform the type.
6499 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6500 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006501 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006502
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006503 // Transform all of the components into components similar to what the
6504 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006505 // FIXME: It would be slightly more efficient in the non-dependent case to
6506 // just map FieldDecls, rather than requiring the rebuilder to look for
6507 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006508 // template code that we don't care.
6509 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006510 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006511 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006512 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006513 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6514 const Node &ON = E->getComponent(I);
6515 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006516 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006517 Comp.LocStart = ON.getSourceRange().getBegin();
6518 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006519 switch (ON.getKind()) {
6520 case Node::Array: {
6521 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006522 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006523 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006524 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006525
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006526 ExprChanged = ExprChanged || Index.get() != FromIndex;
6527 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006528 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006529 break;
6530 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006531
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006532 case Node::Field:
6533 case Node::Identifier:
6534 Comp.isBrackets = false;
6535 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006536 if (!Comp.U.IdentInfo)
6537 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006538
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006539 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006540
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006541 case Node::Base:
6542 // Will be recomputed during the rebuild.
6543 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006544 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006545
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006546 Components.push_back(Comp);
6547 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006548
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006549 // If nothing changed, retain the existing expression.
6550 if (!getDerived().AlwaysRebuild() &&
6551 Type == E->getTypeSourceInfo() &&
6552 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006553 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006554
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006555 // Build a new offsetof expression.
6556 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6557 Components.data(), Components.size(),
6558 E->getRParenLoc());
6559}
6560
6561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006563TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6564 assert(getDerived().AlreadyTransformed(E->getType()) &&
6565 "opaque value expression requires transformation");
6566 return SemaRef.Owned(E);
6567}
6568
6569template<typename Derived>
6570ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006571TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006572 // Rebuild the syntactic form. The original syntactic form has
6573 // opaque-value expressions in it, so strip those away and rebuild
6574 // the result. This is a really awful way of doing this, but the
6575 // better solution (rebuilding the semantic expressions and
6576 // rebinding OVEs as necessary) doesn't work; we'd need
6577 // TreeTransform to not strip away implicit conversions.
6578 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6579 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006580 if (result.isInvalid()) return ExprError();
6581
6582 // If that gives us a pseudo-object result back, the pseudo-object
6583 // expression must have been an lvalue-to-rvalue conversion which we
6584 // should reapply.
6585 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6586 result = SemaRef.checkPseudoObjectRValue(result.take());
6587
6588 return result;
6589}
6590
6591template<typename Derived>
6592ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006593TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6594 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006596 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006597
John McCalla93c9342009-12-07 02:54:59 +00006598 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006599 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006601
John McCall5ab75172009-11-04 07:28:41 +00006602 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006603 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006605 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6606 E->getKind(),
6607 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 }
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006610 // C++0x [expr.sizeof]p1:
6611 // The operand is either an expression, which is an unevaluated operand
6612 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006613 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6614 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006615
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006616 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6617 if (SubExpr.isInvalid())
6618 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006619
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006620 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6621 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006623 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6624 E->getOperatorLoc(),
6625 E->getKind(),
6626 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627}
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>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006632 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006634 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006635
John McCall60d7b3a2010-08-24 06:29:42 +00006636 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
6640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 if (!getDerived().AlwaysRebuild() &&
6642 LHS.get() == E->getLHS() &&
6643 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006644 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006645
John McCall9ae2f072010-08-23 23:25:46 +00006646 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006648 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 E->getRBracketLoc());
6650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
6652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006656 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006658 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659
6660 // Transform arguments.
6661 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006662 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006663 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006664 &ArgChanged))
6665 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (!getDerived().AlwaysRebuild() &&
6668 Callee.get() == E->getCallee() &&
6669 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006670 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006673 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006675 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006676 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 E->getRParenLoc());
6678}
Mike Stump1eb44332009-09-09 15:08:12 +00006679
6680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006681ExprResult
John McCall454feb92009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006683 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregor40d96a62011-02-28 21:54:11 +00006687 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006688 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006689 QualifierLoc
6690 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006691
Douglas Gregor40d96a62011-02-28 21:54:11 +00006692 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006694 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006695 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Eli Friedmanf595cc42009-12-04 06:40:45 +00006697 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006698 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6699 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006702
John McCall6bb80172010-03-30 21:47:33 +00006703 NamedDecl *FoundDecl = E->getFoundDecl();
6704 if (FoundDecl == E->getMemberDecl()) {
6705 FoundDecl = Member;
6706 } else {
6707 FoundDecl = cast_or_null<NamedDecl>(
6708 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6709 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006710 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006711 }
6712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (!getDerived().AlwaysRebuild() &&
6714 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006715 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006716 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006717 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006718 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006719
Anders Carlsson1f240322009-12-22 05:24:09 +00006720 // Mark it referenced in the new context regardless.
6721 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006722 SemaRef.MarkMemberReferenced(E);
6723
John McCall3fa5cae2010-10-26 07:05:15 +00006724 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006725 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726
John McCalld5532b62009-11-23 01:53:49 +00006727 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006728 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006729 TransArgs.setLAngleLoc(E->getLAngleLoc());
6730 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006731 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6732 E->getNumTemplateArgs(),
6733 TransArgs))
6734 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 // FIXME: Bogus source location for the operator
6738 SourceLocation FakeOperatorLoc
6739 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6740
John McCallc2233c52010-01-15 08:34:02 +00006741 // FIXME: to do this check properly, we will need to preserve the
6742 // first-qualifier-in-scope here, just in case we had a dependent
6743 // base (and therefore couldn't do the check) and a
6744 // nested-name-qualifier (and therefore could do the lookup).
6745 NamedDecl *FirstQualifierInScope = 0;
6746
John McCall9ae2f072010-08-23 23:25:46 +00006747 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006749 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006750 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006751 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006752 Member,
John McCall6bb80172010-03-30 21:47:33 +00006753 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006754 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006755 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006756 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757}
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006760ExprResult
John McCall454feb92009-12-08 09:21:05 +00006761TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006762 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006764 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006765
John McCall60d7b3a2010-08-24 06:29:42 +00006766 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (!getDerived().AlwaysRebuild() &&
6771 LHS.get() == E->getLHS() &&
6772 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006773 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Lang Hamesbe9af122012-10-02 04:45:10 +00006775 Sema::FPContractStateRAII FPContractState(getSema());
6776 getSema().FPFeatures.fp_contract = E->isFPContractable();
6777
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006779 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780}
6781
Mike Stump1eb44332009-09-09 15:08:12 +00006782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006783ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006785 CompoundAssignOperator *E) {
6786 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787}
Mike Stump1eb44332009-09-09 15:08:12 +00006788
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006790ExprResult TreeTransform<Derived>::
6791TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6792 // Just rebuild the common and RHS expressions and see whether we
6793 // get any changes.
6794
6795 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6796 if (commonExpr.isInvalid())
6797 return ExprError();
6798
6799 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6800 if (rhs.isInvalid())
6801 return ExprError();
6802
6803 if (!getDerived().AlwaysRebuild() &&
6804 commonExpr.get() == e->getCommon() &&
6805 rhs.get() == e->getFalseExpr())
6806 return SemaRef.Owned(e);
6807
6808 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6809 e->getQuestionLoc(),
6810 0,
6811 e->getColonLoc(),
6812 rhs.get());
6813}
6814
6815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006816ExprResult
John McCall454feb92009-12-08 09:21:05 +00006817TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006818 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006820 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006821
John McCall60d7b3a2010-08-24 06:29:42 +00006822 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006824 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006825
John McCall60d7b3a2010-08-24 06:29:42 +00006826 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (!getDerived().AlwaysRebuild() &&
6831 Cond.get() == E->getCond() &&
6832 LHS.get() == E->getLHS() &&
6833 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006834 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006835
John McCall9ae2f072010-08-23 23:25:46 +00006836 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006837 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006838 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006839 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006840 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841}
Mike Stump1eb44332009-09-09 15:08:12 +00006842
6843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006844ExprResult
John McCall454feb92009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006846 // Implicit casts are eliminated during transformation, since they
6847 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006848 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849}
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006852ExprResult
John McCall454feb92009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006854 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6855 if (!Type)
6856 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006857
John McCall60d7b3a2010-08-24 06:29:42 +00006858 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006859 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006864 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006866 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006867
John McCall9d125032010-01-15 18:39:57 +00006868 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006869 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006871 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006877 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6878 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6879 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006881
John McCall60d7b3a2010-08-24 06:29:42 +00006882 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006884 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006885
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006887 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006889 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890
John McCall1d7d8d62010-01-19 22:33:45 +00006891 // Note: the expression type doesn't necessarily match the
6892 // type-as-written, but that's okay, because it should always be
6893 // derivable from the initializer.
6894
John McCall42f56b52010-01-18 19:35:47 +00006895 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006897 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898}
Mike Stump1eb44332009-09-09 15:08:12 +00006899
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006901ExprResult
John McCall454feb92009-12-08 09:21:05 +00006902TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006903 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006905 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006906
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
6908 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006912 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006914 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 E->getAccessorLoc(),
6916 E->getAccessor());
6917}
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006920ExprResult
John McCall454feb92009-12-08 09:21:05 +00006921TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006924 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006925 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006926 Inits, &InitChanged))
6927 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006928
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006930 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006932 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006933 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934}
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006937ExprResult
John McCall454feb92009-12-08 09:21:05 +00006938TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregor43959a92009-08-20 07:17:43 +00006941 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006942 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006944 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006945
Douglas Gregor43959a92009-08-20 07:17:43 +00006946 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006947 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 bool ExprChanged = false;
6949 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6950 DEnd = E->designators_end();
6951 D != DEnd; ++D) {
6952 if (D->isFieldDesignator()) {
6953 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6954 D->getDotLoc(),
6955 D->getFieldLoc()));
6956 continue;
6957 }
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006960 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006962 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006963
6964 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006966
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6968 ArrayExprs.push_back(Index.release());
6969 continue;
6970 }
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006973 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6975 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006976 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006977
John McCall60d7b3a2010-08-24 06:29:42 +00006978 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006980 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006981
6982 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 End.get(),
6984 D->getLBracketLoc(),
6985 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006986
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6988 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 ArrayExprs.push_back(Start.release());
6991 ArrayExprs.push_back(End.release());
6992 }
Mike Stump1eb44332009-09-09 15:08:12 +00006993
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 if (!getDerived().AlwaysRebuild() &&
6995 Init.get() == E->getInit() &&
6996 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006997 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006999 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007000 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007001 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002}
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007005ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007007 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007008 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007009
Douglas Gregor5557b252009-10-28 00:29:27 +00007010 // FIXME: Will we ever have proper type location here? Will we actually
7011 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 QualType T = getDerived().TransformType(E->getType());
7013 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 if (!getDerived().AlwaysRebuild() &&
7017 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007019
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 return getDerived().RebuildImplicitValueInitExpr(T);
7021}
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
John McCall454feb92009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007026 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7027 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007029
John McCall60d7b3a2010-08-24 06:29:42 +00007030 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007032 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007033
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007035 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007037 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007038
John McCall9ae2f072010-08-23 23:25:46 +00007039 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007040 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041}
7042
7043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007044ExprResult
John McCall454feb92009-12-08 09:21:05 +00007045TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007047 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007048 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7049 &ArgumentChanged))
7050 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007053 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 E->getRParenLoc());
7055}
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057/// \brief Transform an address-of-label expression.
7058///
7059/// By default, the transformation of an address-of-label expression always
7060/// rebuilds the expression, so that the label identifier can be resolved to
7061/// the corresponding label statement by semantic analysis.
7062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007063ExprResult
John McCall454feb92009-12-08 09:21:05 +00007064TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007065 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7066 E->getLabel());
7067 if (!LD)
7068 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007071 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072}
Mike Stump1eb44332009-09-09 15:08:12 +00007073
7074template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007075ExprResult
John McCall454feb92009-12-08 09:21:05 +00007076TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007077 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007078 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007080 if (SubStmt.isInvalid()) {
7081 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007082 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007083 }
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007086 SubStmt.get() == E->getSubStmt()) {
7087 // Calling this an 'error' is unintuitive, but it does the right thing.
7088 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007089 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007090 }
Mike Stump1eb44332009-09-09 15:08:12 +00007091
7092 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007093 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094 E->getRParenLoc());
7095}
Mike Stump1eb44332009-09-09 15:08:12 +00007096
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007098ExprResult
John McCall454feb92009-12-08 09:21:05 +00007099TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007100 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007103
John McCall60d7b3a2010-08-24 06:29:42 +00007104 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007107
John McCall60d7b3a2010-08-24 06:29:42 +00007108 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007110 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 if (!getDerived().AlwaysRebuild() &&
7113 Cond.get() == E->getCond() &&
7114 LHS.get() == E->getLHS() &&
7115 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007116 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007119 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 E->getRParenLoc());
7121}
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007124ExprResult
John McCall454feb92009-12-08 09:21:05 +00007125TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127}
7128
7129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007130ExprResult
John McCall454feb92009-12-08 09:21:05 +00007131TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007132 switch (E->getOperator()) {
7133 case OO_New:
7134 case OO_Delete:
7135 case OO_Array_New:
7136 case OO_Array_Delete:
7137 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007138
Douglas Gregor668d6d92009-12-13 20:44:55 +00007139 case OO_Call: {
7140 // This is a call to an object's operator().
7141 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7142
7143 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007144 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007145 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007146 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007147
7148 // FIXME: Poor location information
7149 SourceLocation FakeLParenLoc
7150 = SemaRef.PP.getLocForEndOfToken(
7151 static_cast<Expr *>(Object.get())->getLocEnd());
7152
7153 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007154 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007155 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007156 Args))
7157 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007158
John McCall9ae2f072010-08-23 23:25:46 +00007159 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007160 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007161 E->getLocEnd());
7162 }
7163
7164#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7165 case OO_##Name:
7166#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7167#include "clang/Basic/OperatorKinds.def"
7168 case OO_Subscript:
7169 // Handled below.
7170 break;
7171
7172 case OO_Conditional:
7173 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007174
7175 case OO_None:
7176 case NUM_OVERLOADED_OPERATORS:
7177 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007178 }
7179
John McCall60d7b3a2010-08-24 06:29:42 +00007180 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Richard Smithefeeccf2012-10-21 03:28:35 +00007184 ExprResult First;
7185 if (E->getOperator() == OO_Amp)
7186 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7187 else
7188 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007190 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191
John McCall60d7b3a2010-08-24 06:29:42 +00007192 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 if (E->getNumArgs() == 2) {
7194 Second = getDerived().TransformExpr(E->getArg(1));
7195 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 }
Mike Stump1eb44332009-09-09 15:08:12 +00007198
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199 if (!getDerived().AlwaysRebuild() &&
7200 Callee.get() == E->getCallee() &&
7201 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007202 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007203 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Lang Hamesbe9af122012-10-02 04:45:10 +00007205 Sema::FPContractStateRAII FPContractState(getSema());
7206 getSema().FPFeatures.fp_contract = E->isFPContractable();
7207
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7209 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007210 Callee.get(),
7211 First.get(),
7212 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213}
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007216ExprResult
John McCall454feb92009-12-08 09:21:05 +00007217TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7218 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007223TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7224 // Transform the callee.
7225 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7226 if (Callee.isInvalid())
7227 return ExprError();
7228
7229 // Transform exec config.
7230 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7231 if (EC.isInvalid())
7232 return ExprError();
7233
7234 // Transform arguments.
7235 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007236 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007237 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007238 &ArgChanged))
7239 return ExprError();
7240
7241 if (!getDerived().AlwaysRebuild() &&
7242 Callee.get() == E->getCallee() &&
7243 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007244 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007245
7246 // FIXME: Wrong source location information for the '('.
7247 SourceLocation FakeLParenLoc
7248 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7249 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007250 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007251 E->getRParenLoc(), EC.get());
7252}
7253
7254template<typename Derived>
7255ExprResult
John McCall454feb92009-12-08 09:21:05 +00007256TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007257 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7258 if (!Type)
7259 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007260
John McCall60d7b3a2010-08-24 06:29:42 +00007261 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007262 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007267 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007269 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007270 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007271 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007272 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007273 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007274 E->getAngleBrackets().getEnd(),
7275 // FIXME. this should be '(' location
7276 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007277 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007278 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007279}
Mike Stump1eb44332009-09-09 15:08:12 +00007280
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007282ExprResult
John McCall454feb92009-12-08 09:21:05 +00007283TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7284 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285}
Mike Stump1eb44332009-09-09 15:08:12 +00007286
7287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007288ExprResult
John McCall454feb92009-12-08 09:21:05 +00007289TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7290 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007291}
7292
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007294ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007296 CXXReinterpretCastExpr *E) {
7297 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298}
Mike Stump1eb44332009-09-09 15:08:12 +00007299
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007301ExprResult
John McCall454feb92009-12-08 09:21:05 +00007302TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7303 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304}
Mike Stump1eb44332009-09-09 15:08:12 +00007305
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007307ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007309 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007310 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7311 if (!Type)
7312 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007313
John McCall60d7b3a2010-08-24 06:29:42 +00007314 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007315 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007320 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007322 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007324 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007325 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007326 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 E->getRParenLoc());
7328}
Mike Stump1eb44332009-09-09 15:08:12 +00007329
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007331ExprResult
John McCall454feb92009-12-08 09:21:05 +00007332TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007334 TypeSourceInfo *TInfo
7335 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7336 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007337 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007338
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007340 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007341 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007342
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007343 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7344 E->getLocStart(),
7345 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 E->getLocEnd());
7347 }
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Eli Friedmanef331b72012-01-20 01:26:23 +00007349 // We don't know whether the subexpression is potentially evaluated until
7350 // after we perform semantic analysis. We speculatively assume it is
7351 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007352 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007353 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7354 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007355
John McCall60d7b3a2010-08-24 06:29:42 +00007356 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 if (!getDerived().AlwaysRebuild() &&
7361 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007362 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007364 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7365 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007366 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367 E->getLocEnd());
7368}
7369
7370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007371ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007372TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7373 if (E->isTypeOperand()) {
7374 TypeSourceInfo *TInfo
7375 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7376 if (!TInfo)
7377 return ExprError();
7378
7379 if (!getDerived().AlwaysRebuild() &&
7380 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007381 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007382
Douglas Gregor3c52a212011-03-06 17:40:41 +00007383 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007384 E->getLocStart(),
7385 TInfo,
7386 E->getLocEnd());
7387 }
7388
Francois Pichet01b7c302010-09-08 12:20:18 +00007389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7390
7391 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7392 if (SubExpr.isInvalid())
7393 return ExprError();
7394
7395 if (!getDerived().AlwaysRebuild() &&
7396 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007397 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007398
7399 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7400 E->getLocStart(),
7401 SubExpr.get(),
7402 E->getLocEnd());
7403}
7404
7405template<typename Derived>
7406ExprResult
John McCall454feb92009-12-08 09:21:05 +00007407TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007408 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007409}
Mike Stump1eb44332009-09-09 15:08:12 +00007410
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007412ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007414 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007415 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416}
Mike Stump1eb44332009-09-09 15:08:12 +00007417
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007419ExprResult
John McCall454feb92009-12-08 09:21:05 +00007420TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007421 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007422
Douglas Gregorec79d872012-02-24 17:41:38 +00007423 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7424 // Make sure that we capture 'this'.
7425 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007426 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007427 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007428
Douglas Gregor828a1972010-01-07 23:12:05 +00007429 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430}
Mike Stump1eb44332009-09-09 15:08:12 +00007431
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007433ExprResult
John McCall454feb92009-12-08 09:21:05 +00007434TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007435 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439 if (!getDerived().AlwaysRebuild() &&
7440 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007441 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007442
Douglas Gregorbca01b42011-07-06 22:04:06 +00007443 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7444 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007445}
Mike Stump1eb44332009-09-09 15:08:12 +00007446
Douglas Gregorb98b1992009-08-11 05:31:07 +00007447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007448ExprResult
John McCall454feb92009-12-08 09:21:05 +00007449TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007450 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007451 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7452 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007455
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007456 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007459
Douglas Gregor036aed12009-12-23 23:03:06 +00007460 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461}
Mike Stump1eb44332009-09-09 15:08:12 +00007462
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007464ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007465TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7466 FieldDecl *Field
7467 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7468 E->getField()));
7469 if (!Field)
7470 return ExprError();
7471
7472 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7473 return SemaRef.Owned(E);
7474
7475 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7476}
7477
7478template<typename Derived>
7479ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007480TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7481 CXXScalarValueInitExpr *E) {
7482 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7483 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007484 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007485
Douglas Gregorb98b1992009-08-11 05:31:07 +00007486 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007487 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007489
Chad Rosier4a9d7952012-08-08 18:46:20 +00007490 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007491 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007492 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007493}
Mike Stump1eb44332009-09-09 15:08:12 +00007494
Douglas Gregorb98b1992009-08-11 05:31:07 +00007495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007496ExprResult
John McCall454feb92009-12-08 09:21:05 +00007497TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007499 TypeSourceInfo *AllocTypeInfo
7500 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7501 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007505 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509 // Transform the placement arguments (if any).
7510 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007511 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007512 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007513 E->getNumPlacementArgs(), true,
7514 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007516
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007517 // Transform the initializer (if any).
7518 Expr *OldInit = E->getInitializer();
7519 ExprResult NewInit;
7520 if (OldInit)
7521 NewInit = getDerived().TransformExpr(OldInit);
7522 if (NewInit.isInvalid())
7523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007524
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007525 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007526 FunctionDecl *OperatorNew = 0;
7527 if (E->getOperatorNew()) {
7528 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007529 getDerived().TransformDecl(E->getLocStart(),
7530 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007531 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007532 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007533 }
7534
7535 FunctionDecl *OperatorDelete = 0;
7536 if (E->getOperatorDelete()) {
7537 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007538 getDerived().TransformDecl(E->getLocStart(),
7539 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007540 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007541 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007542 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007543
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007545 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007547 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007548 OperatorNew == E->getOperatorNew() &&
7549 OperatorDelete == E->getOperatorDelete() &&
7550 !ArgumentChanged) {
7551 // Mark any declarations we need as referenced.
7552 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007553 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007554 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007555 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007556 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007557
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007558 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007559 QualType ElementType
7560 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7561 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7562 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7563 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007564 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007565 }
7566 }
7567 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007568
John McCall3fa5cae2010-10-26 07:05:15 +00007569 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007570 }
Mike Stump1eb44332009-09-09 15:08:12 +00007571
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007572 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007573 if (!ArraySize.get()) {
7574 // If no array size was specified, but the new expression was
7575 // instantiated with an array type (e.g., "new T" where T is
7576 // instantiated with "int[4]"), extract the outer bound from the
7577 // array type as our array size. We do this with constant and
7578 // dependently-sized array types.
7579 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7580 if (!ArrayT) {
7581 // Do nothing
7582 } else if (const ConstantArrayType *ConsArrayT
7583 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007584 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007585 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007586 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007587 SemaRef.Context.getSizeType(),
7588 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007589 AllocType = ConsArrayT->getElementType();
7590 } else if (const DependentSizedArrayType *DepArrayT
7591 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7592 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007593 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007594 AllocType = DepArrayT->getElementType();
7595 }
7596 }
7597 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007598
Douglas Gregorb98b1992009-08-11 05:31:07 +00007599 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7600 E->isGlobalNew(),
7601 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007602 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007604 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007605 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007606 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007607 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007608 E->getDirectInitRange(),
7609 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007610}
Mike Stump1eb44332009-09-09 15:08:12 +00007611
Douglas Gregorb98b1992009-08-11 05:31:07 +00007612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007613ExprResult
John McCall454feb92009-12-08 09:21:05 +00007614TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007615 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007616 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007618
Douglas Gregor1af74512010-02-26 00:38:10 +00007619 // Transform the delete operator, if known.
7620 FunctionDecl *OperatorDelete = 0;
7621 if (E->getOperatorDelete()) {
7622 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007623 getDerived().TransformDecl(E->getLocStart(),
7624 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007625 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007626 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007627 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007628
Douglas Gregorb98b1992009-08-11 05:31:07 +00007629 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007630 Operand.get() == E->getArgument() &&
7631 OperatorDelete == E->getOperatorDelete()) {
7632 // Mark any declarations we need as referenced.
7633 // FIXME: instantiation-specific.
7634 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007635 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007636
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007637 if (!E->getArgument()->isTypeDependent()) {
7638 QualType Destroyed = SemaRef.Context.getBaseElementType(
7639 E->getDestroyedType());
7640 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7641 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007642 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007643 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007644 }
7645 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007646
John McCall3fa5cae2010-10-26 07:05:15 +00007647 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007648 }
Mike Stump1eb44332009-09-09 15:08:12 +00007649
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7651 E->isGlobalDelete(),
7652 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007653 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007654}
Mike Stump1eb44332009-09-09 15:08:12 +00007655
Douglas Gregorb98b1992009-08-11 05:31:07 +00007656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007657ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007658TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007659 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007660 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007661 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007663
John McCallb3d87482010-08-24 05:47:05 +00007664 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007665 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007666 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007667 E->getOperatorLoc(),
7668 E->isArrow()? tok::arrow : tok::period,
7669 ObjectTypePtr,
7670 MayBePseudoDestructor);
7671 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007672 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007673
John McCallb3d87482010-08-24 05:47:05 +00007674 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007675 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7676 if (QualifierLoc) {
7677 QualifierLoc
7678 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7679 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007680 return ExprError();
7681 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007682 CXXScopeSpec SS;
7683 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007684
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007685 PseudoDestructorTypeStorage Destroyed;
7686 if (E->getDestroyedTypeInfo()) {
7687 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007688 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007689 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007690 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007691 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007692 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007693 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007694 // We aren't likely to be able to resolve the identifier down to a type
7695 // now anyway, so just retain the identifier.
7696 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7697 E->getDestroyedTypeLoc());
7698 } else {
7699 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007700 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007701 *E->getDestroyedTypeIdentifier(),
7702 E->getDestroyedTypeLoc(),
7703 /*Scope=*/0,
7704 SS, ObjectTypePtr,
7705 false);
7706 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007707 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007708
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007709 Destroyed
7710 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7711 E->getDestroyedTypeLoc());
7712 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007713
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007714 TypeSourceInfo *ScopeTypeInfo = 0;
7715 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007716 CXXScopeSpec EmptySS;
7717 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7718 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007719 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007720 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007722
John McCall9ae2f072010-08-23 23:25:46 +00007723 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007724 E->getOperatorLoc(),
7725 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007726 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007727 ScopeTypeInfo,
7728 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007729 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007730 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007731}
Mike Stump1eb44332009-09-09 15:08:12 +00007732
Douglas Gregora71d8192009-09-04 17:36:40 +00007733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007734ExprResult
John McCallba135432009-11-21 08:51:07 +00007735TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007736 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007737 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7738 Sema::LookupOrdinaryName);
7739
7740 // Transform all the decls.
7741 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7742 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007743 NamedDecl *InstD = static_cast<NamedDecl*>(
7744 getDerived().TransformDecl(Old->getNameLoc(),
7745 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007746 if (!InstD) {
7747 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7748 // This can happen because of dependent hiding.
7749 if (isa<UsingShadowDecl>(*I))
7750 continue;
7751 else
John McCallf312b1e2010-08-26 23:41:50 +00007752 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007753 }
John McCallf7a1a742009-11-24 19:00:30 +00007754
7755 // Expand using declarations.
7756 if (isa<UsingDecl>(InstD)) {
7757 UsingDecl *UD = cast<UsingDecl>(InstD);
7758 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7759 E = UD->shadow_end(); I != E; ++I)
7760 R.addDecl(*I);
7761 continue;
7762 }
7763
7764 R.addDecl(InstD);
7765 }
7766
7767 // Resolve a kind, but don't do any further analysis. If it's
7768 // ambiguous, the callee needs to deal with it.
7769 R.resolveKind();
7770
7771 // Rebuild the nested-name qualifier, if present.
7772 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007773 if (Old->getQualifierLoc()) {
7774 NestedNameSpecifierLoc QualifierLoc
7775 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7776 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007777 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007778
Douglas Gregor4c9be892011-02-28 20:01:57 +00007779 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007780 }
7781
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007782 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007783 CXXRecordDecl *NamingClass
7784 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7785 Old->getNameLoc(),
7786 Old->getNamingClass()));
7787 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007789
Douglas Gregor66c45152010-04-27 16:10:10 +00007790 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007791 }
7792
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007793 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7794
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007795 // If we have neither explicit template arguments, nor the template keyword,
7796 // it's a normal declaration name.
7797 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007798 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7799
7800 // If we have template arguments, rebuild them, then rebuild the
7801 // templateid expression.
7802 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007803 if (Old->hasExplicitTemplateArgs() &&
7804 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007805 Old->getNumTemplateArgs(),
7806 TransArgs))
7807 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007808
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007809 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007810 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811}
Mike Stump1eb44332009-09-09 15:08:12 +00007812
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>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007816 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7817 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007819
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007821 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007822 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007823
Mike Stump1eb44332009-09-09 15:08:12 +00007824 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007826 T,
7827 E->getLocEnd());
7828}
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
Francois Pichet6ad6f282010-12-07 00:08:36 +00007832TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7833 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7834 if (!LhsT)
7835 return ExprError();
7836
7837 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7838 if (!RhsT)
7839 return ExprError();
7840
7841 if (!getDerived().AlwaysRebuild() &&
7842 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7843 return SemaRef.Owned(E);
7844
7845 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7846 E->getLocStart(),
7847 LhsT, RhsT,
7848 E->getLocEnd());
7849}
7850
7851template<typename Derived>
7852ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007853TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7854 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007855 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007856 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7857 TypeSourceInfo *From = E->getArg(I);
7858 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007859 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007860 TypeLocBuilder TLB;
7861 TLB.reserve(FromTL.getFullDataSize());
7862 QualType To = getDerived().TransformType(TLB, FromTL);
7863 if (To.isNull())
7864 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007865
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007866 if (To == From->getType())
7867 Args.push_back(From);
7868 else {
7869 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7870 ArgChanged = true;
7871 }
7872 continue;
7873 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007874
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007875 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007876
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007877 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007878 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007879 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7880 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7881 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007882
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007883 // Determine whether the set of unexpanded parameter packs can and should
7884 // be expanded.
7885 bool Expand = true;
7886 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007887 Optional<unsigned> OrigNumExpansions =
7888 ExpansionTL.getTypePtr()->getNumExpansions();
7889 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007890 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7891 PatternTL.getSourceRange(),
7892 Unexpanded,
7893 Expand, RetainExpansion,
7894 NumExpansions))
7895 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007896
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007897 if (!Expand) {
7898 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007899 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007900 // expansion.
7901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007902
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007903 TypeLocBuilder TLB;
7904 TLB.reserve(From->getTypeLoc().getFullDataSize());
7905
7906 QualType To = getDerived().TransformType(TLB, PatternTL);
7907 if (To.isNull())
7908 return ExprError();
7909
Chad Rosier4a9d7952012-08-08 18:46:20 +00007910 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007911 PatternTL.getSourceRange(),
7912 ExpansionTL.getEllipsisLoc(),
7913 NumExpansions);
7914 if (To.isNull())
7915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007916
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007917 PackExpansionTypeLoc ToExpansionTL
7918 = TLB.push<PackExpansionTypeLoc>(To);
7919 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7920 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7921 continue;
7922 }
7923
7924 // Expand the pack expansion by substituting for each argument in the
7925 // pack(s).
7926 for (unsigned I = 0; I != *NumExpansions; ++I) {
7927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7928 TypeLocBuilder TLB;
7929 TLB.reserve(PatternTL.getFullDataSize());
7930 QualType To = getDerived().TransformType(TLB, PatternTL);
7931 if (To.isNull())
7932 return ExprError();
7933
Eli Friedman20cfeca2013-07-19 21:49:32 +00007934 if (To->containsUnexpandedParameterPack()) {
7935 To = getDerived().RebuildPackExpansionType(To,
7936 PatternTL.getSourceRange(),
7937 ExpansionTL.getEllipsisLoc(),
7938 NumExpansions);
7939 if (To.isNull())
7940 return ExprError();
7941
7942 PackExpansionTypeLoc ToExpansionTL
7943 = TLB.push<PackExpansionTypeLoc>(To);
7944 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7945 }
7946
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007947 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007949
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007950 if (!RetainExpansion)
7951 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007953 // If we're supposed to retain a pack expansion, do so by temporarily
7954 // forgetting the partially-substituted parameter pack.
7955 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7956
7957 TypeLocBuilder TLB;
7958 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007959
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007960 QualType To = getDerived().TransformType(TLB, PatternTL);
7961 if (To.isNull())
7962 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963
7964 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007965 PatternTL.getSourceRange(),
7966 ExpansionTL.getEllipsisLoc(),
7967 NumExpansions);
7968 if (To.isNull())
7969 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007970
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007971 PackExpansionTypeLoc ToExpansionTL
7972 = TLB.push<PackExpansionTypeLoc>(To);
7973 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7974 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7975 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007977 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7978 return SemaRef.Owned(E);
7979
7980 return getDerived().RebuildTypeTrait(E->getTrait(),
7981 E->getLocStart(),
7982 Args,
7983 E->getLocEnd());
7984}
7985
7986template<typename Derived>
7987ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007988TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7989 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7990 if (!T)
7991 return ExprError();
7992
7993 if (!getDerived().AlwaysRebuild() &&
7994 T == E->getQueriedTypeSourceInfo())
7995 return SemaRef.Owned(E);
7996
7997 ExprResult SubExpr;
7998 {
7999 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8000 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8001 if (SubExpr.isInvalid())
8002 return ExprError();
8003
8004 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8005 return SemaRef.Owned(E);
8006 }
8007
8008 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8009 E->getLocStart(),
8010 T,
8011 SubExpr.get(),
8012 E->getLocEnd());
8013}
8014
8015template<typename Derived>
8016ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008017TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8018 ExprResult SubExpr;
8019 {
8020 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8021 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8022 if (SubExpr.isInvalid())
8023 return ExprError();
8024
8025 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8026 return SemaRef.Owned(E);
8027 }
8028
8029 return getDerived().RebuildExpressionTrait(
8030 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8031}
8032
8033template<typename Derived>
8034ExprResult
John McCall865d4472009-11-19 22:55:06 +00008035TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008036 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008037 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8038}
8039
8040template<typename Derived>
8041ExprResult
8042TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8043 DependentScopeDeclRefExpr *E,
8044 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008045 NestedNameSpecifierLoc QualifierLoc
8046 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8047 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008048 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008049 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008050
John McCall43fed0d2010-11-12 08:19:04 +00008051 // TODO: If this is a conversion-function-id, verify that the
8052 // destination type name (if present) resolves the same way after
8053 // instantiation as it did in the local scope.
8054
Abramo Bagnara25777432010-08-11 22:01:17 +00008055 DeclarationNameInfo NameInfo
8056 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8057 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008058 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008059
John McCallf7a1a742009-11-24 19:00:30 +00008060 if (!E->hasExplicitTemplateArgs()) {
8061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008062 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008063 // Note: it is sufficient to compare the Name component of NameInfo:
8064 // if name has not changed, DNLoc has not changed either.
8065 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008066 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008067
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008068 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008069 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008070 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008071 /*TemplateArgs*/ 0,
8072 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008073 }
John McCalld5532b62009-11-23 01:53:49 +00008074
8075 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008076 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8077 E->getNumTemplateArgs(),
8078 TransArgs))
8079 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008080
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008081 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008082 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008083 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008084 &TransArgs,
8085 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008086}
8087
8088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008089ExprResult
John McCall454feb92009-12-08 09:21:05 +00008090TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008091 // CXXConstructExprs other than for list-initialization and
8092 // CXXTemporaryObjectExpr are always implicit, so when we have
8093 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008094 if ((E->getNumArgs() == 1 ||
8095 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008096 (!getDerived().DropCallArgument(E->getArg(0))) &&
8097 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008098 return getDerived().TransformExpr(E->getArg(0));
8099
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8101
8102 QualType T = getDerived().TransformType(E->getType());
8103 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008104 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105
8106 CXXConstructorDecl *Constructor
8107 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008108 getDerived().TransformDecl(E->getLocStart(),
8109 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008110 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008112
Douglas Gregorb98b1992009-08-11 05:31:07 +00008113 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008114 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008115 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008116 &ArgumentChanged))
8117 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008118
Douglas Gregorb98b1992009-08-11 05:31:07 +00008119 if (!getDerived().AlwaysRebuild() &&
8120 T == E->getType() &&
8121 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008122 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008123 // Mark the constructor as referenced.
8124 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008125 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008126 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008127 }
Mike Stump1eb44332009-09-09 15:08:12 +00008128
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008129 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8130 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008131 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008132 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008133 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008134 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008135 E->getConstructionKind(),
8136 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008137}
Mike Stump1eb44332009-09-09 15:08:12 +00008138
Douglas Gregorb98b1992009-08-11 05:31:07 +00008139/// \brief Transform a C++ temporary-binding expression.
8140///
Douglas Gregor51326552009-12-24 18:51:59 +00008141/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8142/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008144ExprResult
John McCall454feb92009-12-08 09:21:05 +00008145TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008146 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008147}
Mike Stump1eb44332009-09-09 15:08:12 +00008148
John McCall4765fa02010-12-06 08:20:24 +00008149/// \brief Transform a C++ expression that contains cleanups that should
8150/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151///
John McCall4765fa02010-12-06 08:20:24 +00008152/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008153/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008155ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008156TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008157 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158}
Mike Stump1eb44332009-09-09 15:08:12 +00008159
Douglas Gregorb98b1992009-08-11 05:31:07 +00008160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008161ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008162TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008163 CXXTemporaryObjectExpr *E) {
8164 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8165 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008167
Douglas Gregorb98b1992009-08-11 05:31:07 +00008168 CXXConstructorDecl *Constructor
8169 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008170 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008171 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008174
Douglas Gregorb98b1992009-08-11 05:31:07 +00008175 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008176 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008177 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008178 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008179 &ArgumentChanged))
8180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008181
Douglas Gregorb98b1992009-08-11 05:31:07 +00008182 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008183 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008184 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008185 !ArgumentChanged) {
8186 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008187 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008188 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008189 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008190
Richard Smithc83c2302012-12-19 01:39:02 +00008191 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008192 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8193 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008194 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008195 E->getLocEnd());
8196}
Mike Stump1eb44332009-09-09 15:08:12 +00008197
Douglas Gregorb98b1992009-08-11 05:31:07 +00008198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008199ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008200TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valiecb58192013-08-22 01:49:11 +00008201
8202 // FIXME: Implement nested generic lambda transformations.
8203 if (E->isGenericLambda()) {
8204 getSema().Diag(E->getIntroducerRange().getBegin(),
8205 diag::err_glambda_not_fully_implemented)
8206 << " nested lambdas not implemented yet";
8207 return ExprError();
8208 }
Douglas Gregordfca6f52012-02-13 22:00:16 +00008209 // Transform the type of the lambda parameters and start the definition of
8210 // the lambda itself.
8211 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008212 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008213 if (!MethodTy)
8214 return ExprError();
8215
Eli Friedman8da8a662012-09-19 01:18:11 +00008216 // Create the local class that will describe the lambda.
8217 CXXRecordDecl *Class
8218 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8219 MethodTy,
8220 /*KnownDependent=*/false);
8221 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8222
Douglas Gregorc6889e72012-02-14 22:28:59 +00008223 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008224 SmallVector<QualType, 4> ParamTypes;
8225 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008226 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8227 E->getCallOperator()->param_begin(),
8228 E->getCallOperator()->param_size(),
8229 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008230 return ExprError();
Faisal Valiecb58192013-08-22 01:49:11 +00008231 getSema().PushLambdaScope();
8232 LambdaScopeInfo *LSI = getSema().getCurLambda();
8233 // TODO: Fix for nested lambdas
8234 LSI->GLTemplateParameterList = 0;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008235 // Build the call operator.
8236 CXXMethodDecl *CallOperator
8237 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008238 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008239 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008240 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008241 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008242
Richard Smith612409e2012-07-25 03:56:55 +00008243 return getDerived().TransformLambdaScope(E, CallOperator);
8244}
8245
8246template<typename Derived>
8247ExprResult
8248TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8249 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008250 bool Invalid = false;
8251
8252 // Transform any init-capture expressions before entering the scope of the
8253 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008254 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008255 InitCaptureExprs.resize(E->explicit_capture_end() -
8256 E->explicit_capture_begin());
8257 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8258 CEnd = E->capture_end();
8259 C != CEnd; ++C) {
8260 if (!C->isInitCapture())
8261 continue;
8262 InitCaptureExprs[C - E->capture_begin()] =
8263 getDerived().TransformExpr(E->getInitCaptureInit(C));
8264 }
8265
Douglas Gregord5387e82012-02-14 00:00:48 +00008266 // Introduce the context of the call operator.
8267 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8268
Faisal Valiecb58192013-08-22 01:49:11 +00008269 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008270 // Enter the scope of the lambda.
Faisal Valiecb58192013-08-22 01:49:11 +00008271 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008272 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008273 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008274 E->hasExplicitParameters(),
8275 E->hasExplicitResultType(),
8276 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008277
Douglas Gregordfca6f52012-02-13 22:00:16 +00008278 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008279 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008280 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008281 CEnd = E->capture_end();
8282 C != CEnd; ++C) {
8283 // When we hit the first implicit capture, tell Sema that we've finished
8284 // the list of explicit captures.
8285 if (!FinishedExplicitCaptures && C->isImplicit()) {
8286 getSema().finishLambdaExplicitCaptures(LSI);
8287 FinishedExplicitCaptures = true;
8288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008289
Douglas Gregordfca6f52012-02-13 22:00:16 +00008290 // Capturing 'this' is trivial.
8291 if (C->capturesThis()) {
8292 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8293 continue;
8294 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008295
Richard Smith0d8e9642013-05-16 06:20:58 +00008296 // Rebuild init-captures, including the implied field declaration.
8297 if (C->isInitCapture()) {
8298 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8299 if (Init.isInvalid()) {
8300 Invalid = true;
8301 continue;
8302 }
8303 FieldDecl *OldFD = C->getInitCaptureField();
8304 FieldDecl *NewFD = getSema().checkInitCapture(
8305 C->getLocation(), OldFD->getType()->isReferenceType(),
8306 OldFD->getIdentifier(), Init.take());
8307 if (!NewFD)
8308 Invalid = true;
8309 else
8310 getDerived().transformedLocalDecl(OldFD, NewFD);
8311 continue;
8312 }
8313
8314 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8315
Douglas Gregora7365242012-02-14 19:27:52 +00008316 // Determine the capture kind for Sema.
8317 Sema::TryCaptureKind Kind
8318 = C->isImplicit()? Sema::TryCapture_Implicit
8319 : C->getCaptureKind() == LCK_ByCopy
8320 ? Sema::TryCapture_ExplicitByVal
8321 : Sema::TryCapture_ExplicitByRef;
8322 SourceLocation EllipsisLoc;
8323 if (C->isPackExpansion()) {
8324 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8325 bool ShouldExpand = false;
8326 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008327 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008328 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8329 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008330 Unexpanded,
8331 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008332 NumExpansions)) {
8333 Invalid = true;
8334 continue;
8335 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008336
Douglas Gregora7365242012-02-14 19:27:52 +00008337 if (ShouldExpand) {
8338 // The transform has determined that we should perform an expansion;
8339 // transform and capture each of the arguments.
8340 // expansion of the pattern. Do so.
8341 VarDecl *Pack = C->getCapturedVar();
8342 for (unsigned I = 0; I != *NumExpansions; ++I) {
8343 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8344 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008345 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008346 Pack));
8347 if (!CapturedVar) {
8348 Invalid = true;
8349 continue;
8350 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351
Douglas Gregora7365242012-02-14 19:27:52 +00008352 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008353 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8354 }
Douglas Gregora7365242012-02-14 19:27:52 +00008355 continue;
8356 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357
Douglas Gregora7365242012-02-14 19:27:52 +00008358 EllipsisLoc = C->getEllipsisLoc();
8359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregordfca6f52012-02-13 22:00:16 +00008361 // Transform the captured variable.
8362 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008364 C->getCapturedVar()));
8365 if (!CapturedVar) {
8366 Invalid = true;
8367 continue;
8368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369
Douglas Gregordfca6f52012-02-13 22:00:16 +00008370 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008371 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008372 }
8373 if (!FinishedExplicitCaptures)
8374 getSema().finishLambdaExplicitCaptures(LSI);
8375
Douglas Gregordfca6f52012-02-13 22:00:16 +00008376
8377 // Enter a new evaluation context to insulate the lambda from any
8378 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008379 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008380
8381 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008382 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008383 /*IsInstantiation=*/true);
8384 return ExprError();
8385 }
8386
8387 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008388 StmtResult Body = getDerived().TransformStmt(E->getBody());
8389 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008390 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008391 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008392 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008393 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008394
Chad Rosier4a9d7952012-08-08 18:46:20 +00008395 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008396 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008397}
8398
8399template<typename Derived>
8400ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008401TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008402 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008403 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8404 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008406
Douglas Gregorb98b1992009-08-11 05:31:07 +00008407 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008408 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008409 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008410 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008411 &ArgumentChanged))
8412 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008413
Douglas Gregorb98b1992009-08-11 05:31:07 +00008414 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008415 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008416 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008417 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008418
Douglas Gregorb98b1992009-08-11 05:31:07 +00008419 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008420 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008421 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008422 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008423 E->getRParenLoc());
8424}
Mike Stump1eb44332009-09-09 15:08:12 +00008425
Douglas Gregorb98b1992009-08-11 05:31:07 +00008426template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008427ExprResult
John McCall865d4472009-11-19 22:55:06 +00008428TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008429 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008430 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008431 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008432 Expr *OldBase;
8433 QualType BaseType;
8434 QualType ObjectType;
8435 if (!E->isImplicitAccess()) {
8436 OldBase = E->getBase();
8437 Base = getDerived().TransformExpr(OldBase);
8438 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008439 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008440
John McCallaa81e162009-12-01 22:10:20 +00008441 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008442 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008443 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008444 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008445 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008446 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008447 ObjectTy,
8448 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008449 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008450 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008451
John McCallb3d87482010-08-24 05:47:05 +00008452 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008453 BaseType = ((Expr*) Base.get())->getType();
8454 } else {
8455 OldBase = 0;
8456 BaseType = getDerived().TransformType(E->getBaseType());
8457 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8458 }
Mike Stump1eb44332009-09-09 15:08:12 +00008459
Douglas Gregor6cd21982009-10-20 05:58:46 +00008460 // Transform the first part of the nested-name-specifier that qualifies
8461 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008462 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008463 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008464 E->getFirstQualifierFoundInScope(),
8465 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008466
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008467 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008468 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008469 QualifierLoc
8470 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8471 ObjectType,
8472 FirstQualifierInScope);
8473 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008474 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008475 }
Mike Stump1eb44332009-09-09 15:08:12 +00008476
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008477 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8478
John McCall43fed0d2010-11-12 08:19:04 +00008479 // TODO: If this is a conversion-function-id, verify that the
8480 // destination type name (if present) resolves the same way after
8481 // instantiation as it did in the local scope.
8482
Abramo Bagnara25777432010-08-11 22:01:17 +00008483 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008484 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008485 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008487
John McCallaa81e162009-12-01 22:10:20 +00008488 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008489 // This is a reference to a member without an explicitly-specified
8490 // template argument list. Optimize for this common case.
8491 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008492 Base.get() == OldBase &&
8493 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008494 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008495 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008496 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008498
John McCall9ae2f072010-08-23 23:25:46 +00008499 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008500 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008501 E->isArrow(),
8502 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008503 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008504 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008505 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008506 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008507 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008508 }
8509
John McCalld5532b62009-11-23 01:53:49 +00008510 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008511 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8512 E->getNumTemplateArgs(),
8513 TransArgs))
8514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008515
John McCall9ae2f072010-08-23 23:25:46 +00008516 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008517 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008518 E->isArrow(),
8519 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008520 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008521 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008522 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008523 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008524 &TransArgs);
8525}
8526
8527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008528ExprResult
John McCall454feb92009-12-08 09:21:05 +00008529TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008530 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008531 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008532 QualType BaseType;
8533 if (!Old->isImplicitAccess()) {
8534 Base = getDerived().TransformExpr(Old->getBase());
8535 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008536 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008537 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8538 Old->isArrow());
8539 if (Base.isInvalid())
8540 return ExprError();
8541 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008542 } else {
8543 BaseType = getDerived().TransformType(Old->getBaseType());
8544 }
John McCall129e2df2009-11-30 22:42:35 +00008545
Douglas Gregor4c9be892011-02-28 20:01:57 +00008546 NestedNameSpecifierLoc QualifierLoc;
8547 if (Old->getQualifierLoc()) {
8548 QualifierLoc
8549 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8550 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008551 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008552 }
8553
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008554 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8555
Abramo Bagnara25777432010-08-11 22:01:17 +00008556 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008557 Sema::LookupOrdinaryName);
8558
8559 // Transform all the decls.
8560 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8561 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008562 NamedDecl *InstD = static_cast<NamedDecl*>(
8563 getDerived().TransformDecl(Old->getMemberLoc(),
8564 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008565 if (!InstD) {
8566 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8567 // This can happen because of dependent hiding.
8568 if (isa<UsingShadowDecl>(*I))
8569 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008570 else {
8571 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008572 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008573 }
John McCall9f54ad42009-12-10 09:41:52 +00008574 }
John McCall129e2df2009-11-30 22:42:35 +00008575
8576 // Expand using declarations.
8577 if (isa<UsingDecl>(InstD)) {
8578 UsingDecl *UD = cast<UsingDecl>(InstD);
8579 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8580 E = UD->shadow_end(); I != E; ++I)
8581 R.addDecl(*I);
8582 continue;
8583 }
8584
8585 R.addDecl(InstD);
8586 }
8587
8588 R.resolveKind();
8589
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008590 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008591 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008592 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008593 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008594 Old->getMemberLoc(),
8595 Old->getNamingClass()));
8596 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008597 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008598
Douglas Gregor66c45152010-04-27 16:10:10 +00008599 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008601
John McCall129e2df2009-11-30 22:42:35 +00008602 TemplateArgumentListInfo TransArgs;
8603 if (Old->hasExplicitTemplateArgs()) {
8604 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8605 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008606 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8607 Old->getNumTemplateArgs(),
8608 TransArgs))
8609 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008610 }
John McCallc2233c52010-01-15 08:34:02 +00008611
8612 // FIXME: to do this check properly, we will need to preserve the
8613 // first-qualifier-in-scope here, just in case we had a dependent
8614 // base (and therefore couldn't do the check) and a
8615 // nested-name-qualifier (and therefore could do the lookup).
8616 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008617
John McCall9ae2f072010-08-23 23:25:46 +00008618 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008619 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008620 Old->getOperatorLoc(),
8621 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008622 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008623 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008624 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008625 R,
8626 (Old->hasExplicitTemplateArgs()
8627 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008628}
8629
8630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008631ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008632TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008633 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008634 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8635 if (SubExpr.isInvalid())
8636 return ExprError();
8637
8638 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008639 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008640
8641 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8642}
8643
8644template<typename Derived>
8645ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008646TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008647 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8648 if (Pattern.isInvalid())
8649 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008650
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008651 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8652 return SemaRef.Owned(E);
8653
Douglas Gregor67fd1252011-01-14 21:20:45 +00008654 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8655 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008656}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008657
8658template<typename Derived>
8659ExprResult
8660TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8661 // If E is not value-dependent, then nothing will change when we transform it.
8662 // Note: This is an instantiation-centric view.
8663 if (!E->isValueDependent())
8664 return SemaRef.Owned(E);
8665
8666 // Note: None of the implementations of TryExpandParameterPacks can ever
8667 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008668 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008669 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8670 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008671 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008672 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008674 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008675 ShouldExpand, RetainExpansion,
8676 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008677 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008678
Douglas Gregor089e8932011-10-10 18:59:29 +00008679 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008680 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008681
Douglas Gregor089e8932011-10-10 18:59:29 +00008682 NamedDecl *Pack = E->getPack();
8683 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008684 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008685 Pack));
8686 if (!Pack)
8687 return ExprError();
8688 }
8689
Chad Rosier4a9d7952012-08-08 18:46:20 +00008690
Douglas Gregoree8aff02011-01-04 17:33:58 +00008691 // We now know the length of the parameter pack, so build a new expression
8692 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008693 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8694 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008695 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008696}
8697
Douglas Gregorbe230c32011-01-03 17:17:50 +00008698template<typename Derived>
8699ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008700TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8701 SubstNonTypeTemplateParmPackExpr *E) {
8702 // Default behavior is to do nothing with this transformation.
8703 return SemaRef.Owned(E);
8704}
8705
8706template<typename Derived>
8707ExprResult
John McCall91a57552011-07-15 05:09:51 +00008708TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8709 SubstNonTypeTemplateParmExpr *E) {
8710 // Default behavior is to do nothing with this transformation.
8711 return SemaRef.Owned(E);
8712}
8713
8714template<typename Derived>
8715ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008716TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8717 // Default behavior is to do nothing with this transformation.
8718 return SemaRef.Owned(E);
8719}
8720
8721template<typename Derived>
8722ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008723TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8724 MaterializeTemporaryExpr *E) {
8725 return getDerived().TransformExpr(E->GetTemporaryExpr());
8726}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008727
Douglas Gregor03e80032011-06-21 17:03:29 +00008728template<typename Derived>
8729ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008730TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8731 CXXStdInitializerListExpr *E) {
8732 return getDerived().TransformExpr(E->getSubExpr());
8733}
8734
8735template<typename Derived>
8736ExprResult
John McCall454feb92009-12-08 09:21:05 +00008737TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008738 return SemaRef.MaybeBindToTemporary(E);
8739}
8740
8741template<typename Derived>
8742ExprResult
8743TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008744 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008745}
8746
8747template<typename Derived>
8748ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008749TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8750 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8751 if (SubExpr.isInvalid())
8752 return ExprError();
8753
8754 if (!getDerived().AlwaysRebuild() &&
8755 SubExpr.get() == E->getSubExpr())
8756 return SemaRef.Owned(E);
8757
8758 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008759}
8760
8761template<typename Derived>
8762ExprResult
8763TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8764 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008765 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008766 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008767 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008768 /*IsCall=*/false, Elements, &ArgChanged))
8769 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008770
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008771 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8772 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008773
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008774 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8775 Elements.data(),
8776 Elements.size());
8777}
8778
8779template<typename Derived>
8780ExprResult
8781TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008783 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008784 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008785 bool ArgChanged = false;
8786 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8787 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008788
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008789 if (OrigElement.isPackExpansion()) {
8790 // This key/value element is a pack expansion.
8791 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8792 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8793 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8794 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8795
8796 // Determine whether the set of unexpanded parameter packs can
8797 // and should be expanded.
8798 bool Expand = true;
8799 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008800 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8801 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008802 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8803 OrigElement.Value->getLocEnd());
8804 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8805 PatternRange,
8806 Unexpanded,
8807 Expand, RetainExpansion,
8808 NumExpansions))
8809 return ExprError();
8810
8811 if (!Expand) {
8812 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008813 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008814 // expansion.
8815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8816 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8817 if (Key.isInvalid())
8818 return ExprError();
8819
8820 if (Key.get() != OrigElement.Key)
8821 ArgChanged = true;
8822
8823 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8824 if (Value.isInvalid())
8825 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008826
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008827 if (Value.get() != OrigElement.Value)
8828 ArgChanged = true;
8829
Chad Rosier4a9d7952012-08-08 18:46:20 +00008830 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008831 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8832 };
8833 Elements.push_back(Expansion);
8834 continue;
8835 }
8836
8837 // Record right away that the argument was changed. This needs
8838 // to happen even if the array expands to nothing.
8839 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008840
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008841 // The transform has determined that we should perform an elementwise
8842 // expansion of the pattern. Do so.
8843 for (unsigned I = 0; I != *NumExpansions; ++I) {
8844 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8845 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8846 if (Key.isInvalid())
8847 return ExprError();
8848
8849 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8850 if (Value.isInvalid())
8851 return ExprError();
8852
Chad Rosier4a9d7952012-08-08 18:46:20 +00008853 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008854 Key.get(), Value.get(), SourceLocation(), NumExpansions
8855 };
8856
8857 // If any unexpanded parameter packs remain, we still have a
8858 // pack expansion.
8859 if (Key.get()->containsUnexpandedParameterPack() ||
8860 Value.get()->containsUnexpandedParameterPack())
8861 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008862
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008863 Elements.push_back(Element);
8864 }
8865
8866 // We've finished with this pack expansion.
8867 continue;
8868 }
8869
8870 // Transform and check key.
8871 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8872 if (Key.isInvalid())
8873 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008874
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008875 if (Key.get() != OrigElement.Key)
8876 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008877
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008878 // Transform and check value.
8879 ExprResult Value
8880 = getDerived().TransformExpr(OrigElement.Value);
8881 if (Value.isInvalid())
8882 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008883
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008884 if (Value.get() != OrigElement.Value)
8885 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008886
8887 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008888 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008889 };
8890 Elements.push_back(Element);
8891 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008892
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008893 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8894 return SemaRef.MaybeBindToTemporary(E);
8895
8896 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8897 Elements.data(),
8898 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008899}
8900
Mike Stump1eb44332009-09-09 15:08:12 +00008901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008902ExprResult
John McCall454feb92009-12-08 09:21:05 +00008903TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008904 TypeSourceInfo *EncodedTypeInfo
8905 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8906 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008907 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008908
Douglas Gregorb98b1992009-08-11 05:31:07 +00008909 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008910 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008911 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008912
8913 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008914 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008915 E->getRParenLoc());
8916}
Mike Stump1eb44332009-09-09 15:08:12 +00008917
Douglas Gregorb98b1992009-08-11 05:31:07 +00008918template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008919ExprResult TreeTransform<Derived>::
8920TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008921 // This is a kind of implicit conversion, and it needs to get dropped
8922 // and recomputed for the same general reasons that ImplicitCastExprs
8923 // do, as well a more specific one: this expression is only valid when
8924 // it appears *immediately* as an argument expression.
8925 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008926}
8927
8928template<typename Derived>
8929ExprResult TreeTransform<Derived>::
8930TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008932 = getDerived().TransformType(E->getTypeInfoAsWritten());
8933 if (!TSInfo)
8934 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008935
John McCallf85e1932011-06-15 23:02:42 +00008936 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008937 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008938 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008939
John McCallf85e1932011-06-15 23:02:42 +00008940 if (!getDerived().AlwaysRebuild() &&
8941 TSInfo == E->getTypeInfoAsWritten() &&
8942 Result.get() == E->getSubExpr())
8943 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008944
John McCallf85e1932011-06-15 23:02:42 +00008945 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008946 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008947 Result.get());
8948}
8949
8950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008951ExprResult
John McCall454feb92009-12-08 09:21:05 +00008952TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008953 // Transform arguments.
8954 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008955 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008956 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008957 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008958 &ArgChanged))
8959 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008960
Douglas Gregor92e986e2010-04-22 16:44:27 +00008961 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8962 // Class message: transform the receiver type.
8963 TypeSourceInfo *ReceiverTypeInfo
8964 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8965 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008966 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008967
Douglas Gregor92e986e2010-04-22 16:44:27 +00008968 // If nothing changed, just retain the existing message send.
8969 if (!getDerived().AlwaysRebuild() &&
8970 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008971 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008972
8973 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008974 SmallVector<SourceLocation, 16> SelLocs;
8975 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008976 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8977 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008978 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008979 E->getMethodDecl(),
8980 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008981 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008982 E->getRightLoc());
8983 }
8984
8985 // Instance message: transform the receiver
8986 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8987 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008988 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008989 = getDerived().TransformExpr(E->getInstanceReceiver());
8990 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008991 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008992
8993 // If nothing changed, just retain the existing message send.
8994 if (!getDerived().AlwaysRebuild() &&
8995 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008996 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008997
Douglas Gregor92e986e2010-04-22 16:44:27 +00008998 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008999 SmallVector<SourceLocation, 16> SelLocs;
9000 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009001 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009002 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009003 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009004 E->getMethodDecl(),
9005 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009006 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009007 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009008}
9009
Mike Stump1eb44332009-09-09 15:08:12 +00009010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009011ExprResult
John McCall454feb92009-12-08 09:21:05 +00009012TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009013 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009014}
9015
Mike Stump1eb44332009-09-09 15:08:12 +00009016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009017ExprResult
John McCall454feb92009-12-08 09:21:05 +00009018TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009019 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009020}
9021
Mike Stump1eb44332009-09-09 15:08:12 +00009022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009023ExprResult
John McCall454feb92009-12-08 09:21:05 +00009024TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009025 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009026 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009027 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009028 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009029
9030 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009031
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009032 // If nothing changed, just retain the existing expression.
9033 if (!getDerived().AlwaysRebuild() &&
9034 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009035 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009036
John McCall9ae2f072010-08-23 23:25:46 +00009037 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009038 E->getLocation(),
9039 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009040}
9041
Mike Stump1eb44332009-09-09 15:08:12 +00009042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009043ExprResult
John McCall454feb92009-12-08 09:21:05 +00009044TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009045 // 'super' and types never change. Property never changes. Just
9046 // retain the existing expression.
9047 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009048 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009049
Douglas Gregore3303542010-04-26 20:47:02 +00009050 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009051 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009052 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009053 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009054
Douglas Gregore3303542010-04-26 20:47:02 +00009055 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009056
Douglas Gregore3303542010-04-26 20:47:02 +00009057 // If nothing changed, just retain the existing expression.
9058 if (!getDerived().AlwaysRebuild() &&
9059 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009060 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009061
John McCall12f78a62010-12-02 01:19:52 +00009062 if (E->isExplicitProperty())
9063 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9064 E->getExplicitProperty(),
9065 E->getLocation());
9066
9067 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009068 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009069 E->getImplicitPropertyGetter(),
9070 E->getImplicitPropertySetter(),
9071 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009072}
9073
Mike Stump1eb44332009-09-09 15:08:12 +00009074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009075ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009076TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9077 // Transform the base expression.
9078 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9079 if (Base.isInvalid())
9080 return ExprError();
9081
9082 // Transform the key expression.
9083 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9084 if (Key.isInvalid())
9085 return ExprError();
9086
9087 // If nothing changed, just retain the existing expression.
9088 if (!getDerived().AlwaysRebuild() &&
9089 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9090 return SemaRef.Owned(E);
9091
Chad Rosier4a9d7952012-08-08 18:46:20 +00009092 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009093 Base.get(), Key.get(),
9094 E->getAtIndexMethodDecl(),
9095 E->setAtIndexMethodDecl());
9096}
9097
9098template<typename Derived>
9099ExprResult
John McCall454feb92009-12-08 09:21:05 +00009100TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009101 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009102 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009103 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009104 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009105
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009106 // If nothing changed, just retain the existing expression.
9107 if (!getDerived().AlwaysRebuild() &&
9108 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009109 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009110
John McCall9ae2f072010-08-23 23:25:46 +00009111 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009112 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009113 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009114}
9115
Mike Stump1eb44332009-09-09 15:08:12 +00009116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009117ExprResult
John McCall454feb92009-12-08 09:21:05 +00009118TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009119 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009120 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009121 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009122 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009123 SubExprs, &ArgumentChanged))
9124 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009125
Douglas Gregorb98b1992009-08-11 05:31:07 +00009126 if (!getDerived().AlwaysRebuild() &&
9127 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009128 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009129
Douglas Gregorb98b1992009-08-11 05:31:07 +00009130 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009131 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009132 E->getRParenLoc());
9133}
9134
Mike Stump1eb44332009-09-09 15:08:12 +00009135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009136ExprResult
John McCall454feb92009-12-08 09:21:05 +00009137TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009138 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009139
John McCallc6ac9c32011-02-04 18:33:18 +00009140 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9141 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9142
9143 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009144 blockScope->TheDecl->setBlockMissingReturnType(
9145 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009146
Chris Lattner686775d2011-07-20 06:58:45 +00009147 SmallVector<ParmVarDecl*, 4> params;
9148 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009149
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009150 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009151 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9152 oldBlock->param_begin(),
9153 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009154 0, paramTypes, &params)) {
9155 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009156 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009157 }
John McCallc6ac9c32011-02-04 18:33:18 +00009158
Jordan Rose09189892013-03-08 22:25:36 +00009159 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009160 QualType exprResultType =
9161 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009162
Jordan Rosebea522f2013-03-08 21:51:21 +00009163 QualType functionType =
9164 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009165 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009166 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009167
9168 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009169 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009170 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009171
9172 if (!oldBlock->blockMissingReturnType()) {
9173 blockScope->HasImplicitReturnType = false;
9174 blockScope->ReturnType = exprResultType;
9175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009176
John McCall711c52b2011-01-05 12:14:39 +00009177 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009178 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009179 if (body.isInvalid()) {
9180 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009181 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009182 }
John McCall711c52b2011-01-05 12:14:39 +00009183
John McCallc6ac9c32011-02-04 18:33:18 +00009184#ifndef NDEBUG
9185 // In builds with assertions, make sure that we captured everything we
9186 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009187 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9188 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9189 e = oldBlock->capture_end(); i != e; ++i) {
9190 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009191
Douglas Gregorfc921372011-05-20 15:32:55 +00009192 // Ignore parameter packs.
9193 if (isa<ParmVarDecl>(oldCapture) &&
9194 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9195 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009196
Douglas Gregorfc921372011-05-20 15:32:55 +00009197 VarDecl *newCapture =
9198 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9199 oldCapture));
9200 assert(blockScope->CaptureMap.count(newCapture));
9201 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009202 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009203 }
9204#endif
9205
9206 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9207 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009208}
9209
Mike Stump1eb44332009-09-09 15:08:12 +00009210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009211ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009212TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009213 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009214}
Eli Friedman276b0612011-10-11 02:20:01 +00009215
9216template<typename Derived>
9217ExprResult
9218TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009219 QualType RetTy = getDerived().TransformType(E->getType());
9220 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009221 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009222 SubExprs.reserve(E->getNumSubExprs());
9223 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9224 SubExprs, &ArgumentChanged))
9225 return ExprError();
9226
9227 if (!getDerived().AlwaysRebuild() &&
9228 !ArgumentChanged)
9229 return SemaRef.Owned(E);
9230
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009231 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009232 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009233}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009234
Douglas Gregorb98b1992009-08-11 05:31:07 +00009235//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009236// Type reconstruction
9237//===----------------------------------------------------------------------===//
9238
Mike Stump1eb44332009-09-09 15:08:12 +00009239template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009240QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9241 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009242 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009243 getDerived().getBaseEntity());
9244}
9245
Mike Stump1eb44332009-09-09 15:08:12 +00009246template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009247QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9248 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009249 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009250 getDerived().getBaseEntity());
9251}
9252
Mike Stump1eb44332009-09-09 15:08:12 +00009253template<typename Derived>
9254QualType
John McCall85737a72009-10-30 00:06:24 +00009255TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9256 bool WrittenAsLValue,
9257 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009258 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009259 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009260}
9261
9262template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009263QualType
John McCall85737a72009-10-30 00:06:24 +00009264TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9265 QualType ClassType,
9266 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009267 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009268 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009269}
9270
9271template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009272QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009273TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9274 ArrayType::ArraySizeModifier SizeMod,
9275 const llvm::APInt *Size,
9276 Expr *SizeExpr,
9277 unsigned IndexTypeQuals,
9278 SourceRange BracketsRange) {
9279 if (SizeExpr || !Size)
9280 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9281 IndexTypeQuals, BracketsRange,
9282 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009283
9284 QualType Types[] = {
9285 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9286 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9287 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009288 };
Craig Topperb9602322013-07-15 03:38:40 +00009289 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009290 QualType SizeType;
9291 for (unsigned I = 0; I != NumTypes; ++I)
9292 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9293 SizeType = Types[I];
9294 break;
9295 }
Mike Stump1eb44332009-09-09 15:08:12 +00009296
Eli Friedman01f276d2012-01-25 23:20:27 +00009297 // Note that we can return a VariableArrayType here in the case where
9298 // the element type was a dependent VariableArrayType.
9299 IntegerLiteral *ArraySize
9300 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9301 /*FIXME*/BracketsRange.getBegin());
9302 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009303 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009304 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009305}
Mike Stump1eb44332009-09-09 15:08:12 +00009306
Douglas Gregor577f75a2009-08-04 16:50:30 +00009307template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009308QualType
9309TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009310 ArrayType::ArraySizeModifier SizeMod,
9311 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009312 unsigned IndexTypeQuals,
9313 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009314 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009315 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009316}
9317
9318template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009319QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009320TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009321 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009322 unsigned IndexTypeQuals,
9323 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009324 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009325 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009326}
Mike Stump1eb44332009-09-09 15:08:12 +00009327
Douglas Gregor577f75a2009-08-04 16:50:30 +00009328template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009329QualType
9330TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009331 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009332 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009333 unsigned IndexTypeQuals,
9334 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009335 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009336 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009337 IndexTypeQuals, BracketsRange);
9338}
9339
9340template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009341QualType
9342TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009343 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009344 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009345 unsigned IndexTypeQuals,
9346 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009347 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009348 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009349 IndexTypeQuals, BracketsRange);
9350}
9351
9352template<typename Derived>
9353QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009354 unsigned NumElements,
9355 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009356 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009357 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009358}
Mike Stump1eb44332009-09-09 15:08:12 +00009359
Douglas Gregor577f75a2009-08-04 16:50:30 +00009360template<typename Derived>
9361QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9362 unsigned NumElements,
9363 SourceLocation AttributeLoc) {
9364 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9365 NumElements, true);
9366 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009367 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9368 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009369 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009370}
Mike Stump1eb44332009-09-09 15:08:12 +00009371
Douglas Gregor577f75a2009-08-04 16:50:30 +00009372template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009373QualType
9374TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009375 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009376 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009377 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009378}
Mike Stump1eb44332009-09-09 15:08:12 +00009379
Douglas Gregor577f75a2009-08-04 16:50:30 +00009380template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009381QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9382 QualType T,
9383 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009384 const FunctionProtoType::ExtProtoInfo &EPI) {
9385 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009386 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009387 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009388 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009389}
Mike Stump1eb44332009-09-09 15:08:12 +00009390
Douglas Gregor577f75a2009-08-04 16:50:30 +00009391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009392QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9393 return SemaRef.Context.getFunctionNoProtoType(T);
9394}
9395
9396template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009397QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9398 assert(D && "no decl found");
9399 if (D->isInvalidDecl()) return QualType();
9400
Douglas Gregor92e986e2010-04-22 16:44:27 +00009401 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009402 TypeDecl *Ty;
9403 if (isa<UsingDecl>(D)) {
9404 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009405 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009406 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9407
9408 // A valid resolved using typename decl points to exactly one type decl.
9409 assert(++Using->shadow_begin() == Using->shadow_end());
9410 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009411
John McCalled976492009-12-04 22:46:56 +00009412 } else {
9413 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9414 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9415 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9416 }
9417
9418 return SemaRef.Context.getTypeDeclType(Ty);
9419}
9420
9421template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009422QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9423 SourceLocation Loc) {
9424 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009425}
9426
9427template<typename Derived>
9428QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9429 return SemaRef.Context.getTypeOfType(Underlying);
9430}
9431
9432template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009433QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9434 SourceLocation Loc) {
9435 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009436}
9437
9438template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009439QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9440 UnaryTransformType::UTTKind UKind,
9441 SourceLocation Loc) {
9442 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9443}
9444
9445template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009446QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009447 TemplateName Template,
9448 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009449 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009450 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009451}
Mike Stump1eb44332009-09-09 15:08:12 +00009452
Douglas Gregordcee1a12009-08-06 05:28:30 +00009453template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009454QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9455 SourceLocation KWLoc) {
9456 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9457}
9458
9459template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009460TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009461TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009462 bool TemplateKW,
9463 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009464 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009465 Template);
9466}
9467
9468template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009469TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009470TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9471 const IdentifierInfo &Name,
9472 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009473 QualType ObjectType,
9474 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009475 UnqualifiedId TemplateName;
9476 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009477 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009478 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009479 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009480 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009481 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009482 /*EnteringContext=*/false,
9483 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009484 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009485}
Mike Stump1eb44332009-09-09 15:08:12 +00009486
Douglas Gregorb98b1992009-08-11 05:31:07 +00009487template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009488TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009489TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009490 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009491 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009492 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009493 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009494 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009495 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009496 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009497 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009498 Sema::TemplateTy Template;
9499 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009500 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009501 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009502 /*EnteringContext=*/false,
9503 Template);
9504 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009505}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009506
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009508ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009509TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9510 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009511 Expr *OrigCallee,
9512 Expr *First,
9513 Expr *Second) {
9514 Expr *Callee = OrigCallee->IgnoreParenCasts();
9515 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009516
Douglas Gregorb98b1992009-08-11 05:31:07 +00009517 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009518 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009519 if (!First->getType()->isOverloadableType() &&
9520 !Second->getType()->isOverloadableType())
9521 return getSema().CreateBuiltinArraySubscriptExpr(First,
9522 Callee->getLocStart(),
9523 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009524 } else if (Op == OO_Arrow) {
9525 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009526 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9527 } else if (Second == 0 || isPostIncDec) {
9528 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009529 // The argument is not of overloadable type, so try to create a
9530 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009531 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009532 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009533
John McCall9ae2f072010-08-23 23:25:46 +00009534 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009535 }
9536 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009537 if (!First->getType()->isOverloadableType() &&
9538 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009539 // Neither of the arguments is an overloadable type, so try to
9540 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009541 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009542 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009543 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009544 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009546
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009547 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009548 }
9549 }
Mike Stump1eb44332009-09-09 15:08:12 +00009550
9551 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009552 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009553 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009554
John McCall9ae2f072010-08-23 23:25:46 +00009555 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009556 assert(ULE->requiresADL());
9557
9558 // FIXME: Do we have to check
9559 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009560 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009561 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009562 // If we've resolved this to a particular non-member function, just call
9563 // that function. If we resolved it to a member function,
9564 // CreateOverloaded* will find that function for us.
9565 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9566 if (!isa<CXXMethodDecl>(ND))
9567 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009568 }
Mike Stump1eb44332009-09-09 15:08:12 +00009569
Douglas Gregorb98b1992009-08-11 05:31:07 +00009570 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009571 Expr *Args[2] = { First, Second };
9572 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009573
Douglas Gregorb98b1992009-08-11 05:31:07 +00009574 // Create the overloaded operator invocation for unary operators.
9575 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009576 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009577 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009578 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009579 }
Mike Stump1eb44332009-09-09 15:08:12 +00009580
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009581 if (Op == OO_Subscript) {
9582 SourceLocation LBrace;
9583 SourceLocation RBrace;
9584
9585 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9586 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9587 LBrace = SourceLocation::getFromRawEncoding(
9588 NameLoc.CXXOperatorName.BeginOpNameLoc);
9589 RBrace = SourceLocation::getFromRawEncoding(
9590 NameLoc.CXXOperatorName.EndOpNameLoc);
9591 } else {
9592 LBrace = Callee->getLocStart();
9593 RBrace = OpLoc;
9594 }
9595
9596 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9597 First, Second);
9598 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009599
Douglas Gregorb98b1992009-08-11 05:31:07 +00009600 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009601 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009602 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009603 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9604 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009606
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009607 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009608}
Mike Stump1eb44332009-09-09 15:08:12 +00009609
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009610template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009611ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009612TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009613 SourceLocation OperatorLoc,
9614 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009615 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009616 TypeSourceInfo *ScopeType,
9617 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009618 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009619 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009620 QualType BaseType = Base->getType();
9621 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009622 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009623 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009624 !BaseType->getAs<PointerType>()->getPointeeType()
9625 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009626 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009627 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009628 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009629 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009630 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009631 /*FIXME?*/true);
9632 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009633
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009634 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009635 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9636 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9637 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9638 NameInfo.setNamedTypeInfo(DestroyedType);
9639
Richard Smith6314db92012-05-15 06:15:11 +00009640 // The scope type is now known to be a valid nested name specifier
9641 // component. Tack it on to the end of the nested name specifier.
9642 if (ScopeType)
9643 SS.Extend(SemaRef.Context, SourceLocation(),
9644 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009645
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009646 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009647 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009648 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009649 SS, TemplateKWLoc,
9650 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009651 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009652 /*TemplateArgs*/ 0);
9653}
9654
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009655template<typename Derived>
9656StmtResult
9657TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009658 SourceLocation Loc = S->getLocStart();
9659 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9660 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9661 S->getCapturedRegionKind(), NumParams);
9662 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9663
9664 if (Body.isInvalid()) {
9665 getSema().ActOnCapturedRegionError();
9666 return StmtError();
9667 }
9668
9669 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009670}
9671
Douglas Gregor577f75a2009-08-04 16:50:30 +00009672} // end namespace clang
9673
9674#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H