blob: 0ec47b8fc19ab4b3f172dab40e2369ada6f8d3d5 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-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 Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000101
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000106
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000114
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000119
Mike Stump11289f42009-09-09 15:08:12 +0000120public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000123
Douglas Gregord6ff3322009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 }
131
John McCalldadc5752010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000134
Douglas Gregord6ff3322009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000144 ///
145 /// We must always rebuild all AST nodes when performing variadic template
146 /// pack expansion, in order to avoid violating the AST invariant that each
147 /// statement node appears at most once in its containing declaration.
148 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregord6ff3322009-08-04 16:50:30 +0000150 /// \brief Returns the location of the entity being transformed, if that
151 /// information was not available elsewhere in the AST.
152 ///
Mike Stump11289f42009-09-09 15:08:12 +0000153 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000154 /// provide an alternative implementation that provides better location
155 /// information.
156 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregord6ff3322009-08-04 16:50:30 +0000158 /// \brief Returns the name of the entity being transformed, if that
159 /// information was not available elsewhere in the AST.
160 ///
161 /// By default, returns an empty name. Subclasses can provide an alternative
162 /// implementation with a more precise name.
163 DeclarationName getBaseEntity() { return DeclarationName(); }
164
Douglas Gregora16548e2009-08-11 05:31:07 +0000165 /// \brief Sets the "base" location and entity when that
166 /// information is known based on another transformation.
167 ///
168 /// By default, the source location and entity are ignored. Subclasses can
169 /// override this function to provide a customized implementation.
170 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000171
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// \brief RAII object that temporarily sets the base location and entity
173 /// used for reporting diagnostics in types.
174 class TemporaryBase {
175 TreeTransform &Self;
176 SourceLocation OldLocation;
177 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000178
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 public:
180 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000181 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000182 OldLocation = Self.getDerived().getBaseLocation();
183 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000184
Douglas Gregora518d5b2011-01-25 17:51:48 +0000185 if (Location.isValid())
186 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000187 }
Mike Stump11289f42009-09-09 15:08:12 +0000188
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 ~TemporaryBase() {
190 Self.getDerived().setBase(OldLocation, OldEntity);
191 }
192 };
Mike Stump11289f42009-09-09 15:08:12 +0000193
194 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000195 /// transformed.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000198 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000199 /// not change. For example, template instantiation need not traverse
200 /// non-dependent types.
201 bool AlreadyTransformed(QualType T) {
202 return T.isNull();
203 }
204
Douglas Gregord196a582009-12-14 19:27:10 +0000205 /// \brief Determine whether the given call argument should be dropped, e.g.,
206 /// because it is a default argument.
207 ///
208 /// Subclasses can provide an alternative implementation of this routine to
209 /// determine which kinds of call arguments get dropped. By default,
210 /// CXXDefaultArgument nodes are dropped (prior to transformation).
211 bool DropCallArgument(Expr *E) {
212 return E->isDefaultArgument();
213 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000214
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000215 /// \brief Determine whether we should expand a pack expansion with the
216 /// given set of parameter packs into separate arguments by repeatedly
217 /// transforming the pattern.
218 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000219 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000220 /// Subclasses can override this routine to provide different behavior.
221 ///
222 /// \param EllipsisLoc The location of the ellipsis that identifies the
223 /// pack expansion.
224 ///
225 /// \param PatternRange The source range that covers the entire pattern of
226 /// the pack expansion.
227 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000228 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// pattern.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param ShouldExpand Will be set to \c true if the transformer should
232 /// expand the corresponding pack expansions into separate arguments. When
233 /// set, \c NumExpansions must also be set.
234 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000235 /// \param RetainExpansion Whether the caller should add an unexpanded
236 /// pack expansion after all of the expanded arguments. This is used
237 /// when extending explicitly-specified template argument packs per
238 /// C++0x [temp.arg.explicit]p9.
239 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000240 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000241 /// the expanded form of the corresponding pack expansion. This is both an
242 /// input and an output parameter, which can be set by the caller if the
243 /// number of expansions is known a priori (e.g., due to a prior substitution)
244 /// and will be set by the callee when the number of expansions is known.
245 /// The callee must set this value when \c ShouldExpand is \c true; it may
246 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000247 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000248 /// \returns true if an error occurred (e.g., because the parameter packs
249 /// are to be instantiated with arguments of different lengths), false
250 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 /// must be set.
252 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
253 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000254 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000255 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000257 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000258 ShouldExpand = false;
259 return false;
260 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000261
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 /// \brief "Forget" about the partially-substituted pack template argument,
263 /// when performing an instantiation that must preserve the parameter pack
264 /// use.
265 ///
266 /// This routine is meant to be overridden by the template instantiator.
267 TemplateArgument ForgetPartiallySubstitutedPack() {
268 return TemplateArgument();
269 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000270
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000271 /// \brief "Remember" the partially-substituted pack template argument
272 /// after performing an instantiation that must preserve the parameter pack
273 /// use.
274 ///
275 /// This routine is meant to be overridden by the template instantiator.
276 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000277
Douglas Gregorf3010112011-01-07 16:43:16 +0000278 /// \brief Note to the derived class when a function parameter pack is
279 /// being expanded.
280 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transforms the given type into another type.
283 ///
John McCall550e0c22009-10-21 00:40:46 +0000284 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000285 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000286 /// function. This is expensive, but we don't mind, because
287 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000288 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
290 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000291 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000292
John McCall550e0c22009-10-21 00:40:46 +0000293 /// \brief Transforms the given type-with-location into a new
294 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
John McCall550e0c22009-10-21 00:40:46 +0000296 /// By default, this routine transforms a type by delegating to the
297 /// appropriate TransformXXXType to build a new type. Subclasses
298 /// may override this function (to take over all type
299 /// transformations) or some set of the TransformXXXType functions
300 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000301 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000302
303 /// \brief Transform the given type-with-location into a new
304 /// type, collecting location information in the given builder
305 /// as necessary.
306 ///
John McCall31f82722010-11-12 08:19:04 +0000307 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000308
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000309 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000310 ///
Mike Stump11289f42009-09-09 15:08:12 +0000311 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000312 /// appropriate TransformXXXStmt function to transform a specific kind of
313 /// statement or the TransformExpr() function to transform an expression.
314 /// Subclasses may override this function to transform statements using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000318 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000320 /// \brief Transform the given statement.
321 ///
322 /// By default, this routine transforms a statement by delegating to the
323 /// appropriate TransformOMPXXXClause function to transform a specific kind
324 /// of clause. Subclasses may override this function to transform statements
325 /// using some other mechanism.
326 ///
327 /// \returns the transformed OpenMP clause.
328 OMPClause *TransformOMPClause(OMPClause *S);
329
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000330 /// \brief Transform the given attribute.
331 ///
332 /// By default, this routine transforms a statement by delegating to the
333 /// appropriate TransformXXXAttr function to transform a specific kind
334 /// of attribute. Subclasses may override this function to transform
335 /// attributed statements using some other mechanism.
336 ///
337 /// \returns the transformed attribute
338 const Attr *TransformAttr(const Attr *S);
339
340/// \brief Transform the specified attribute.
341///
342/// Subclasses should override the transformation of attributes with a pragma
343/// spelling to transform expressions stored within the attribute.
344///
345/// \returns the transformed attribute.
346#define ATTR(X)
347#define PRAGMA_SPELLING_ATTR(X) \
348 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
349#include "clang/Basic/AttrList.inc"
350
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000351 /// \brief Transform the given expression.
352 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000353 /// By default, this routine transforms an expression by delegating to the
354 /// appropriate TransformXXXExpr function to build a new expression.
355 /// Subclasses may override this function to transform expressions using some
356 /// other mechanism.
357 ///
358 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000359 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000360
Richard Smithd59b8322012-12-19 01:39:02 +0000361 /// \brief Transform the given initializer.
362 ///
363 /// By default, this routine transforms an initializer by stripping off the
364 /// semantic nodes added by initialization, then passing the result to
365 /// TransformExpr or TransformExprs.
366 ///
367 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000368 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000369
Douglas Gregora3efea12011-01-03 19:04:46 +0000370 /// \brief Transform the given list of expressions.
371 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000372 /// This routine transforms a list of expressions by invoking
373 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000374 /// support for variadic templates by expanding any pack expansions (if the
375 /// derived class permits such expansion) along the way. When pack expansions
376 /// are present, the number of outputs may not equal the number of inputs.
377 ///
378 /// \param Inputs The set of expressions to be transformed.
379 ///
380 /// \param NumInputs The number of expressions in \c Inputs.
381 ///
382 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000383 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000384 /// be.
385 ///
386 /// \param Outputs The transformed input expressions will be added to this
387 /// vector.
388 ///
389 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
390 /// due to transformation.
391 ///
392 /// \returns true if an error occurred, false otherwise.
393 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000394 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000395 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given declaration, which is referenced from a type
398 /// or expression.
399 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000400 /// By default, acts as the identity function on declarations, unless the
401 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000402 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000403 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000404 llvm::DenseMap<Decl *, Decl *>::iterator Known
405 = TransformedLocalDecls.find(D);
406 if (Known != TransformedLocalDecls.end())
407 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
409 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000410 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000411
Chad Rosier1dcde962012-08-08 18:46:20 +0000412 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// place them on the new declaration.
414 ///
415 /// By default, this operation does nothing. Subclasses may override this
416 /// behavior to transform attributes.
417 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000418
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// \brief Note that a local declaration has been transformed by this
420 /// transformer.
421 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
424 /// the transformer itself has to transform the declarations. This routine
425 /// can be overridden by a subclass that keeps track of such mappings.
426 void transformedLocalDecl(Decl *Old, Decl *New) {
427 TransformedLocalDecls[Old] = New;
428 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000429
Douglas Gregorebe10102009-08-20 07:17:43 +0000430 /// \brief Transform the definition of the given declaration.
431 ///
Mike Stump11289f42009-09-09 15:08:12 +0000432 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000433 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000434 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
435 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000436 }
Mike Stump11289f42009-09-09 15:08:12 +0000437
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000438 /// \brief Transform the given declaration, which was the first part of a
439 /// nested-name-specifier in a member access expression.
440 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000441 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000442 /// identifier in a nested-name-specifier of a member access expression, e.g.,
443 /// the \c T in \c x->T::member
444 ///
445 /// By default, invokes TransformDecl() to transform the declaration.
446 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000447 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
448 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregor14454802011-02-25 02:25:35 +0000451 /// \brief Transform the given nested-name-specifier with source-location
452 /// information.
453 ///
454 /// By default, transforms all of the types and declarations within the
455 /// nested-name-specifier. Subclasses may override this function to provide
456 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000457 NestedNameSpecifierLoc
458 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000461
Douglas Gregorf816bd72009-09-03 22:13:48 +0000462 /// \brief Transform the given declaration name.
463 ///
464 /// By default, transforms the types of conversion function, constructor,
465 /// and destructor names and then (if needed) rebuilds the declaration name.
466 /// Identifiers and selectors are returned unmodified. Sublcasses may
467 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000468 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000469 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000470
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000472 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000473 /// \param SS The nested-name-specifier that qualifies the template
474 /// name. This nested-name-specifier must already have been transformed.
475 ///
476 /// \param Name The template name to transform.
477 ///
478 /// \param NameLoc The source location of the template name.
479 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000480 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000481 /// access expression, this is the type of the object whose member template
482 /// is being referenced.
483 ///
484 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
485 /// also refers to a name within the current (lexical) scope, this is the
486 /// declaration it refers to.
487 ///
488 /// By default, transforms the template name by transforming the declarations
489 /// and nested-name-specifiers that occur within the template name.
490 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000491 TemplateName
492 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
493 SourceLocation NameLoc,
494 QualType ObjectType = QualType(),
495 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000496
Douglas Gregord6ff3322009-08-04 16:50:30 +0000497 /// \brief Transform the given template argument.
498 ///
Mike Stump11289f42009-09-09 15:08:12 +0000499 /// By default, this operation transforms the type, expression, or
500 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000501 /// new template argument from the transformed result. Subclasses may
502 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000503 ///
504 /// Returns true if there was an error.
505 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
506 TemplateArgumentLoc &Output);
507
Douglas Gregor62e06f22010-12-20 17:31:10 +0000508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
512 /// the transformed arguments to the output list.
513 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000514 /// Note that this overload of \c TransformTemplateArguments() is merely
515 /// a convenience function. Subclasses that wish to override this behavior
516 /// should override the iterator-based member template version.
517 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \param Inputs The set of template arguments to be transformed.
519 ///
520 /// \param NumInputs The number of template arguments in \p Inputs.
521 ///
522 /// \param Outputs The set of transformed template arguments output by this
523 /// routine.
524 ///
525 /// Returns true if an error occurred.
526 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
527 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000528 TemplateArgumentListInfo &Outputs) {
529 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
530 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000531
532 /// \brief Transform the given set of template arguments.
533 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000534 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000537 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000538 /// \param First An iterator to the first template argument.
539 ///
540 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
542 /// \param Outputs The set of transformed template arguments output by this
543 /// routine.
544 ///
545 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000546 template<typename InputIterator>
547 bool TransformTemplateArguments(InputIterator First,
548 InputIterator Last,
549 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000550
John McCall0ad16662009-10-29 08:12:44 +0000551 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
552 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
553 TemplateArgumentLoc &ArgLoc);
554
John McCallbcd03502009-12-07 02:54:59 +0000555 /// \brief Fakes up a TypeSourceInfo for a type.
556 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
557 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000558 getDerived().getBaseLocation());
559 }
Mike Stump11289f42009-09-09 15:08:12 +0000560
John McCall550e0c22009-10-21 00:40:46 +0000561#define ABSTRACT_TYPELOC(CLASS, PARENT)
562#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000563 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000564#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565
Richard Smith2e321552014-11-12 02:00:47 +0000566 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000567 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
568 FunctionProtoTypeLoc TL,
569 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000570 unsigned ThisTypeQuals,
571 Fn TransformExceptionSpec);
572
573 bool TransformExceptionSpec(SourceLocation Loc,
574 FunctionProtoType::ExceptionSpecInfo &ESI,
575 SmallVectorImpl<QualType> &Exceptions,
576 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000577
David Majnemerfad8f482013-10-15 09:33:02 +0000578 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000579
Chad Rosier1dcde962012-08-08 18:46:20 +0000580 QualType
John McCall31f82722010-11-12 08:19:04 +0000581 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
582 TemplateSpecializationTypeLoc TL,
583 TemplateName Template);
584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
587 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000588 TemplateName Template,
589 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000590
Nico Weberc153d242014-07-28 00:02:09 +0000591 QualType TransformDependentTemplateSpecializationType(
592 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
593 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000594
John McCall58f10c32010-03-11 09:03:00 +0000595 /// \brief Transforms the parameters of a function type into the
596 /// given vectors.
597 ///
598 /// The result vectors should be kept in sync; null entries in the
599 /// variables vector are acceptable.
600 ///
601 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000602 bool TransformFunctionTypeParams(SourceLocation Loc,
603 ParmVarDecl **Params, unsigned NumParams,
604 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000605 SmallVectorImpl<QualType> &PTypes,
606 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000607
608 /// \brief Transforms a single function-type parameter. Return null
609 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000610 ///
611 /// \param indexAdjustment - A number to add to the parameter's
612 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000613 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000614 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000615 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000616 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000617
John McCall31f82722010-11-12 08:19:04 +0000618 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000619
John McCalldadc5752010-08-24 06:29:42 +0000620 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
621 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000622
Faisal Vali2cba1332013-10-23 06:44:28 +0000623 TemplateParameterList *TransformTemplateParameterList(
624 TemplateParameterList *TPL) {
625 return TPL;
626 }
627
Richard Smithdb2630f2012-10-21 03:28:35 +0000628 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000629
Richard Smithdb2630f2012-10-21 03:28:35 +0000630 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000631 bool IsAddressOfOperand,
632 TypeSourceInfo **RecoveryTSI);
633
634 ExprResult TransformParenDependentScopeDeclRefExpr(
635 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
636 TypeSourceInfo **RecoveryTSI);
637
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000638 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000639
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000640// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
641// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000642#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000643 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000644 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000645#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000646 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000647 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000648#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000649#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000650
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000651#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000652 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000653 OMPClause *Transform ## Class(Class *S);
654#include "clang/Basic/OpenMPKinds.def"
655
Douglas Gregord6ff3322009-08-04 16:50:30 +0000656 /// \brief Build a new pointer type given its pointee type.
657 ///
658 /// By default, performs semantic analysis when building the pointer type.
659 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000660 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661
662 /// \brief Build a new block pointer type given its pointee type.
663 ///
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000666 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
John McCall70dd5f62009-10-30 00:06:24 +0000668 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
John McCall70dd5f62009-10-30 00:06:24 +0000670 /// By default, performs semantic analysis when building the
671 /// reference type. Subclasses may override this routine to provide
672 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
John McCall70dd5f62009-10-30 00:06:24 +0000674 /// \param LValue whether the type was written with an lvalue sigil
675 /// or an rvalue sigil.
676 QualType RebuildReferenceType(QualType ReferentType,
677 bool LValue,
678 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000679
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 /// \brief Build a new member pointer type given the pointee type and the
681 /// class type it refers into.
682 ///
683 /// By default, performs semantic analysis when building the member pointer
684 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000685 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
686 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000688 /// \brief Build an Objective-C object type.
689 ///
690 /// By default, performs semantic analysis when building the object type.
691 /// Subclasses may override this routine to provide different behavior.
692 QualType RebuildObjCObjectType(QualType BaseType,
693 SourceLocation Loc,
694 SourceLocation TypeArgsLAngleLoc,
695 ArrayRef<TypeSourceInfo *> TypeArgs,
696 SourceLocation TypeArgsRAngleLoc,
697 SourceLocation ProtocolLAngleLoc,
698 ArrayRef<ObjCProtocolDecl *> Protocols,
699 ArrayRef<SourceLocation> ProtocolLocs,
700 SourceLocation ProtocolRAngleLoc);
701
702 /// \brief Build a new Objective-C object pointer type given the pointee type.
703 ///
704 /// By default, directly builds the pointer type, with no additional semantic
705 /// analysis.
706 QualType RebuildObjCObjectPointerType(QualType PointeeType,
707 SourceLocation Star);
708
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 /// \brief Build a new array type given the element type, size
710 /// modifier, size of the array (if known), size expression, and index type
711 /// qualifiers.
712 ///
713 /// By default, performs semantic analysis when building the array type.
714 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000715 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000716 QualType RebuildArrayType(QualType ElementType,
717 ArrayType::ArraySizeModifier SizeMod,
718 const llvm::APInt *Size,
719 Expr *SizeExpr,
720 unsigned IndexTypeQuals,
721 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new constant array type given the element type, size
724 /// modifier, (known) size of the array, and index type qualifiers.
725 ///
726 /// By default, performs semantic analysis when building the array type.
727 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000728 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 ArrayType::ArraySizeModifier SizeMod,
730 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000731 unsigned IndexTypeQuals,
732 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000733
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 /// \brief Build a new incomplete array type given the element type, size
735 /// modifier, and index type qualifiers.
736 ///
737 /// By default, performs semantic analysis when building the array type.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000741 unsigned IndexTypeQuals,
742 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743
Mike Stump11289f42009-09-09 15:08:12 +0000744 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 /// size modifier, size expression, and index type qualifiers.
746 ///
747 /// By default, performs semantic analysis when building the array type.
748 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000749 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000751 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000752 unsigned IndexTypeQuals,
753 SourceRange BracketsRange);
754
Mike Stump11289f42009-09-09 15:08:12 +0000755 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// size modifier, size expression, and index type qualifiers.
757 ///
758 /// By default, performs semantic analysis when building the array type.
759 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000760 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000762 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 unsigned IndexTypeQuals,
764 SourceRange BracketsRange);
765
766 /// \brief Build a new vector type given the element type and
767 /// number of elements.
768 ///
769 /// By default, performs semantic analysis when building the vector type.
770 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000771 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000772 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000773
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 /// \brief Build a new extended vector type given the element type and
775 /// number of elements.
776 ///
777 /// By default, performs semantic analysis when building the vector type.
778 /// Subclasses may override this routine to provide different behavior.
779 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
780 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000781
782 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 /// given the element type and number of elements.
784 ///
785 /// By default, performs semantic analysis when building the vector type.
786 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000787 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000788 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000790
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// \brief Build a new function type.
792 ///
793 /// By default, performs semantic analysis when building the function type.
794 /// Subclasses may override this routine to provide different behavior.
795 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000796 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000797 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000798
John McCall550e0c22009-10-21 00:40:46 +0000799 /// \brief Build a new unprototyped function type.
800 QualType RebuildFunctionNoProtoType(QualType ResultType);
801
John McCallb96ec562009-12-04 22:46:56 +0000802 /// \brief Rebuild an unresolved typename type, given the decl that
803 /// the UnresolvedUsingTypenameDecl was transformed to.
804 QualType RebuildUnresolvedUsingType(Decl *D);
805
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000807 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 return SemaRef.Context.getTypeDeclType(Typedef);
809 }
810
811 /// \brief Build a new class/struct/union type.
812 QualType RebuildRecordType(RecordDecl *Record) {
813 return SemaRef.Context.getTypeDeclType(Record);
814 }
815
816 /// \brief Build a new Enum type.
817 QualType RebuildEnumType(EnumDecl *Enum) {
818 return SemaRef.Context.getTypeDeclType(Enum);
819 }
John McCallfcc33b02009-09-05 00:15:47 +0000820
Mike Stump11289f42009-09-09 15:08:12 +0000821 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 ///
823 /// By default, performs semantic analysis when building the typeof type.
824 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000825 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000826
Mike Stump11289f42009-09-09 15:08:12 +0000827 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 ///
829 /// By default, builds a new TypeOfType with the given underlying type.
830 QualType RebuildTypeOfType(QualType Underlying);
831
Alexis Hunte852b102011-05-24 22:41:36 +0000832 /// \brief Build a new unary transform type.
833 QualType RebuildUnaryTransformType(QualType BaseType,
834 UnaryTransformType::UTTKind UKind,
835 SourceLocation Loc);
836
Richard Smith74aeef52013-04-26 16:15:35 +0000837 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 ///
839 /// By default, performs semantic analysis when building the decltype type.
840 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000841 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000842
Richard Smith74aeef52013-04-26 16:15:35 +0000843 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000844 ///
845 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000846 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000847 // Note, IsDependent is always false here: we implicitly convert an 'auto'
848 // which has been deduced to a dependent type into an undeduced 'auto', so
849 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000850 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
851 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000852 }
853
Douglas Gregord6ff3322009-08-04 16:50:30 +0000854 /// \brief Build a new template specialization type.
855 ///
856 /// By default, performs semantic analysis when building the template
857 /// specialization type. Subclasses may override this routine to provide
858 /// different behavior.
859 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000860 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000861 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000863 /// \brief Build a new parenthesized type.
864 ///
865 /// By default, builds a new ParenType type from the inner type.
866 /// Subclasses may override this routine to provide different behavior.
867 QualType RebuildParenType(QualType InnerType) {
868 return SemaRef.Context.getParenType(InnerType);
869 }
870
Douglas Gregord6ff3322009-08-04 16:50:30 +0000871 /// \brief Build a new qualified name type.
872 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000873 /// By default, builds a new ElaboratedType type from the keyword,
874 /// the nested-name-specifier and the named type.
875 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000876 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
877 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000878 NestedNameSpecifierLoc QualifierLoc,
879 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000882 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000883 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884
885 /// \brief Build a new typename type that refers to a template-id.
886 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000887 /// By default, builds a new DependentNameType type from the
888 /// nested-name-specifier and the given type. Subclasses may override
889 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000890 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000891 ElaboratedTypeKeyword Keyword,
892 NestedNameSpecifierLoc QualifierLoc,
893 const IdentifierInfo *Name,
894 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000895 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 // Rebuild the template name.
897 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000898 CXXScopeSpec SS;
899 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000901 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
902 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000903
Douglas Gregora7a795b2011-03-01 20:11:18 +0000904 if (InstName.isNull())
905 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000906
Douglas Gregora7a795b2011-03-01 20:11:18 +0000907 // If it's still dependent, make a dependent specialization.
908 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000909 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
910 QualifierLoc.getNestedNameSpecifier(),
911 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000913
Douglas Gregora7a795b2011-03-01 20:11:18 +0000914 // Otherwise, make an elaborated type wrapping a non-dependent
915 // specialization.
916 QualType T =
917 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
918 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000919
Craig Topperc3ec1492014-05-26 06:22:03 +0000920 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000921 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000922
923 return SemaRef.Context.getElaboratedType(Keyword,
924 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000925 T);
926 }
927
Douglas Gregord6ff3322009-08-04 16:50:30 +0000928 /// \brief Build a new typename type that refers to an identifier.
929 ///
930 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000931 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000932 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000933 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000935 NestedNameSpecifierLoc QualifierLoc,
936 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000937 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000938 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000939 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000940
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000941 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000942 // If the name is still dependent, just build a new dependent name type.
943 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000944 return SemaRef.Context.getDependentNameType(Keyword,
945 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 }
948
Abramo Bagnara6150c882010-05-11 21:36:43 +0000949 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000950 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000951 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000952
953 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
954
Abramo Bagnarad7548482010-05-19 21:37:53 +0000955 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000956 // into a non-dependent elaborated-type-specifier. Find the tag we're
957 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000958 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000959 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
960 if (!DC)
961 return QualType();
962
John McCallbf8c5192010-05-27 06:40:31 +0000963 if (SemaRef.RequireCompleteDeclContext(SS, DC))
964 return QualType();
965
Craig Topperc3ec1492014-05-26 06:22:03 +0000966 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000967 SemaRef.LookupQualifiedName(Result, DC);
968 switch (Result.getResultKind()) {
969 case LookupResult::NotFound:
970 case LookupResult::NotFoundInCurrentInstantiation:
971 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000972
Douglas Gregore677daf2010-03-31 22:19:08 +0000973 case LookupResult::Found:
974 Tag = Result.getAsSingle<TagDecl>();
975 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000976
Douglas Gregore677daf2010-03-31 22:19:08 +0000977 case LookupResult::FoundOverloaded:
978 case LookupResult::FoundUnresolvedValue:
979 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000980
Douglas Gregore677daf2010-03-31 22:19:08 +0000981 case LookupResult::Ambiguous:
982 // Let the LookupResult structure handle ambiguities.
983 return QualType();
984 }
985
986 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000987 // Check where the name exists but isn't a tag type and use that to emit
988 // better diagnostics.
989 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
990 SemaRef.LookupQualifiedName(Result, DC);
991 switch (Result.getResultKind()) {
992 case LookupResult::Found:
993 case LookupResult::FoundOverloaded:
994 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000995 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000996 unsigned Kind = 0;
997 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000998 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
999 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001000 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1001 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1002 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001003 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001004 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001006 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 break;
1008 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001009 return QualType();
1010 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001011
Richard Trieucaa33d32011-06-10 03:11:26 +00001012 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001013 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001014 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001015 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1016 return QualType();
1017 }
1018
1019 // Build the elaborated-type-specifier type.
1020 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001021 return SemaRef.Context.getElaboratedType(Keyword,
1022 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001023 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001024 }
Mike Stump11289f42009-09-09 15:08:12 +00001025
Douglas Gregor822d0302011-01-12 17:07:58 +00001026 /// \brief Build a new pack expansion type.
1027 ///
1028 /// By default, builds a new PackExpansionType type from the given pattern.
1029 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001030 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001032 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001033 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001034 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1035 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 }
1037
Eli Friedman0dfb8892011-10-06 23:00:33 +00001038 /// \brief Build a new atomic type given its value type.
1039 ///
1040 /// By default, performs semantic analysis when building the atomic type.
1041 /// Subclasses may override this routine to provide different behavior.
1042 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1043
Douglas Gregor71dc5092009-08-06 06:41:21 +00001044 /// \brief Build a new template name given a nested name specifier, a flag
1045 /// indicating whether the "template" keyword was provided, and the template
1046 /// that the template name refers to.
1047 ///
1048 /// By default, builds the new template name directly. Subclasses may override
1049 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001050 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001051 bool TemplateKW,
1052 TemplateDecl *Template);
1053
Douglas Gregor71dc5092009-08-06 06:41:21 +00001054 /// \brief Build a new template name given a nested name specifier and the
1055 /// name that is referred to as a template.
1056 ///
1057 /// By default, performs semantic analysis to determine whether the name can
1058 /// be resolved to a specific template, then builds the appropriate kind of
1059 /// template name. Subclasses may override this routine to provide different
1060 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001061 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1062 const IdentifierInfo &Name,
1063 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001064 QualType ObjectType,
1065 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregor71395fa2009-11-04 00:56:37 +00001067 /// \brief Build a new template name given a nested name specifier and the
1068 /// overloaded operator name that is referred to as a template.
1069 ///
1070 /// By default, performs semantic analysis to determine whether the name can
1071 /// be resolved to a specific template, then builds the appropriate kind of
1072 /// template name. Subclasses may override this routine to provide different
1073 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001074 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001075 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001076 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001077 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001078
1079 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001080 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001081 ///
1082 /// By default, performs semantic analysis to determine whether the name can
1083 /// be resolved to a specific template, then builds the appropriate kind of
1084 /// template name. Subclasses may override this routine to provide different
1085 /// behavior.
1086 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1087 const TemplateArgument &ArgPack) {
1088 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1089 }
1090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Build a new compound statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001095 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 MultiStmtArg Statements,
1097 SourceLocation RBraceLoc,
1098 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001099 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001100 IsStmtExpr);
1101 }
1102
1103 /// \brief Build a new case statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001107 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001108 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001109 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001111 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001112 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 ColonLoc);
1114 }
Mike Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 /// \brief Attach the body to a new case statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001121 getSema().ActOnCaseStmtBody(S, Body);
1122 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregorebe10102009-08-20 07:17:43 +00001125 /// \brief Build a new default statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001131 Stmt *SubStmt) {
1132 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001133 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregorebe10102009-08-20 07:17:43 +00001136 /// \brief Build a new label statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001140 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1141 SourceLocation ColonLoc, Stmt *SubStmt) {
1142 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Richard Smithc202b282012-04-14 00:33:13 +00001145 /// \brief Build a new label statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001149 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1150 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001151 Stmt *SubStmt) {
1152 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1153 }
1154
Douglas Gregorebe10102009-08-20 07:17:43 +00001155 /// \brief Build a new "if" statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001159 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001160 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001161 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001162 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 /// \brief Start building a new switch statement.
1166 ///
1167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001169 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001170 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001171 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001172 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregorebe10102009-08-20 07:17:43 +00001175 /// \brief Attach the body to the switch statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001180 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001181 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001182 }
1183
1184 /// \brief Build a new while statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001188 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1189 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001190 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new do-while statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001198 SourceLocation WhileLoc, SourceLocation LParenLoc,
1199 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001200 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1201 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new for statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001208 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001209 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001210 VarDecl *CondVar, Sema::FullExprArg Inc,
1211 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001212 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 }
Mike Stump11289f42009-09-09 15:08:12 +00001215
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 /// \brief Build a new goto statement.
1217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001220 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1221 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001222 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
1224
1225 /// \brief Build a new indirect goto statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001230 SourceLocation StarLoc,
1231 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001232 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 /// \brief Build a new return statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001239 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001240 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Build a new declaration statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001247 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001248 SourceLocation StartLoc, SourceLocation EndLoc) {
1249 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001250 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Anders Carlssonaaeef072010-01-24 05:50:09 +00001253 /// \brief Build a new inline asm statement.
1254 ///
1255 /// By default, performs semantic analysis to build the new statement.
1256 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001257 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1258 bool IsVolatile, unsigned NumOutputs,
1259 unsigned NumInputs, IdentifierInfo **Names,
1260 MultiExprArg Constraints, MultiExprArg Exprs,
1261 Expr *AsmString, MultiExprArg Clobbers,
1262 SourceLocation RParenLoc) {
1263 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1264 NumInputs, Names, Constraints, Exprs,
1265 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001266 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001267
Chad Rosier32503022012-06-11 20:47:18 +00001268 /// \brief Build a new MS style inline asm statement.
1269 ///
1270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001272 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001273 ArrayRef<Token> AsmToks,
1274 StringRef AsmString,
1275 unsigned NumOutputs, unsigned NumInputs,
1276 ArrayRef<StringRef> Constraints,
1277 ArrayRef<StringRef> Clobbers,
1278 ArrayRef<Expr*> Exprs,
1279 SourceLocation EndLoc) {
1280 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1281 NumOutputs, NumInputs,
1282 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001283 }
1284
James Dennett2a4d13c2012-06-15 07:13:21 +00001285 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001286 ///
1287 /// By default, performs semantic analysis to build the new statement.
1288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001289 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001290 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001291 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001292 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001293 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001294 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001295 }
1296
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001297 /// \brief Rebuild an Objective-C exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new declaration.
1300 /// Subclasses may override this routine to provide different behavior.
1301 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1302 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001303 return getSema().BuildObjCExceptionDecl(TInfo, T,
1304 ExceptionDecl->getInnerLocStart(),
1305 ExceptionDecl->getLocation(),
1306 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001308
James Dennett2a4d13c2012-06-15 07:13:21 +00001309 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001313 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001314 SourceLocation RParenLoc,
1315 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001316 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001317 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001318 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001320
James Dennett2a4d13c2012-06-15 07:13:21 +00001321 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001326 Stmt *Body) {
1327 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001329
James Dennett2a4d13c2012-06-15 07:13:21 +00001330 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001334 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Expr *Operand) {
1336 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001338
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001339 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001340 ///
1341 /// By default, performs semantic analysis to build the new statement.
1342 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001343 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001344 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001345 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001346 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001347 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001348 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001349 return getSema().ActOnOpenMPExecutableDirective(
1350 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001351 }
1352
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001353 /// \brief Build a new OpenMP 'if' clause.
1354 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001355 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001356 /// Subclasses may override this routine to provide different behavior.
1357 OMPClause *RebuildOMPIfClause(Expr *Condition,
1358 SourceLocation StartLoc,
1359 SourceLocation LParenLoc,
1360 SourceLocation EndLoc) {
1361 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1362 LParenLoc, EndLoc);
1363 }
1364
Alexey Bataev3778b602014-07-17 07:32:53 +00001365 /// \brief Build a new OpenMP 'final' clause.
1366 ///
1367 /// By default, performs semantic analysis to build the new OpenMP clause.
1368 /// Subclasses may override this routine to provide different behavior.
1369 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1370 SourceLocation LParenLoc,
1371 SourceLocation EndLoc) {
1372 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1373 EndLoc);
1374 }
1375
Alexey Bataev568a8332014-03-06 06:15:19 +00001376 /// \brief Build a new OpenMP 'num_threads' clause.
1377 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001378 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001379 /// Subclasses may override this routine to provide different behavior.
1380 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1381 SourceLocation StartLoc,
1382 SourceLocation LParenLoc,
1383 SourceLocation EndLoc) {
1384 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1385 LParenLoc, EndLoc);
1386 }
1387
Alexey Bataev62c87d22014-03-21 04:51:18 +00001388 /// \brief Build a new OpenMP 'safelen' clause.
1389 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001390 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001391 /// Subclasses may override this routine to provide different behavior.
1392 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1393 SourceLocation LParenLoc,
1394 SourceLocation EndLoc) {
1395 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1396 }
1397
Alexander Musman8bd31e62014-05-27 15:12:19 +00001398 /// \brief Build a new OpenMP 'collapse' clause.
1399 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001400 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001401 /// Subclasses may override this routine to provide different behavior.
1402 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1403 SourceLocation LParenLoc,
1404 SourceLocation EndLoc) {
1405 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1406 EndLoc);
1407 }
1408
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409 /// \brief Build a new OpenMP 'default' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1414 SourceLocation KindKwLoc,
1415 SourceLocation StartLoc,
1416 SourceLocation LParenLoc,
1417 SourceLocation EndLoc) {
1418 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1419 StartLoc, LParenLoc, EndLoc);
1420 }
1421
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001422 /// \brief Build a new OpenMP 'proc_bind' clause.
1423 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001424 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001425 /// Subclasses may override this routine to provide different behavior.
1426 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1427 SourceLocation KindKwLoc,
1428 SourceLocation StartLoc,
1429 SourceLocation LParenLoc,
1430 SourceLocation EndLoc) {
1431 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1432 StartLoc, LParenLoc, EndLoc);
1433 }
1434
Alexey Bataev56dafe82014-06-20 07:16:17 +00001435 /// \brief Build a new OpenMP 'schedule' clause.
1436 ///
1437 /// By default, performs semantic analysis to build the new OpenMP clause.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1440 Expr *ChunkSize,
1441 SourceLocation StartLoc,
1442 SourceLocation LParenLoc,
1443 SourceLocation KindLoc,
1444 SourceLocation CommaLoc,
1445 SourceLocation EndLoc) {
1446 return getSema().ActOnOpenMPScheduleClause(
1447 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1448 }
1449
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001450 /// \brief Build a new OpenMP 'private' clause.
1451 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001452 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001453 /// Subclasses may override this routine to provide different behavior.
1454 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1455 SourceLocation StartLoc,
1456 SourceLocation LParenLoc,
1457 SourceLocation EndLoc) {
1458 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1459 EndLoc);
1460 }
1461
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001462 /// \brief Build a new OpenMP 'firstprivate' clause.
1463 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001464 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001465 /// Subclasses may override this routine to provide different behavior.
1466 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1467 SourceLocation StartLoc,
1468 SourceLocation LParenLoc,
1469 SourceLocation EndLoc) {
1470 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1471 EndLoc);
1472 }
1473
Alexander Musman1bb328c2014-06-04 13:06:39 +00001474 /// \brief Build a new OpenMP 'lastprivate' clause.
1475 ///
1476 /// By default, performs semantic analysis to build the new OpenMP clause.
1477 /// Subclasses may override this routine to provide different behavior.
1478 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1479 SourceLocation StartLoc,
1480 SourceLocation LParenLoc,
1481 SourceLocation EndLoc) {
1482 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1483 EndLoc);
1484 }
1485
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001486 /// \brief Build a new OpenMP 'shared' clause.
1487 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001488 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001489 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001490 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1491 SourceLocation StartLoc,
1492 SourceLocation LParenLoc,
1493 SourceLocation EndLoc) {
1494 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1495 EndLoc);
1496 }
1497
Alexey Bataevc5e02582014-06-16 07:08:35 +00001498 /// \brief Build a new OpenMP 'reduction' clause.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1502 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1503 SourceLocation StartLoc,
1504 SourceLocation LParenLoc,
1505 SourceLocation ColonLoc,
1506 SourceLocation EndLoc,
1507 CXXScopeSpec &ReductionIdScopeSpec,
1508 const DeclarationNameInfo &ReductionId) {
1509 return getSema().ActOnOpenMPReductionClause(
1510 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1511 ReductionId);
1512 }
1513
Alexander Musman8dba6642014-04-22 13:09:42 +00001514 /// \brief Build a new OpenMP 'linear' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001517 /// Subclasses may override this routine to provide different behavior.
1518 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation ColonLoc,
1522 SourceLocation EndLoc) {
1523 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1524 ColonLoc, EndLoc);
1525 }
1526
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001527 /// \brief Build a new OpenMP 'aligned' clause.
1528 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001529 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001530 /// Subclasses may override this routine to provide different behavior.
1531 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1532 SourceLocation StartLoc,
1533 SourceLocation LParenLoc,
1534 SourceLocation ColonLoc,
1535 SourceLocation EndLoc) {
1536 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1537 LParenLoc, ColonLoc, EndLoc);
1538 }
1539
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001540 /// \brief Build a new OpenMP 'copyin' clause.
1541 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001542 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1549 EndLoc);
1550 }
1551
Alexey Bataevbae9a792014-06-27 10:37:06 +00001552 /// \brief Build a new OpenMP 'copyprivate' clause.
1553 ///
1554 /// By default, performs semantic analysis to build the new OpenMP clause.
1555 /// Subclasses may override this routine to provide different behavior.
1556 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1561 EndLoc);
1562 }
1563
Alexey Bataev6125da92014-07-21 11:26:11 +00001564 /// \brief Build a new OpenMP 'flush' pseudo clause.
1565 ///
1566 /// By default, performs semantic analysis to build the new OpenMP clause.
1567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1569 SourceLocation StartLoc,
1570 SourceLocation LParenLoc,
1571 SourceLocation EndLoc) {
1572 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1573 EndLoc);
1574 }
1575
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001576 /// \brief Build a new OpenMP 'depend' pseudo clause.
1577 ///
1578 /// By default, performs semantic analysis to build the new OpenMP clause.
1579 /// Subclasses may override this routine to provide different behavior.
1580 OMPClause *
1581 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1582 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1583 SourceLocation StartLoc, SourceLocation LParenLoc,
1584 SourceLocation EndLoc) {
1585 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1586 StartLoc, LParenLoc, EndLoc);
1587 }
1588
James Dennett2a4d13c2012-06-15 07:13:21 +00001589 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001590 ///
1591 /// By default, performs semantic analysis to build the new statement.
1592 /// Subclasses may override this routine to provide different behavior.
1593 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1594 Expr *object) {
1595 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1596 }
1597
James Dennett2a4d13c2012-06-15 07:13:21 +00001598 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001599 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001600 /// By default, performs semantic analysis to build the new statement.
1601 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001602 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001603 Expr *Object, Stmt *Body) {
1604 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001605 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001606
James Dennett2a4d13c2012-06-15 07:13:21 +00001607 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001608 ///
1609 /// By default, performs semantic analysis to build the new statement.
1610 /// Subclasses may override this routine to provide different behavior.
1611 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1612 Stmt *Body) {
1613 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1614 }
John McCall53848232011-07-27 01:07:15 +00001615
Douglas Gregorf68a5082010-04-22 23:10:45 +00001616 /// \brief Build a new Objective-C fast enumeration statement.
1617 ///
1618 /// By default, performs semantic analysis to build the new statement.
1619 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001620 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001621 Stmt *Element,
1622 Expr *Collection,
1623 SourceLocation RParenLoc,
1624 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001625 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001626 Element,
John McCallb268a282010-08-23 23:25:46 +00001627 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001628 RParenLoc);
1629 if (ForEachStmt.isInvalid())
1630 return StmtError();
1631
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001632 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001634
Douglas Gregorebe10102009-08-20 07:17:43 +00001635 /// \brief Build a new C++ exception declaration.
1636 ///
1637 /// By default, performs semantic analysis to build the new decaration.
1638 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001639 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001640 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001641 SourceLocation StartLoc,
1642 SourceLocation IdLoc,
1643 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001644 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001645 StartLoc, IdLoc, Id);
1646 if (Var)
1647 getSema().CurContext->addDecl(Var);
1648 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001649 }
1650
1651 /// \brief Build a new C++ catch statement.
1652 ///
1653 /// By default, performs semantic analysis to build the new statement.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001656 VarDecl *ExceptionDecl,
1657 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001658 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1659 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001660 }
Mike Stump11289f42009-09-09 15:08:12 +00001661
Douglas Gregorebe10102009-08-20 07:17:43 +00001662 /// \brief Build a new C++ try statement.
1663 ///
1664 /// By default, performs semantic analysis to build the new statement.
1665 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001666 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1667 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001668 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001669 }
Mike Stump11289f42009-09-09 15:08:12 +00001670
Richard Smith02e85f32011-04-14 22:09:26 +00001671 /// \brief Build a new C++0x range-based for statement.
1672 ///
1673 /// By default, performs semantic analysis to build the new statement.
1674 /// Subclasses may override this routine to provide different behavior.
1675 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1676 SourceLocation ColonLoc,
1677 Stmt *Range, Stmt *BeginEnd,
1678 Expr *Cond, Expr *Inc,
1679 Stmt *LoopVar,
1680 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001681 // If we've just learned that the range is actually an Objective-C
1682 // collection, treat this as an Objective-C fast enumeration loop.
1683 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1684 if (RangeStmt->isSingleDecl()) {
1685 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001686 if (RangeVar->isInvalidDecl())
1687 return StmtError();
1688
Douglas Gregorf7106af2013-04-08 18:40:13 +00001689 Expr *RangeExpr = RangeVar->getInit();
1690 if (!RangeExpr->isTypeDependent() &&
1691 RangeExpr->getType()->isObjCObjectPointerType())
1692 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1693 RParenLoc);
1694 }
1695 }
1696 }
1697
Richard Smith02e85f32011-04-14 22:09:26 +00001698 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001699 Cond, Inc, LoopVar, RParenLoc,
1700 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001701 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001702
1703 /// \brief Build a new C++0x range-based for statement.
1704 ///
1705 /// By default, performs semantic analysis to build the new statement.
1706 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001707 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001708 bool IsIfExists,
1709 NestedNameSpecifierLoc QualifierLoc,
1710 DeclarationNameInfo NameInfo,
1711 Stmt *Nested) {
1712 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1713 QualifierLoc, NameInfo, Nested);
1714 }
1715
Richard Smith02e85f32011-04-14 22:09:26 +00001716 /// \brief Attach body to a C++0x range-based for statement.
1717 ///
1718 /// By default, performs semantic analysis to finish the new statement.
1719 /// Subclasses may override this routine to provide different behavior.
1720 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1721 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001723
David Majnemerfad8f482013-10-15 09:33:02 +00001724 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001725 Stmt *TryBlock, Stmt *Handler) {
1726 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001727 }
1728
David Majnemerfad8f482013-10-15 09:33:02 +00001729 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001730 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001731 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001732 }
1733
David Majnemerfad8f482013-10-15 09:33:02 +00001734 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001735 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001736 }
1737
Alexey Bataevec474782014-10-09 08:45:04 +00001738 /// \brief Build a new predefined expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
1742 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1743 PredefinedExpr::IdentType IT) {
1744 return getSema().BuildPredefinedExpr(Loc, IT);
1745 }
1746
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 /// \brief Build a new expression that references a declaration.
1748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001751 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001752 LookupResult &R,
1753 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001754 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1755 }
1756
1757
1758 /// \brief Build a new expression that references a declaration.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001762 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001763 ValueDecl *VD,
1764 const DeclarationNameInfo &NameInfo,
1765 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001766 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001767 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001768
1769 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001770
1771 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 }
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001775 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +00001778 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001780 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 }
1782
Douglas Gregorad8a3362009-09-04 17:36:40 +00001783 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001784 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001785 /// By default, performs semantic analysis to build the new expression.
1786 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001787 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001788 SourceLocation OperatorLoc,
1789 bool isArrow,
1790 CXXScopeSpec &SS,
1791 TypeSourceInfo *ScopeType,
1792 SourceLocation CCLoc,
1793 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001794 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001795
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001797 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001800 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001801 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001802 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001803 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 }
Mike Stump11289f42009-09-09 15:08:12 +00001805
Douglas Gregor882211c2010-04-28 22:16:22 +00001806 /// \brief Build a new builtin offsetof expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001810 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001811 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001812 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001813 unsigned NumComponents,
1814 SourceLocation RParenLoc) {
1815 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1816 NumComponents, RParenLoc);
1817 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001818
1819 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001820 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001824 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1825 SourceLocation OpLoc,
1826 UnaryExprOrTypeTrait ExprKind,
1827 SourceRange R) {
1828 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 }
1830
Peter Collingbournee190dee2011-03-11 19:24:49 +00001831 /// \brief Build a new sizeof, alignof or vec step expression with an
1832 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001833 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001836 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1837 UnaryExprOrTypeTrait ExprKind,
1838 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001840 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001843
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001844 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 }
Mike Stump11289f42009-09-09 15:08:12 +00001846
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001848 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 /// By default, performs semantic analysis to build the new expression.
1850 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001851 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001853 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001855 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001856 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 RBracketLoc);
1858 }
1859
1860 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001861 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001864 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001866 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001867 Expr *ExecConfig = nullptr) {
1868 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001869 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 }
1871
1872 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001873 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001877 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001878 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001879 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001880 const DeclarationNameInfo &MemberNameInfo,
1881 ValueDecl *Member,
1882 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001883 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001884 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001885 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1886 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001887 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001888 // We have a reference to an unnamed field. This is always the
1889 // base of an anonymous struct/union member access, i.e. the
1890 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001891 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001892 assert(Member->getType()->isRecordType() &&
1893 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001894
Richard Smithcab9a7d2011-10-26 19:06:56 +00001895 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001896 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001897 QualifierLoc.getNestedNameSpecifier(),
1898 FoundDecl, Member);
1899 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001900 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001901 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001902 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001903 MemberExpr *ME = new (getSema().Context)
1904 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1905 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001906 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001907 }
Mike Stump11289f42009-09-09 15:08:12 +00001908
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001909 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001910 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001911
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001912 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001913 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001914
John McCall16df1e52010-03-30 21:47:33 +00001915 // FIXME: this involves duplicating earlier analysis in a lot of
1916 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001917 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001918 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001919 R.resolveKind();
1920
John McCallb268a282010-08-23 23:25:46 +00001921 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001922 SS, TemplateKWLoc,
1923 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001924 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
Mike Stump11289f42009-09-09 15:08:12 +00001926
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001932 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001933 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001934 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 }
1936
1937 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001938 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001941 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001942 SourceLocation QuestionLoc,
1943 Expr *LHS,
1944 SourceLocation ColonLoc,
1945 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001946 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1947 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 }
1949
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001951 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001955 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001957 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001958 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001959 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 }
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001963 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 /// By default, performs semantic analysis to build the new expression.
1965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001966 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001967 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001969 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001970 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001971 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 }
Mike Stump11289f42009-09-09 15:08:12 +00001973
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001975 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 SourceLocation OpLoc,
1980 SourceLocation AccessorLoc,
1981 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001982
John McCall10eae182009-11-30 22:42:35 +00001983 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001984 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001985 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001986 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001987 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00001988 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001989 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00001990 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001998 MultiExprArg Inits,
1999 SourceLocation RBraceLoc,
2000 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002002 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002003 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002004 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002005
Douglas Gregord3d93062009-11-09 17:16:50 +00002006 // Patch in the result type we were given, which may have been computed
2007 // when the initial InitListExpr was built.
2008 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2009 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002010 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 }
Mike Stump11289f42009-09-09 15:08:12 +00002012
Douglas Gregora16548e2009-08-11 05:31:07 +00002013 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002014 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 MultiExprArg ArrayExprs,
2019 SourceLocation EqualOrColonLoc,
2020 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002021 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002024 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002027
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002028 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 }
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002032 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 /// By default, builds the implicit value initialization without performing
2034 /// any semantic analysis. Subclasses may override this routine to provide
2035 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002036 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002037 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 }
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002044 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002045 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002046 SourceLocation RParenLoc) {
2047 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002048 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002049 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
2051
2052 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002057 MultiExprArg SubExprs,
2058 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002059 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 }
Mike Stump11289f42009-09-09 15:08:12 +00002061
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002063 ///
2064 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 /// rather than attempting to map the label statement itself.
2066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002067 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002068 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002069 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 }
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002073 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002076 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002077 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002079 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 /// \brief Build a new __builtin_choose_expr expression.
2083 ///
2084 /// By default, performs semantic analysis to build the new expression.
2085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002086 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002087 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 SourceLocation RParenLoc) {
2089 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002090 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 RParenLoc);
2092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
Peter Collingbourne91147592011-04-15 00:35:48 +00002094 /// \brief Build a new generic selection expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
2098 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2099 SourceLocation DefaultLoc,
2100 SourceLocation RParenLoc,
2101 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002102 ArrayRef<TypeSourceInfo *> Types,
2103 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002104 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002105 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002106 }
2107
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 /// \brief Build a new overloaded operator call expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// The semantic analysis provides the behavior of template instantiation,
2112 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002113 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// argument-dependent lookup, etc. Subclasses may override this routine to
2115 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002116 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002118 Expr *Callee,
2119 Expr *First,
2120 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002121
2122 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002123 /// reinterpret_cast.
2124 ///
2125 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002126 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002128 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 Stmt::StmtClass Class,
2130 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002131 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 SourceLocation RAngleLoc,
2133 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002134 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RParenLoc) {
2136 switch (Class) {
2137 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002138 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002139 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002140 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002141
2142 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002143 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002144 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002145 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002148 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002149 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002150 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002154 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002155 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002156 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002159 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 }
Mike Stump11289f42009-09-09 15:08:12 +00002162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new C++ static_cast expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002169 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 SourceLocation RAngleLoc,
2171 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002172 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002174 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002175 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002176 SourceRange(LAngleLoc, RAngleLoc),
2177 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 }
2179
2180 /// \brief Build a new C++ dynamic_cast expression.
2181 ///
2182 /// By default, performs semantic analysis to build the new expression.
2183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002186 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 SourceLocation RAngleLoc,
2188 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002189 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002191 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002192 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002193 SourceRange(LAngleLoc, RAngleLoc),
2194 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 }
2196
2197 /// \brief Build a new C++ reinterpret_cast expression.
2198 ///
2199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002201 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002203 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 SourceLocation RAngleLoc,
2205 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002206 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002208 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002209 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002210 SourceRange(LAngleLoc, RAngleLoc),
2211 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 }
2213
2214 /// \brief Build a new C++ const_cast expression.
2215 ///
2216 /// By default, performs semantic analysis to build the new expression.
2217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002218 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002220 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 SourceLocation RAngleLoc,
2222 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002223 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002225 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002226 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002227 SourceRange(LAngleLoc, RAngleLoc),
2228 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 }
Mike Stump11289f42009-09-09 15:08:12 +00002230
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 /// \brief Build a new C++ functional-style cast expression.
2232 ///
2233 /// By default, performs semantic analysis to build the new expression.
2234 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002235 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2236 SourceLocation LParenLoc,
2237 Expr *Sub,
2238 SourceLocation RParenLoc) {
2239 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002240 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 RParenLoc);
2242 }
Mike Stump11289f42009-09-09 15:08:12 +00002243
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 /// \brief Build a new C++ typeid(type) expression.
2245 ///
2246 /// By default, performs semantic analysis to build the new expression.
2247 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002248 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002249 SourceLocation TypeidLoc,
2250 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002252 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002253 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 }
Mike Stump11289f42009-09-09 15:08:12 +00002255
Francois Pichet9f4f2072010-09-08 12:20:18 +00002256
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 /// \brief Build a new C++ typeid(expr) expression.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002261 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002262 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002263 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002265 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002266 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002267 }
2268
Francois Pichet9f4f2072010-09-08 12:20:18 +00002269 /// \brief Build a new C++ __uuidof(type) expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
2273 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2274 SourceLocation TypeidLoc,
2275 TypeSourceInfo *Operand,
2276 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002277 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002278 RParenLoc);
2279 }
2280
2281 /// \brief Build a new C++ __uuidof(expr) expression.
2282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
2285 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2286 SourceLocation TypeidLoc,
2287 Expr *Operand,
2288 SourceLocation RParenLoc) {
2289 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2290 RParenLoc);
2291 }
2292
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 /// \brief Build a new C++ "this" expression.
2294 ///
2295 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002296 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002298 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002299 QualType ThisType,
2300 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002301 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002302 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 }
2304
2305 /// \brief Build a new C++ throw expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002309 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2310 bool IsThrownVariableInScope) {
2311 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 }
2313
2314 /// \brief Build a new C++ default-argument expression.
2315 ///
2316 /// By default, builds a new default-argument expression, which does not
2317 /// require any semantic analysis. Subclasses may override this routine to
2318 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002319 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002320 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002321 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
2323
Richard Smith852c9db2013-04-20 22:23:05 +00002324 /// \brief Build a new C++11 default-initialization expression.
2325 ///
2326 /// By default, builds a new default field initialization expression, which
2327 /// does not require any semantic analysis. Subclasses may override this
2328 /// routine to provide different behavior.
2329 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2330 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002331 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002332 }
2333
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 /// \brief Build a new C++ zero-initialization expression.
2335 ///
2336 /// By default, performs semantic analysis to build the new expression.
2337 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002338 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2339 SourceLocation LParenLoc,
2340 SourceLocation RParenLoc) {
2341 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002342 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 }
Mike Stump11289f42009-09-09 15:08:12 +00002344
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 /// \brief Build a new C++ "new" expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002349 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002350 bool UseGlobal,
2351 SourceLocation PlacementLParen,
2352 MultiExprArg PlacementArgs,
2353 SourceLocation PlacementRParen,
2354 SourceRange TypeIdParens,
2355 QualType AllocatedType,
2356 TypeSourceInfo *AllocatedTypeInfo,
2357 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002358 SourceRange DirectInitRange,
2359 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002360 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002362 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002364 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002365 AllocatedType,
2366 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002367 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002368 DirectInitRange,
2369 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 /// \brief Build a new C++ "delete" expression.
2373 ///
2374 /// By default, performs semantic analysis to build the new expression.
2375 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002376 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 bool IsGlobalDelete,
2378 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002379 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002381 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383
Douglas Gregor29c42f22012-02-24 07:38:34 +00002384 /// \brief Build a new type trait expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
2388 ExprResult RebuildTypeTrait(TypeTrait Trait,
2389 SourceLocation StartLoc,
2390 ArrayRef<TypeSourceInfo *> Args,
2391 SourceLocation RParenLoc) {
2392 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002394
John Wiegley6242b6a2011-04-28 00:16:57 +00002395 /// \brief Build a new array type trait expression.
2396 ///
2397 /// By default, performs semantic analysis to build the new expression.
2398 /// Subclasses may override this routine to provide different behavior.
2399 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2400 SourceLocation StartLoc,
2401 TypeSourceInfo *TSInfo,
2402 Expr *DimExpr,
2403 SourceLocation RParenLoc) {
2404 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2405 }
2406
John Wiegleyf9f65842011-04-25 06:54:41 +00002407 /// \brief Build a new expression trait expression.
2408 ///
2409 /// By default, performs semantic analysis to build the new expression.
2410 /// Subclasses may override this routine to provide different behavior.
2411 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2412 SourceLocation StartLoc,
2413 Expr *Queried,
2414 SourceLocation RParenLoc) {
2415 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2416 }
2417
Mike Stump11289f42009-09-09 15:08:12 +00002418 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 /// expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002423 ExprResult RebuildDependentScopeDeclRefExpr(
2424 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002425 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002426 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002427 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002428 bool IsAddressOfOperand,
2429 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002431 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002432
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002433 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002434 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2435 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002436
Reid Kleckner32506ed2014-06-12 23:03:48 +00002437 return getSema().BuildQualifiedDeclarationNameExpr(
2438 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
2440
2441 /// \brief Build a new template-id expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002445 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002446 SourceLocation TemplateKWLoc,
2447 LookupResult &R,
2448 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002449 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002450 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2451 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 }
2453
2454 /// \brief Build a new object-construction expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002458 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002459 SourceLocation Loc,
2460 CXXConstructorDecl *Constructor,
2461 bool IsElidable,
2462 MultiExprArg Args,
2463 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002464 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002465 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002466 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002467 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002468 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002469 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002470 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002471 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002472 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002473
Douglas Gregordb121ba2009-12-14 16:27:04 +00002474 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002475 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002476 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002477 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002478 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002479 RequiresZeroInit, ConstructKind,
2480 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 }
2482
2483 /// \brief Build a new object-construction expression.
2484 ///
2485 /// By default, performs semantic analysis to build the new expression.
2486 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002487 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2488 SourceLocation LParenLoc,
2489 MultiExprArg Args,
2490 SourceLocation RParenLoc) {
2491 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002492 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002493 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 RParenLoc);
2495 }
2496
2497 /// \brief Build a new object-construction expression.
2498 ///
2499 /// By default, performs semantic analysis to build the new expression.
2500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002501 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2502 SourceLocation LParenLoc,
2503 MultiExprArg Args,
2504 SourceLocation RParenLoc) {
2505 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002507 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002508 RParenLoc);
2509 }
Mike Stump11289f42009-09-09 15:08:12 +00002510
Douglas Gregora16548e2009-08-11 05:31:07 +00002511 /// \brief Build a new member reference expression.
2512 ///
2513 /// By default, performs semantic analysis to build the new expression.
2514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002515 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002516 QualType BaseType,
2517 bool IsArrow,
2518 SourceLocation OperatorLoc,
2519 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002520 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002521 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002522 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002523 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002525 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002526
John McCallb268a282010-08-23 23:25:46 +00002527 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002528 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002529 SS, TemplateKWLoc,
2530 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002531 MemberNameInfo,
2532 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 }
2534
John McCall10eae182009-11-30 22:42:35 +00002535 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002539 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2540 SourceLocation OperatorLoc,
2541 bool IsArrow,
2542 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002543 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002544 NamedDecl *FirstQualifierInScope,
2545 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002546 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002547 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002548 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002549
John McCallb268a282010-08-23 23:25:46 +00002550 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002551 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002552 SS, TemplateKWLoc,
2553 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002554 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002555 }
Mike Stump11289f42009-09-09 15:08:12 +00002556
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002557 /// \brief Build a new noexcept expression.
2558 ///
2559 /// By default, performs semantic analysis to build the new expression.
2560 /// Subclasses may override this routine to provide different behavior.
2561 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2562 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2563 }
2564
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002565 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002566 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2567 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002568 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002569 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002570 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002571 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2572 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002573 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002574
2575 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2576 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002577 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002578 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002579
Patrick Beard0caa3942012-04-19 00:25:12 +00002580 /// \brief Build a new Objective-C boxed expression.
2581 ///
2582 /// By default, performs semantic analysis to build the new expression.
2583 /// Subclasses may override this routine to provide different behavior.
2584 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2585 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002587
Ted Kremeneke65b0862012-03-06 20:05:56 +00002588 /// \brief Build a new Objective-C array literal.
2589 ///
2590 /// By default, performs semantic analysis to build the new expression.
2591 /// Subclasses may override this routine to provide different behavior.
2592 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2593 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002594 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002595 MultiExprArg(Elements, NumElements));
2596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002597
2598 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002599 Expr *Base, Expr *Key,
2600 ObjCMethodDecl *getterMethod,
2601 ObjCMethodDecl *setterMethod) {
2602 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2603 getterMethod, setterMethod);
2604 }
2605
2606 /// \brief Build a new Objective-C dictionary literal.
2607 ///
2608 /// By default, performs semantic analysis to build the new expression.
2609 /// Subclasses may override this routine to provide different behavior.
2610 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2611 ObjCDictionaryElement *Elements,
2612 unsigned NumElements) {
2613 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2614 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002615
James Dennett2a4d13c2012-06-15 07:13:21 +00002616 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002620 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002621 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002623 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002624 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002625
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002626 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002627 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002628 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002629 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002630 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002631 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002632 MultiExprArg Args,
2633 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002634 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2635 ReceiverTypeInfo->getType(),
2636 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002637 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002638 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002639 }
2640
2641 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002642 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002643 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002644 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002645 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002646 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002647 MultiExprArg Args,
2648 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002649 return SemaRef.BuildInstanceMessage(Receiver,
2650 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002651 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002652 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002653 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002654 }
2655
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002656 /// \brief Build a new Objective-C instance/class message to 'super'.
2657 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2658 Selector Sel,
2659 ArrayRef<SourceLocation> SelectorLocs,
2660 ObjCMethodDecl *Method,
2661 SourceLocation LBracLoc,
2662 MultiExprArg Args,
2663 SourceLocation RBracLoc) {
2664 ObjCInterfaceDecl *Class = Method->getClassInterface();
2665 QualType ReceiverTy = SemaRef.Context.getObjCInterfaceType(Class);
2666
2667 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
2668 ReceiverTy,
2669 SuperLoc,
2670 Sel, Method, LBracLoc, SelectorLocs,
2671 RBracLoc, Args)
2672 : SemaRef.BuildClassMessage(nullptr,
2673 ReceiverTy,
2674 SuperLoc,
2675 Sel, Method, LBracLoc, SelectorLocs,
2676 RBracLoc, Args);
2677
2678
2679 }
2680
Douglas Gregord51d90d2010-04-26 20:11:03 +00002681 /// \brief Build a new Objective-C ivar reference expression.
2682 ///
2683 /// By default, performs semantic analysis to build the new expression.
2684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002685 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002686 SourceLocation IvarLoc,
2687 bool IsArrow, bool IsFreeIvar) {
2688 // FIXME: We lose track of the IsFreeIvar bit.
2689 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002690 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2691 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002692 /*FIXME:*/IvarLoc, IsArrow,
2693 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002694 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002695 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002696 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002697 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002698
2699 /// \brief Build a new Objective-C property reference expression.
2700 ///
2701 /// By default, performs semantic analysis to build the new expression.
2702 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002703 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002704 ObjCPropertyDecl *Property,
2705 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002706 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002707 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2708 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2709 /*FIXME:*/PropertyLoc,
2710 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002711 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002712 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002713 NameInfo,
2714 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002716
John McCallb7bd14f2010-12-02 01:19:52 +00002717 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002718 ///
2719 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002720 /// Subclasses may override this routine to provide different behavior.
2721 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2722 ObjCMethodDecl *Getter,
2723 ObjCMethodDecl *Setter,
2724 SourceLocation PropertyLoc) {
2725 // Since these expressions can only be value-dependent, we do not
2726 // need to perform semantic analysis again.
2727 return Owned(
2728 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2729 VK_LValue, OK_ObjCProperty,
2730 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002731 }
2732
Douglas Gregord51d90d2010-04-26 20:11:03 +00002733 /// \brief Build a new Objective-C "isa" expression.
2734 ///
2735 /// By default, performs semantic analysis to build the new expression.
2736 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002737 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002738 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002739 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002740 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2741 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002742 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002743 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002744 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002745 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002746 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002748
Douglas Gregora16548e2009-08-11 05:31:07 +00002749 /// \brief Build a new shuffle vector expression.
2750 ///
2751 /// By default, performs semantic analysis to build the new expression.
2752 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002753 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002754 MultiExprArg SubExprs,
2755 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002757 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002758 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2759 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2760 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002761 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002762
Douglas Gregora16548e2009-08-11 05:31:07 +00002763 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002764 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002765 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2766 SemaRef.Context.BuiltinFnTy,
2767 VK_RValue, BuiltinLoc);
2768 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2769 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002770 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002771
2772 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002773 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002774 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002775 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002776
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002778 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002779 }
John McCall31f82722010-11-12 08:19:04 +00002780
Hal Finkelc4d7c822013-09-18 03:29:45 +00002781 /// \brief Build a new convert vector expression.
2782 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2783 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2784 SourceLocation RParenLoc) {
2785 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2786 BuiltinLoc, RParenLoc);
2787 }
2788
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002789 /// \brief Build a new template argument pack expansion.
2790 ///
2791 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002792 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002793 /// different behavior.
2794 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002795 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002796 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002797 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002798 case TemplateArgument::Expression: {
2799 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002800 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2801 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002802 if (Result.isInvalid())
2803 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002804
Douglas Gregor98318c22011-01-03 21:37:45 +00002805 return TemplateArgumentLoc(Result.get(), Result.get());
2806 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002807
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002808 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002809 return TemplateArgumentLoc(TemplateArgument(
2810 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002811 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002812 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002813 Pattern.getTemplateNameLoc(),
2814 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002815
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002816 case TemplateArgument::Null:
2817 case TemplateArgument::Integral:
2818 case TemplateArgument::Declaration:
2819 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002820 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002821 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002822 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002823
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002824 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002825 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002826 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002827 EllipsisLoc,
2828 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002829 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2830 Expansion);
2831 break;
2832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002833
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002834 return TemplateArgumentLoc();
2835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002836
Douglas Gregor968f23a2011-01-03 19:31:53 +00002837 /// \brief Build a new expression pack expansion.
2838 ///
2839 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002840 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002841 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002842 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002843 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002844 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002845 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002846
Richard Smith0f0af192014-11-08 05:07:16 +00002847 /// \brief Build a new C++1z fold-expression.
2848 ///
2849 /// By default, performs semantic analysis in order to build a new fold
2850 /// expression.
2851 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2852 BinaryOperatorKind Operator,
2853 SourceLocation EllipsisLoc, Expr *RHS,
2854 SourceLocation RParenLoc) {
2855 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2856 RHS, RParenLoc);
2857 }
2858
2859 /// \brief Build an empty C++1z fold-expression with the given operator.
2860 ///
2861 /// By default, produces the fallback value for the fold-expression, or
2862 /// produce an error if there is no fallback value.
2863 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2864 BinaryOperatorKind Operator) {
2865 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2866 }
2867
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002868 /// \brief Build a new atomic operation expression.
2869 ///
2870 /// By default, performs semantic analysis to build the new expression.
2871 /// Subclasses may override this routine to provide different behavior.
2872 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2873 MultiExprArg SubExprs,
2874 QualType RetTy,
2875 AtomicExpr::AtomicOp Op,
2876 SourceLocation RParenLoc) {
2877 // Just create the expression; there is not any interesting semantic
2878 // analysis here because we can't actually build an AtomicExpr until
2879 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002880 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002881 RParenLoc);
2882 }
2883
John McCall31f82722010-11-12 08:19:04 +00002884private:
Douglas Gregor14454802011-02-25 02:25:35 +00002885 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2886 QualType ObjectType,
2887 NamedDecl *FirstQualifierInScope,
2888 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002889
2890 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2891 QualType ObjectType,
2892 NamedDecl *FirstQualifierInScope,
2893 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002894
2895 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2896 NamedDecl *FirstQualifierInScope,
2897 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002898};
Douglas Gregora16548e2009-08-11 05:31:07 +00002899
Douglas Gregorebe10102009-08-20 07:17:43 +00002900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002901StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002902 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002903 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002904
Douglas Gregorebe10102009-08-20 07:17:43 +00002905 switch (S->getStmtClass()) {
2906 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002907
Douglas Gregorebe10102009-08-20 07:17:43 +00002908 // Transform individual statement nodes
2909#define STMT(Node, Parent) \
2910 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002911#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002912#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002913#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002914
Douglas Gregorebe10102009-08-20 07:17:43 +00002915 // Transform expressions by calling TransformExpr.
2916#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002917#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002918#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002919#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002920 {
John McCalldadc5752010-08-24 06:29:42 +00002921 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002922 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002924
Richard Smith945f8d32013-01-14 22:39:08 +00002925 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002926 }
Mike Stump11289f42009-09-09 15:08:12 +00002927 }
2928
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002929 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002930}
Mike Stump11289f42009-09-09 15:08:12 +00002931
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002932template<typename Derived>
2933OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2934 if (!S)
2935 return S;
2936
2937 switch (S->getClauseKind()) {
2938 default: break;
2939 // Transform individual clause nodes
2940#define OPENMP_CLAUSE(Name, Class) \
2941 case OMPC_ ## Name : \
2942 return getDerived().Transform ## Class(cast<Class>(S));
2943#include "clang/Basic/OpenMPKinds.def"
2944 }
2945
2946 return S;
2947}
2948
Mike Stump11289f42009-09-09 15:08:12 +00002949
Douglas Gregore922c772009-08-04 22:27:00 +00002950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002951ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002952 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002953 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002954
2955 switch (E->getStmtClass()) {
2956 case Stmt::NoStmtClass: break;
2957#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002958#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002959#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002960 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002961#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002962 }
2963
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002964 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002965}
2966
2967template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002968ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002969 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002970 // Initializers are instantiated like expressions, except that various outer
2971 // layers are stripped.
2972 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002973 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002974
2975 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2976 Init = ExprTemp->getSubExpr();
2977
Richard Smithe6ca4752013-05-30 22:40:16 +00002978 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2979 Init = MTE->GetTemporaryExpr();
2980
Richard Smithd59b8322012-12-19 01:39:02 +00002981 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2982 Init = Binder->getSubExpr();
2983
2984 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2985 Init = ICE->getSubExprAsWritten();
2986
Richard Smithcc1b96d2013-06-12 22:31:48 +00002987 if (CXXStdInitializerListExpr *ILE =
2988 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00002989 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00002990
Richard Smithc6abd962014-07-25 01:12:44 +00002991 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00002992 // InitListExprs. Other forms of copy-initialization will be a no-op if
2993 // the initializer is already the right type.
2994 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00002995 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00002996 return getDerived().TransformExpr(Init);
2997
2998 // Revert value-initialization back to empty parens.
2999 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3000 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003001 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003002 Parens.getEnd());
3003 }
3004
3005 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3006 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003007 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003008 SourceLocation());
3009
3010 // Revert initialization by constructor back to a parenthesized or braced list
3011 // of expressions. Any other form of initializer can just be reused directly.
3012 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003013 return getDerived().TransformExpr(Init);
3014
Richard Smithf8adcdc2014-07-17 05:12:35 +00003015 // If the initialization implicitly converted an initializer list to a
3016 // std::initializer_list object, unwrap the std::initializer_list too.
3017 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003018 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003019
Richard Smithd59b8322012-12-19 01:39:02 +00003020 SmallVector<Expr*, 8> NewArgs;
3021 bool ArgChanged = false;
3022 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003023 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003024 return ExprError();
3025
3026 // If this was list initialization, revert to list form.
3027 if (Construct->isListInitialization())
3028 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3029 Construct->getLocEnd(),
3030 Construct->getType());
3031
Richard Smithd59b8322012-12-19 01:39:02 +00003032 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003033 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003034 if (Parens.isInvalid()) {
3035 // This was a variable declaration's initialization for which no initializer
3036 // was specified.
3037 assert(NewArgs.empty() &&
3038 "no parens or braces but have direct init with arguments?");
3039 return ExprEmpty();
3040 }
Richard Smithd59b8322012-12-19 01:39:02 +00003041 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3042 Parens.getEnd());
3043}
3044
3045template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003046bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3047 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003048 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003049 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003050 bool *ArgChanged) {
3051 for (unsigned I = 0; I != NumInputs; ++I) {
3052 // If requested, drop call arguments that need to be dropped.
3053 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3054 if (ArgChanged)
3055 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003056
Douglas Gregora3efea12011-01-03 19:04:46 +00003057 break;
3058 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003059
Douglas Gregor968f23a2011-01-03 19:31:53 +00003060 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3061 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003062
Chris Lattner01cf8db2011-07-20 06:58:45 +00003063 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003064 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3065 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003066
Douglas Gregor968f23a2011-01-03 19:31:53 +00003067 // Determine whether the set of unexpanded parameter packs can and should
3068 // be expanded.
3069 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003070 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003071 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3072 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003073 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3074 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003075 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003076 Expand, RetainExpansion,
3077 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003078 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003079
Douglas Gregor968f23a2011-01-03 19:31:53 +00003080 if (!Expand) {
3081 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003082 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003083 // expansion.
3084 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3085 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3086 if (OutPattern.isInvalid())
3087 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003088
3089 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003090 Expansion->getEllipsisLoc(),
3091 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003092 if (Out.isInvalid())
3093 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003094
Douglas Gregor968f23a2011-01-03 19:31:53 +00003095 if (ArgChanged)
3096 *ArgChanged = true;
3097 Outputs.push_back(Out.get());
3098 continue;
3099 }
John McCall542e7c62011-07-06 07:30:07 +00003100
3101 // Record right away that the argument was changed. This needs
3102 // to happen even if the array expands to nothing.
3103 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregor968f23a2011-01-03 19:31:53 +00003105 // The transform has determined that we should perform an elementwise
3106 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003107 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003108 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3109 ExprResult Out = getDerived().TransformExpr(Pattern);
3110 if (Out.isInvalid())
3111 return true;
3112
Richard Smith9467be42014-06-06 17:33:35 +00003113 // FIXME: Can this happen? We should not try to expand the pack
3114 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003115 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003116 Out = getDerived().RebuildPackExpansion(
3117 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003118 if (Out.isInvalid())
3119 return true;
3120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003121
Douglas Gregor968f23a2011-01-03 19:31:53 +00003122 Outputs.push_back(Out.get());
3123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Richard Smith9467be42014-06-06 17:33:35 +00003125 // If we're supposed to retain a pack expansion, do so by temporarily
3126 // forgetting the partially-substituted parameter pack.
3127 if (RetainExpansion) {
3128 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3129
3130 ExprResult Out = getDerived().TransformExpr(Pattern);
3131 if (Out.isInvalid())
3132 return true;
3133
3134 Out = getDerived().RebuildPackExpansion(
3135 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3136 if (Out.isInvalid())
3137 return true;
3138
3139 Outputs.push_back(Out.get());
3140 }
3141
Douglas Gregor968f23a2011-01-03 19:31:53 +00003142 continue;
3143 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Richard Smithd59b8322012-12-19 01:39:02 +00003145 ExprResult Result =
3146 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3147 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003148 if (Result.isInvalid())
3149 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003150
Douglas Gregora3efea12011-01-03 19:04:46 +00003151 if (Result.get() != Inputs[I] && ArgChanged)
3152 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003153
3154 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003155 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003156
Douglas Gregora3efea12011-01-03 19:04:46 +00003157 return false;
3158}
3159
3160template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003161NestedNameSpecifierLoc
3162TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3163 NestedNameSpecifierLoc NNS,
3164 QualType ObjectType,
3165 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003166 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003167 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003168 Qualifier = Qualifier.getPrefix())
3169 Qualifiers.push_back(Qualifier);
3170
3171 CXXScopeSpec SS;
3172 while (!Qualifiers.empty()) {
3173 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3174 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor14454802011-02-25 02:25:35 +00003176 switch (QNNS->getKind()) {
3177 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003178 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003179 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003180 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003181 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003182 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003183 FirstQualifierInScope, false))
3184 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor14454802011-02-25 02:25:35 +00003186 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
Douglas Gregor14454802011-02-25 02:25:35 +00003188 case NestedNameSpecifier::Namespace: {
3189 NamespaceDecl *NS
3190 = cast_or_null<NamespaceDecl>(
3191 getDerived().TransformDecl(
3192 Q.getLocalBeginLoc(),
3193 QNNS->getAsNamespace()));
3194 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3195 break;
3196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor14454802011-02-25 02:25:35 +00003198 case NestedNameSpecifier::NamespaceAlias: {
3199 NamespaceAliasDecl *Alias
3200 = cast_or_null<NamespaceAliasDecl>(
3201 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3202 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003203 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003204 Q.getLocalEndLoc());
3205 break;
3206 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor14454802011-02-25 02:25:35 +00003208 case NestedNameSpecifier::Global:
3209 // There is no meaningful transformation that one could perform on the
3210 // global scope.
3211 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3212 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003213
Nikola Smiljanic67860242014-09-26 00:28:20 +00003214 case NestedNameSpecifier::Super: {
3215 CXXRecordDecl *RD =
3216 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3217 SourceLocation(), QNNS->getAsRecordDecl()));
3218 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3219 break;
3220 }
3221
Douglas Gregor14454802011-02-25 02:25:35 +00003222 case NestedNameSpecifier::TypeSpecWithTemplate:
3223 case NestedNameSpecifier::TypeSpec: {
3224 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3225 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor14454802011-02-25 02:25:35 +00003227 if (!TL)
3228 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor14454802011-02-25 02:25:35 +00003230 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003231 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003232 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003233 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003234 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003235 if (TL.getType()->isEnumeralType())
3236 SemaRef.Diag(TL.getBeginLoc(),
3237 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003238 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3239 Q.getLocalEndLoc());
3240 break;
3241 }
Richard Trieude756fb2011-05-07 01:36:37 +00003242 // If the nested-name-specifier is an invalid type def, don't emit an
3243 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003244 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3245 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003246 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003247 << TL.getType() << SS.getRange();
3248 }
Douglas Gregor14454802011-02-25 02:25:35 +00003249 return NestedNameSpecifierLoc();
3250 }
Douglas Gregore16af532011-02-28 18:50:33 +00003251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregore16af532011-02-28 18:50:33 +00003253 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003254 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003255 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003256 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003257
Douglas Gregor14454802011-02-25 02:25:35 +00003258 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003259 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003260 !getDerived().AlwaysRebuild())
3261 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
3263 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003264 // nested-name-specifier, do so.
3265 if (SS.location_size() == NNS.getDataLength() &&
3266 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3267 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3268
3269 // Allocate new nested-name-specifier location information.
3270 return SS.getWithLocInContext(SemaRef.Context);
3271}
3272
3273template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003274DeclarationNameInfo
3275TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003276::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003277 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003278 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003279 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003280
3281 switch (Name.getNameKind()) {
3282 case DeclarationName::Identifier:
3283 case DeclarationName::ObjCZeroArgSelector:
3284 case DeclarationName::ObjCOneArgSelector:
3285 case DeclarationName::ObjCMultiArgSelector:
3286 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003287 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003288 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003289 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorf816bd72009-09-03 22:13:48 +00003291 case DeclarationName::CXXConstructorName:
3292 case DeclarationName::CXXDestructorName:
3293 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003294 TypeSourceInfo *NewTInfo;
3295 CanQualType NewCanTy;
3296 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003297 NewTInfo = getDerived().TransformType(OldTInfo);
3298 if (!NewTInfo)
3299 return DeclarationNameInfo();
3300 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003301 }
3302 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003303 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003304 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003305 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003306 if (NewT.isNull())
3307 return DeclarationNameInfo();
3308 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3309 }
Mike Stump11289f42009-09-09 15:08:12 +00003310
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003311 DeclarationName NewName
3312 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3313 NewCanTy);
3314 DeclarationNameInfo NewNameInfo(NameInfo);
3315 NewNameInfo.setName(NewName);
3316 NewNameInfo.setNamedTypeInfo(NewTInfo);
3317 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003318 }
Mike Stump11289f42009-09-09 15:08:12 +00003319 }
3320
David Blaikie83d382b2011-09-23 05:06:16 +00003321 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003322}
3323
3324template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003325TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003326TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3327 TemplateName Name,
3328 SourceLocation NameLoc,
3329 QualType ObjectType,
3330 NamedDecl *FirstQualifierInScope) {
3331 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3332 TemplateDecl *Template = QTN->getTemplateDecl();
3333 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003334
Douglas Gregor9db53502011-03-02 18:07:45 +00003335 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003336 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003337 Template));
3338 if (!TransTemplate)
3339 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003340
Douglas Gregor9db53502011-03-02 18:07:45 +00003341 if (!getDerived().AlwaysRebuild() &&
3342 SS.getScopeRep() == QTN->getQualifier() &&
3343 TransTemplate == Template)
3344 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003345
Douglas Gregor9db53502011-03-02 18:07:45 +00003346 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3347 TransTemplate);
3348 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003349
Douglas Gregor9db53502011-03-02 18:07:45 +00003350 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3351 if (SS.getScopeRep()) {
3352 // These apply to the scope specifier, not the template.
3353 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003354 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003355 }
3356
Douglas Gregor9db53502011-03-02 18:07:45 +00003357 if (!getDerived().AlwaysRebuild() &&
3358 SS.getScopeRep() == DTN->getQualifier() &&
3359 ObjectType.isNull())
3360 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003361
Douglas Gregor9db53502011-03-02 18:07:45 +00003362 if (DTN->isIdentifier()) {
3363 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003364 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003365 NameLoc,
3366 ObjectType,
3367 FirstQualifierInScope);
3368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003369
Douglas Gregor9db53502011-03-02 18:07:45 +00003370 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3371 ObjectType);
3372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003373
Douglas Gregor9db53502011-03-02 18:07:45 +00003374 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3375 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003376 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003377 Template));
3378 if (!TransTemplate)
3379 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor9db53502011-03-02 18:07:45 +00003381 if (!getDerived().AlwaysRebuild() &&
3382 TransTemplate == Template)
3383 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor9db53502011-03-02 18:07:45 +00003385 return TemplateName(TransTemplate);
3386 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor9db53502011-03-02 18:07:45 +00003388 if (SubstTemplateTemplateParmPackStorage *SubstPack
3389 = Name.getAsSubstTemplateTemplateParmPack()) {
3390 TemplateTemplateParmDecl *TransParam
3391 = cast_or_null<TemplateTemplateParmDecl>(
3392 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3393 if (!TransParam)
3394 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Douglas Gregor9db53502011-03-02 18:07:45 +00003396 if (!getDerived().AlwaysRebuild() &&
3397 TransParam == SubstPack->getParameterPack())
3398 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
3400 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003401 SubstPack->getArgumentPack());
3402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor9db53502011-03-02 18:07:45 +00003404 // These should be getting filtered out before they reach the AST.
3405 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003406}
3407
3408template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003409void TreeTransform<Derived>::InventTemplateArgumentLoc(
3410 const TemplateArgument &Arg,
3411 TemplateArgumentLoc &Output) {
3412 SourceLocation Loc = getDerived().getBaseLocation();
3413 switch (Arg.getKind()) {
3414 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003415 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003416 break;
3417
3418 case TemplateArgument::Type:
3419 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003420 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
John McCall0ad16662009-10-29 08:12:44 +00003422 break;
3423
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003424 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003425 case TemplateArgument::TemplateExpansion: {
3426 NestedNameSpecifierLocBuilder Builder;
3427 TemplateName Template = Arg.getAsTemplate();
3428 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3429 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3430 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3431 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor9d802122011-03-02 17:09:35 +00003433 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003434 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003435 Builder.getWithLocInContext(SemaRef.Context),
3436 Loc);
3437 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003438 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003439 Builder.getWithLocInContext(SemaRef.Context),
3440 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003442 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003443 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003444
John McCall0ad16662009-10-29 08:12:44 +00003445 case TemplateArgument::Expression:
3446 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3447 break;
3448
3449 case TemplateArgument::Declaration:
3450 case TemplateArgument::Integral:
3451 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003452 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003453 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003454 break;
3455 }
3456}
3457
3458template<typename Derived>
3459bool TreeTransform<Derived>::TransformTemplateArgument(
3460 const TemplateArgumentLoc &Input,
3461 TemplateArgumentLoc &Output) {
3462 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003463 switch (Arg.getKind()) {
3464 case TemplateArgument::Null:
3465 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003466 case TemplateArgument::Pack:
3467 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003468 case TemplateArgument::NullPtr:
3469 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003470
Douglas Gregore922c772009-08-04 22:27:00 +00003471 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003472 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003473 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003474 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003475
3476 DI = getDerived().TransformType(DI);
3477 if (!DI) return true;
3478
3479 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3480 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003481 }
Mike Stump11289f42009-09-09 15:08:12 +00003482
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003483 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003484 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3485 if (QualifierLoc) {
3486 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3487 if (!QualifierLoc)
3488 return true;
3489 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003490
Douglas Gregordf846d12011-03-02 18:46:51 +00003491 CXXScopeSpec SS;
3492 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003493 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003494 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3495 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003496 if (Template.isNull())
3497 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor9d802122011-03-02 17:09:35 +00003499 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003500 Input.getTemplateNameLoc());
3501 return false;
3502 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003503
3504 case TemplateArgument::TemplateExpansion:
3505 llvm_unreachable("Caller should expand pack expansions");
3506
Douglas Gregore922c772009-08-04 22:27:00 +00003507 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003508 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003509 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003510 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003511
John McCall0ad16662009-10-29 08:12:44 +00003512 Expr *InputExpr = Input.getSourceExpression();
3513 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3514
Chris Lattnercdb591a2011-04-25 20:37:58 +00003515 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003516 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003517 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003518 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003519 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003520 }
Douglas Gregore922c772009-08-04 22:27:00 +00003521 }
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregore922c772009-08-04 22:27:00 +00003523 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003524 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003525}
3526
Douglas Gregorfe921a72010-12-20 23:36:19 +00003527/// \brief Iterator adaptor that invents template argument location information
3528/// for each of the template arguments in its underlying iterator.
3529template<typename Derived, typename InputIterator>
3530class TemplateArgumentLocInventIterator {
3531 TreeTransform<Derived> &Self;
3532 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003533
Douglas Gregorfe921a72010-12-20 23:36:19 +00003534public:
3535 typedef TemplateArgumentLoc value_type;
3536 typedef TemplateArgumentLoc reference;
3537 typedef typename std::iterator_traits<InputIterator>::difference_type
3538 difference_type;
3539 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003540
Douglas Gregorfe921a72010-12-20 23:36:19 +00003541 class pointer {
3542 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregorfe921a72010-12-20 23:36:19 +00003544 public:
3545 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
Douglas Gregorfe921a72010-12-20 23:36:19 +00003547 const TemplateArgumentLoc *operator->() const { return &Arg; }
3548 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregorfe921a72010-12-20 23:36:19 +00003550 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregorfe921a72010-12-20 23:36:19 +00003552 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3553 InputIterator Iter)
3554 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregorfe921a72010-12-20 23:36:19 +00003556 TemplateArgumentLocInventIterator &operator++() {
3557 ++Iter;
3558 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregorfe921a72010-12-20 23:36:19 +00003561 TemplateArgumentLocInventIterator operator++(int) {
3562 TemplateArgumentLocInventIterator Old(*this);
3563 ++(*this);
3564 return Old;
3565 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003566
Douglas Gregorfe921a72010-12-20 23:36:19 +00003567 reference operator*() const {
3568 TemplateArgumentLoc Result;
3569 Self.InventTemplateArgumentLoc(*Iter, Result);
3570 return Result;
3571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregorfe921a72010-12-20 23:36:19 +00003573 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Douglas Gregorfe921a72010-12-20 23:36:19 +00003575 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3576 const TemplateArgumentLocInventIterator &Y) {
3577 return X.Iter == Y.Iter;
3578 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003579
Douglas Gregorfe921a72010-12-20 23:36:19 +00003580 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3581 const TemplateArgumentLocInventIterator &Y) {
3582 return X.Iter != Y.Iter;
3583 }
3584};
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregor42cafa82010-12-20 17:42:22 +00003586template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003587template<typename InputIterator>
3588bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3589 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003590 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003591 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003592 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003593 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003595 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3596 // Unpack argument packs, which we translate them into separate
3597 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003598 // FIXME: We could do much better if we could guarantee that the
3599 // TemplateArgumentLocInfo for the pack expansion would be usable for
3600 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003601 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003602 TemplateArgument::pack_iterator>
3603 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003604 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003605 In.getArgument().pack_begin()),
3606 PackLocIterator(*this,
3607 In.getArgument().pack_end()),
3608 Outputs))
3609 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003610
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003611 continue;
3612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003614 if (In.getArgument().isPackExpansion()) {
3615 // We have a pack expansion, for which we will be substituting into
3616 // the pattern.
3617 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003618 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003619 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003620 = getSema().getTemplateArgumentPackExpansionPattern(
3621 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Chris Lattner01cf8db2011-07-20 06:58:45 +00003623 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003624 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3625 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003627 // Determine whether the set of unexpanded parameter packs can and should
3628 // be expanded.
3629 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003630 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003631 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003632 if (getDerived().TryExpandParameterPacks(Ellipsis,
3633 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003634 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003635 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003636 RetainExpansion,
3637 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003638 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003640 if (!Expand) {
3641 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003642 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003643 // expansion.
3644 TemplateArgumentLoc OutPattern;
3645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3646 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3647 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003649 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3650 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003651 if (Out.getArgument().isNull())
3652 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003654 Outputs.addArgument(Out);
3655 continue;
3656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003657
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003658 // The transform has determined that we should perform an elementwise
3659 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003660 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003661 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3662
3663 if (getDerived().TransformTemplateArgument(Pattern, Out))
3664 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003666 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003667 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3668 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003669 if (Out.getArgument().isNull())
3670 return true;
3671 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 Outputs.addArgument(Out);
3674 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Douglas Gregor48d24112011-01-10 20:53:55 +00003676 // If we're supposed to retain a pack expansion, do so by temporarily
3677 // forgetting the partially-substituted parameter pack.
3678 if (RetainExpansion) {
3679 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Douglas Gregor48d24112011-01-10 20:53:55 +00003681 if (getDerived().TransformTemplateArgument(Pattern, Out))
3682 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003683
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003684 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3685 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003686 if (Out.getArgument().isNull())
3687 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor48d24112011-01-10 20:53:55 +00003689 Outputs.addArgument(Out);
3690 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 continue;
3693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
3695 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003696 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003697 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor42cafa82010-12-20 17:42:22 +00003699 Outputs.addArgument(Out);
3700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003701
Douglas Gregor42cafa82010-12-20 17:42:22 +00003702 return false;
3703
3704}
3705
Douglas Gregord6ff3322009-08-04 16:50:30 +00003706//===----------------------------------------------------------------------===//
3707// Type transformation
3708//===----------------------------------------------------------------------===//
3709
3710template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003711QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003712 if (getDerived().AlreadyTransformed(T))
3713 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003714
John McCall550e0c22009-10-21 00:40:46 +00003715 // Temporary workaround. All of these transformations should
3716 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003717 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3718 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003719
John McCall31f82722010-11-12 08:19:04 +00003720 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003721
John McCall550e0c22009-10-21 00:40:46 +00003722 if (!NewDI)
3723 return QualType();
3724
3725 return NewDI->getType();
3726}
3727
3728template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003729TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003730 // Refine the base location to the type's location.
3731 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3732 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003733 if (getDerived().AlreadyTransformed(DI->getType()))
3734 return DI;
3735
3736 TypeLocBuilder TLB;
3737
3738 TypeLoc TL = DI->getTypeLoc();
3739 TLB.reserve(TL.getFullDataSize());
3740
John McCall31f82722010-11-12 08:19:04 +00003741 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003742 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003743 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003744
John McCallbcd03502009-12-07 02:54:59 +00003745 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003746}
3747
3748template<typename Derived>
3749QualType
John McCall31f82722010-11-12 08:19:04 +00003750TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003751 switch (T.getTypeLocClass()) {
3752#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003753#define TYPELOC(CLASS, PARENT) \
3754 case TypeLoc::CLASS: \
3755 return getDerived().Transform##CLASS##Type(TLB, \
3756 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003757#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003758 }
Mike Stump11289f42009-09-09 15:08:12 +00003759
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003760 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003761}
3762
3763/// FIXME: By default, this routine adds type qualifiers only to types
3764/// that can have qualifiers, and silently suppresses those qualifiers
3765/// that are not permitted (e.g., qualifiers on reference or function
3766/// types). This is the right thing for template instantiation, but
3767/// probably not for other clients.
3768template<typename Derived>
3769QualType
3770TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003771 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003772 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003773
John McCall31f82722010-11-12 08:19:04 +00003774 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003775 if (Result.isNull())
3776 return QualType();
3777
3778 // Silently suppress qualifiers if the result type can't be qualified.
3779 // FIXME: this is the right thing for template instantiation, but
3780 // probably not for other clients.
3781 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003782 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003783
John McCall31168b02011-06-15 23:02:42 +00003784 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003785 // resulting type.
3786 if (Quals.hasObjCLifetime()) {
3787 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3788 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003789 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003790 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003791 // A lifetime qualifier applied to a substituted template parameter
3792 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003793 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003794 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003795 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3796 QualType Replacement = SubstTypeParam->getReplacementType();
3797 Qualifiers Qs = Replacement.getQualifiers();
3798 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003799 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003800 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3801 Qs);
3802 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003803 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003804 Replacement);
3805 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003806 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3807 // 'auto' types behave the same way as template parameters.
3808 QualType Deduced = AutoTy->getDeducedType();
3809 Qualifiers Qs = Deduced.getQualifiers();
3810 Qs.removeObjCLifetime();
3811 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3812 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003813 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3814 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003815 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003816 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003817 // Otherwise, complain about the addition of a qualifier to an
3818 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003819 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003820 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003821 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003822
Douglas Gregore46db902011-06-17 22:11:49 +00003823 Quals.removeObjCLifetime();
3824 }
3825 }
3826 }
John McCallcb0f89a2010-06-05 06:41:15 +00003827 if (!Quals.empty()) {
3828 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003829 // BuildQualifiedType might not add qualifiers if they are invalid.
3830 if (Result.hasLocalQualifiers())
3831 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003832 // No location information to preserve.
3833 }
John McCall550e0c22009-10-21 00:40:46 +00003834
3835 return Result;
3836}
3837
Douglas Gregor14454802011-02-25 02:25:35 +00003838template<typename Derived>
3839TypeLoc
3840TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3841 QualType ObjectType,
3842 NamedDecl *UnqualLookup,
3843 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003844 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003845 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003847 TypeSourceInfo *TSI =
3848 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3849 if (TSI)
3850 return TSI->getTypeLoc();
3851 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003852}
3853
Douglas Gregor579c15f2011-03-02 18:32:08 +00003854template<typename Derived>
3855TypeSourceInfo *
3856TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3857 QualType ObjectType,
3858 NamedDecl *UnqualLookup,
3859 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003860 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003861 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003863 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3864 UnqualLookup, SS);
3865}
3866
3867template <typename Derived>
3868TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3869 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3870 CXXScopeSpec &SS) {
3871 QualType T = TL.getType();
3872 assert(!getDerived().AlreadyTransformed(T));
3873
Douglas Gregor579c15f2011-03-02 18:32:08 +00003874 TypeLocBuilder TLB;
3875 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
Douglas Gregor579c15f2011-03-02 18:32:08 +00003877 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003878 TemplateSpecializationTypeLoc SpecTL =
3879 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
Douglas Gregor579c15f2011-03-02 18:32:08 +00003881 TemplateName Template
3882 = getDerived().TransformTemplateName(SS,
3883 SpecTL.getTypePtr()->getTemplateName(),
3884 SpecTL.getTemplateNameLoc(),
3885 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003886 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003887 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003888
3889 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003890 Template);
3891 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003892 DependentTemplateSpecializationTypeLoc SpecTL =
3893 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003894
Douglas Gregor579c15f2011-03-02 18:32:08 +00003895 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003896 = getDerived().RebuildTemplateName(SS,
3897 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003898 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003899 ObjectType, UnqualLookup);
3900 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003901 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003902
3903 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003904 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003905 Template,
3906 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003907 } else {
3908 // Nothing special needs to be done for these.
3909 Result = getDerived().TransformType(TLB, TL);
3910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
3912 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003913 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor579c15f2011-03-02 18:32:08 +00003915 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3916}
3917
John McCall550e0c22009-10-21 00:40:46 +00003918template <class TyLoc> static inline
3919QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3920 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3921 NewT.setNameLoc(T.getNameLoc());
3922 return T.getType();
3923}
3924
John McCall550e0c22009-10-21 00:40:46 +00003925template<typename Derived>
3926QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003927 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003928 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3929 NewT.setBuiltinLoc(T.getBuiltinLoc());
3930 if (T.needsExtraLocalData())
3931 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3932 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003933}
Mike Stump11289f42009-09-09 15:08:12 +00003934
Douglas Gregord6ff3322009-08-04 16:50:30 +00003935template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003936QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003937 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003938 // FIXME: recurse?
3939 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003940}
Mike Stump11289f42009-09-09 15:08:12 +00003941
Reid Kleckner0503a872013-12-05 01:23:43 +00003942template <typename Derived>
3943QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3944 AdjustedTypeLoc TL) {
3945 // Adjustments applied during transformation are handled elsewhere.
3946 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3947}
3948
Douglas Gregord6ff3322009-08-04 16:50:30 +00003949template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003950QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3951 DecayedTypeLoc TL) {
3952 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3953 if (OriginalType.isNull())
3954 return QualType();
3955
3956 QualType Result = TL.getType();
3957 if (getDerived().AlwaysRebuild() ||
3958 OriginalType != TL.getOriginalLoc().getType())
3959 Result = SemaRef.Context.getDecayedType(OriginalType);
3960 TLB.push<DecayedTypeLoc>(Result);
3961 // Nothing to set for DecayedTypeLoc.
3962 return Result;
3963}
3964
3965template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003966QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003967 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003968 QualType PointeeType
3969 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003970 if (PointeeType.isNull())
3971 return QualType();
3972
3973 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003974 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003975 // A dependent pointer type 'T *' has is being transformed such
3976 // that an Objective-C class type is being replaced for 'T'. The
3977 // resulting pointer type is an ObjCObjectPointerType, not a
3978 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003979 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003980
John McCall8b07ec22010-05-15 11:32:37 +00003981 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3982 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003983 return Result;
3984 }
John McCall31f82722010-11-12 08:19:04 +00003985
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003986 if (getDerived().AlwaysRebuild() ||
3987 PointeeType != TL.getPointeeLoc().getType()) {
3988 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3989 if (Result.isNull())
3990 return QualType();
3991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003992
John McCall31168b02011-06-15 23:02:42 +00003993 // Objective-C ARC can add lifetime qualifiers to the type that we're
3994 // pointing to.
3995 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00003996
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003997 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3998 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00003999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004000}
Mike Stump11289f42009-09-09 15:08:12 +00004001
4002template<typename Derived>
4003QualType
John McCall550e0c22009-10-21 00:40:46 +00004004TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004005 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004006 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004007 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4008 if (PointeeType.isNull())
4009 return QualType();
4010
4011 QualType Result = TL.getType();
4012 if (getDerived().AlwaysRebuild() ||
4013 PointeeType != TL.getPointeeLoc().getType()) {
4014 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004015 TL.getSigilLoc());
4016 if (Result.isNull())
4017 return QualType();
4018 }
4019
Douglas Gregor049211a2010-04-22 16:50:51 +00004020 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004021 NewT.setSigilLoc(TL.getSigilLoc());
4022 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004023}
4024
John McCall70dd5f62009-10-30 00:06:24 +00004025/// Transforms a reference type. Note that somewhat paradoxically we
4026/// don't care whether the type itself is an l-value type or an r-value
4027/// type; we only care if the type was *written* as an l-value type
4028/// or an r-value type.
4029template<typename Derived>
4030QualType
4031TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004032 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004033 const ReferenceType *T = TL.getTypePtr();
4034
4035 // Note that this works with the pointee-as-written.
4036 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4037 if (PointeeType.isNull())
4038 return QualType();
4039
4040 QualType Result = TL.getType();
4041 if (getDerived().AlwaysRebuild() ||
4042 PointeeType != T->getPointeeTypeAsWritten()) {
4043 Result = getDerived().RebuildReferenceType(PointeeType,
4044 T->isSpelledAsLValue(),
4045 TL.getSigilLoc());
4046 if (Result.isNull())
4047 return QualType();
4048 }
4049
John McCall31168b02011-06-15 23:02:42 +00004050 // Objective-C ARC can add lifetime qualifiers to the type that we're
4051 // referring to.
4052 TLB.TypeWasModifiedSafely(
4053 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4054
John McCall70dd5f62009-10-30 00:06:24 +00004055 // r-value references can be rebuilt as l-value references.
4056 ReferenceTypeLoc NewTL;
4057 if (isa<LValueReferenceType>(Result))
4058 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4059 else
4060 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4061 NewTL.setSigilLoc(TL.getSigilLoc());
4062
4063 return Result;
4064}
4065
Mike Stump11289f42009-09-09 15:08:12 +00004066template<typename Derived>
4067QualType
John McCall550e0c22009-10-21 00:40:46 +00004068TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004069 LValueReferenceTypeLoc TL) {
4070 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071}
4072
Mike Stump11289f42009-09-09 15:08:12 +00004073template<typename Derived>
4074QualType
John McCall550e0c22009-10-21 00:40:46 +00004075TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004076 RValueReferenceTypeLoc TL) {
4077 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004078}
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004081QualType
John McCall550e0c22009-10-21 00:40:46 +00004082TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004083 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004084 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004085 if (PointeeType.isNull())
4086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004087
Abramo Bagnara509357842011-03-05 14:42:21 +00004088 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004089 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004090 if (OldClsTInfo) {
4091 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4092 if (!NewClsTInfo)
4093 return QualType();
4094 }
4095
4096 const MemberPointerType *T = TL.getTypePtr();
4097 QualType OldClsType = QualType(T->getClass(), 0);
4098 QualType NewClsType;
4099 if (NewClsTInfo)
4100 NewClsType = NewClsTInfo->getType();
4101 else {
4102 NewClsType = getDerived().TransformType(OldClsType);
4103 if (NewClsType.isNull())
4104 return QualType();
4105 }
Mike Stump11289f42009-09-09 15:08:12 +00004106
John McCall550e0c22009-10-21 00:40:46 +00004107 QualType Result = TL.getType();
4108 if (getDerived().AlwaysRebuild() ||
4109 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004110 NewClsType != OldClsType) {
4111 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004112 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004113 if (Result.isNull())
4114 return QualType();
4115 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116
Reid Kleckner0503a872013-12-05 01:23:43 +00004117 // If we had to adjust the pointee type when building a member pointer, make
4118 // sure to push TypeLoc info for it.
4119 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4120 if (MPT && PointeeType != MPT->getPointeeType()) {
4121 assert(isa<AdjustedType>(MPT->getPointeeType()));
4122 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4123 }
4124
John McCall550e0c22009-10-21 00:40:46 +00004125 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4126 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004127 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004128
4129 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130}
4131
Mike Stump11289f42009-09-09 15:08:12 +00004132template<typename Derived>
4133QualType
John McCall550e0c22009-10-21 00:40:46 +00004134TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004135 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004136 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004137 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138 if (ElementType.isNull())
4139 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004140
John McCall550e0c22009-10-21 00:40:46 +00004141 QualType Result = TL.getType();
4142 if (getDerived().AlwaysRebuild() ||
4143 ElementType != T->getElementType()) {
4144 Result = getDerived().RebuildConstantArrayType(ElementType,
4145 T->getSizeModifier(),
4146 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004147 T->getIndexTypeCVRQualifiers(),
4148 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004149 if (Result.isNull())
4150 return QualType();
4151 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004152
4153 // We might have either a ConstantArrayType or a VariableArrayType now:
4154 // a ConstantArrayType is allowed to have an element type which is a
4155 // VariableArrayType if the type is dependent. Fortunately, all array
4156 // types have the same location layout.
4157 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004158 NewTL.setLBracketLoc(TL.getLBracketLoc());
4159 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 Expr *Size = TL.getSizeExpr();
4162 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004163 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4164 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004165 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4166 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004167 }
4168 NewTL.setSizeExpr(Size);
4169
4170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregord6ff3322009-08-04 16:50:30 +00004173template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004175 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004176 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004177 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004178 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179 if (ElementType.isNull())
4180 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004181
John McCall550e0c22009-10-21 00:40:46 +00004182 QualType Result = TL.getType();
4183 if (getDerived().AlwaysRebuild() ||
4184 ElementType != T->getElementType()) {
4185 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004187 T->getIndexTypeCVRQualifiers(),
4188 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004189 if (Result.isNull())
4190 return QualType();
4191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004192
John McCall550e0c22009-10-21 00:40:46 +00004193 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4194 NewTL.setLBracketLoc(TL.getLBracketLoc());
4195 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004196 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004197
4198 return Result;
4199}
4200
4201template<typename Derived>
4202QualType
4203TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004204 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004205 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004206 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4207 if (ElementType.isNull())
4208 return QualType();
4209
John McCalldadc5752010-08-24 06:29:42 +00004210 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004211 = getDerived().TransformExpr(T->getSizeExpr());
4212 if (SizeResult.isInvalid())
4213 return QualType();
4214
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004215 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004216
4217 QualType Result = TL.getType();
4218 if (getDerived().AlwaysRebuild() ||
4219 ElementType != T->getElementType() ||
4220 Size != T->getSizeExpr()) {
4221 Result = getDerived().RebuildVariableArrayType(ElementType,
4222 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004223 Size,
John McCall550e0c22009-10-21 00:40:46 +00004224 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004225 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004226 if (Result.isNull())
4227 return QualType();
4228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004229
Serge Pavlov774c6d02014-02-06 03:49:11 +00004230 // We might have constant size array now, but fortunately it has the same
4231 // location layout.
4232 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004233 NewTL.setLBracketLoc(TL.getLBracketLoc());
4234 NewTL.setRBracketLoc(TL.getRBracketLoc());
4235 NewTL.setSizeExpr(Size);
4236
4237 return Result;
4238}
4239
4240template<typename Derived>
4241QualType
4242TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004243 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004244 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004245 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4246 if (ElementType.isNull())
4247 return QualType();
4248
Richard Smith764d2fe2011-12-20 02:08:33 +00004249 // Array bounds are constant expressions.
4250 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4251 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004252
John McCall33ddac02011-01-19 10:06:00 +00004253 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4254 Expr *origSize = TL.getSizeExpr();
4255 if (!origSize) origSize = T->getSizeExpr();
4256
4257 ExprResult sizeResult
4258 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004259 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004260 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004261 return QualType();
4262
John McCall33ddac02011-01-19 10:06:00 +00004263 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004264
4265 QualType Result = TL.getType();
4266 if (getDerived().AlwaysRebuild() ||
4267 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004268 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004269 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4270 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004271 size,
John McCall550e0c22009-10-21 00:40:46 +00004272 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004273 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004274 if (Result.isNull())
4275 return QualType();
4276 }
John McCall550e0c22009-10-21 00:40:46 +00004277
4278 // We might have any sort of array type now, but fortunately they
4279 // all have the same location layout.
4280 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4281 NewTL.setLBracketLoc(TL.getLBracketLoc());
4282 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004283 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004284
4285 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
4288template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004289QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004290 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004291 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004292 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004293
4294 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004295 QualType ElementType = getDerived().TransformType(T->getElementType());
4296 if (ElementType.isNull())
4297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004298
Richard Smith764d2fe2011-12-20 02:08:33 +00004299 // Vector sizes are constant expressions.
4300 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4301 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004302
John McCalldadc5752010-08-24 06:29:42 +00004303 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004304 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004305 if (Size.isInvalid())
4306 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004307
John McCall550e0c22009-10-21 00:40:46 +00004308 QualType Result = TL.getType();
4309 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004310 ElementType != T->getElementType() ||
4311 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004312 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004313 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004315 if (Result.isNull())
4316 return QualType();
4317 }
John McCall550e0c22009-10-21 00:40:46 +00004318
4319 // Result might be dependent or not.
4320 if (isa<DependentSizedExtVectorType>(Result)) {
4321 DependentSizedExtVectorTypeLoc NewTL
4322 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4323 NewTL.setNameLoc(TL.getNameLoc());
4324 } else {
4325 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4326 NewTL.setNameLoc(TL.getNameLoc());
4327 }
4328
4329 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004330}
Mike Stump11289f42009-09-09 15:08:12 +00004331
4332template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004333QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004334 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004335 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336 QualType ElementType = getDerived().TransformType(T->getElementType());
4337 if (ElementType.isNull())
4338 return QualType();
4339
John McCall550e0c22009-10-21 00:40:46 +00004340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() ||
4342 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004343 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004344 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004345 if (Result.isNull())
4346 return QualType();
4347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004348
John McCall550e0c22009-10-21 00:40:46 +00004349 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4350 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004351
John McCall550e0c22009-10-21 00:40:46 +00004352 return Result;
4353}
4354
4355template<typename Derived>
4356QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004357 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004358 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004359 QualType ElementType = getDerived().TransformType(T->getElementType());
4360 if (ElementType.isNull())
4361 return QualType();
4362
4363 QualType Result = TL.getType();
4364 if (getDerived().AlwaysRebuild() ||
4365 ElementType != T->getElementType()) {
4366 Result = getDerived().RebuildExtVectorType(ElementType,
4367 T->getNumElements(),
4368 /*FIXME*/ SourceLocation());
4369 if (Result.isNull())
4370 return QualType();
4371 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004372
John McCall550e0c22009-10-21 00:40:46 +00004373 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4374 NewTL.setNameLoc(TL.getNameLoc());
4375
4376 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004377}
Mike Stump11289f42009-09-09 15:08:12 +00004378
David Blaikie05785d12013-02-20 22:23:23 +00004379template <typename Derived>
4380ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4381 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4382 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004383 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004384 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004385
Douglas Gregor715e4612011-01-14 22:40:04 +00004386 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004387 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004388 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004389 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004390 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004391
Douglas Gregor715e4612011-01-14 22:40:04 +00004392 TypeLocBuilder TLB;
4393 TypeLoc NewTL = OldDI->getTypeLoc();
4394 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004395
4396 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004397 OldExpansionTL.getPatternLoc());
4398 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004399 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004400
4401 Result = RebuildPackExpansionType(Result,
4402 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004403 OldExpansionTL.getEllipsisLoc(),
4404 NumExpansions);
4405 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004406 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregor715e4612011-01-14 22:40:04 +00004408 PackExpansionTypeLoc NewExpansionTL
4409 = TLB.push<PackExpansionTypeLoc>(Result);
4410 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4411 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4412 } else
4413 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004414 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004415 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004416
John McCall8fb0d9d2011-05-01 22:35:37 +00004417 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004418 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004419
4420 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4421 OldParm->getDeclContext(),
4422 OldParm->getInnerLocStart(),
4423 OldParm->getLocation(),
4424 OldParm->getIdentifier(),
4425 NewDI->getType(),
4426 NewDI,
4427 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004428 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004429 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4430 OldParm->getFunctionScopeIndex() + indexAdjustment);
4431 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004432}
4433
4434template<typename Derived>
4435bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004436 TransformFunctionTypeParams(SourceLocation Loc,
4437 ParmVarDecl **Params, unsigned NumParams,
4438 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004439 SmallVectorImpl<QualType> &OutParamTypes,
4440 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004441 int indexAdjustment = 0;
4442
Douglas Gregordd472162011-01-07 00:20:55 +00004443 for (unsigned i = 0; i != NumParams; ++i) {
4444 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004445 assert(OldParm->getFunctionScopeIndex() == i);
4446
David Blaikie05785d12013-02-20 22:23:23 +00004447 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004448 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004449 if (OldParm->isParameterPack()) {
4450 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004451 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004452
Douglas Gregor5499af42011-01-05 23:12:31 +00004453 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004454 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004455 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004456 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4457 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004458 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4459
Douglas Gregor5499af42011-01-05 23:12:31 +00004460 // Determine whether we should expand the parameter packs.
4461 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004462 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004463 Optional<unsigned> OrigNumExpansions =
4464 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004465 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004466 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4467 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004468 Unexpanded,
4469 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004470 RetainExpansion,
4471 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004472 return true;
4473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004474
Douglas Gregor5499af42011-01-05 23:12:31 +00004475 if (ShouldExpand) {
4476 // Expand the function parameter pack into multiple, separate
4477 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004478 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004479 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004481 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004482 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004483 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004484 OrigNumExpansions,
4485 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004486 if (!NewParm)
4487 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
Douglas Gregordd472162011-01-07 00:20:55 +00004489 OutParamTypes.push_back(NewParm->getType());
4490 if (PVars)
4491 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004492 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004493
4494 // If we're supposed to retain a pack expansion, do so by temporarily
4495 // forgetting the partially-substituted parameter pack.
4496 if (RetainExpansion) {
4497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004498 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004499 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004500 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004501 OrigNumExpansions,
4502 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004503 if (!NewParm)
4504 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004505
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004506 OutParamTypes.push_back(NewParm->getType());
4507 if (PVars)
4508 PVars->push_back(NewParm);
4509 }
4510
John McCall8fb0d9d2011-05-01 22:35:37 +00004511 // The next parameter should have the same adjustment as the
4512 // last thing we pushed, but we post-incremented indexAdjustment
4513 // on every push. Also, if we push nothing, the adjustment should
4514 // go down by one.
4515 indexAdjustment--;
4516
Douglas Gregor5499af42011-01-05 23:12:31 +00004517 // We're done with the pack expansion.
4518 continue;
4519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004520
4521 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004522 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004523 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4524 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004525 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004526 NumExpansions,
4527 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004528 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004529 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004530 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004532
John McCall58f10c32010-03-11 09:03:00 +00004533 if (!NewParm)
4534 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004535
Douglas Gregordd472162011-01-07 00:20:55 +00004536 OutParamTypes.push_back(NewParm->getType());
4537 if (PVars)
4538 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004539 continue;
4540 }
John McCall58f10c32010-03-11 09:03:00 +00004541
4542 // Deal with the possibility that we don't have a parameter
4543 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004544 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004546 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004547 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004548 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004549 = dyn_cast<PackExpansionType>(OldType)) {
4550 // We have a function parameter pack that may need to be expanded.
4551 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004552 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004553 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004554
Douglas Gregor5499af42011-01-05 23:12:31 +00004555 // Determine whether we should expand the parameter packs.
4556 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004557 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004558 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004559 Unexpanded,
4560 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004561 RetainExpansion,
4562 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004563 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004565
Douglas Gregor5499af42011-01-05 23:12:31 +00004566 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004567 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004568 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004569 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004570 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4571 QualType NewType = getDerived().TransformType(Pattern);
4572 if (NewType.isNull())
4573 return true;
John McCall58f10c32010-03-11 09:03:00 +00004574
Douglas Gregordd472162011-01-07 00:20:55 +00004575 OutParamTypes.push_back(NewType);
4576 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004577 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004579
Douglas Gregor5499af42011-01-05 23:12:31 +00004580 // We're done with the pack expansion.
4581 continue;
4582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004583
Douglas Gregor48d24112011-01-10 20:53:55 +00004584 // If we're supposed to retain a pack expansion, do so by temporarily
4585 // forgetting the partially-substituted parameter pack.
4586 if (RetainExpansion) {
4587 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4588 QualType NewType = getDerived().TransformType(Pattern);
4589 if (NewType.isNull())
4590 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004591
Douglas Gregor48d24112011-01-10 20:53:55 +00004592 OutParamTypes.push_back(NewType);
4593 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004594 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004595 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004596
Chad Rosier1dcde962012-08-08 18:46:20 +00004597 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004598 // expansion.
4599 OldType = Expansion->getPattern();
4600 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004601 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4602 NewType = getDerived().TransformType(OldType);
4603 } else {
4604 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004605 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004606
Douglas Gregor5499af42011-01-05 23:12:31 +00004607 if (NewType.isNull())
4608 return true;
4609
4610 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004611 NewType = getSema().Context.getPackExpansionType(NewType,
4612 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004613
Douglas Gregordd472162011-01-07 00:20:55 +00004614 OutParamTypes.push_back(NewType);
4615 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004616 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004617 }
4618
John McCall8fb0d9d2011-05-01 22:35:37 +00004619#ifndef NDEBUG
4620 if (PVars) {
4621 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4622 if (ParmVarDecl *parm = (*PVars)[i])
4623 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004624 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004625#endif
4626
4627 return false;
4628}
John McCall58f10c32010-03-11 09:03:00 +00004629
4630template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004631QualType
John McCall550e0c22009-10-21 00:40:46 +00004632TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004633 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004634 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004635 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004636 return getDerived().TransformFunctionProtoType(
4637 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004638 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4639 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4640 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004641 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004642}
4643
Richard Smith2e321552014-11-12 02:00:47 +00004644template<typename Derived> template<typename Fn>
4645QualType TreeTransform<Derived>::TransformFunctionProtoType(
4646 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4647 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004648 // Transform the parameters and return type.
4649 //
Richard Smithf623c962012-04-17 00:58:00 +00004650 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004651 // When the function has a trailing return type, we instantiate the
4652 // parameters before the return type, since the return type can then refer
4653 // to the parameters themselves (via decltype, sizeof, etc.).
4654 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004655 SmallVector<QualType, 4> ParamTypes;
4656 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004657 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004658
Douglas Gregor7fb25412010-10-01 18:44:50 +00004659 QualType ResultType;
4660
Richard Smith1226c602012-08-14 22:51:13 +00004661 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004662 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004663 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004664 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004665 return QualType();
4666
Douglas Gregor3024f072012-04-16 07:05:22 +00004667 {
4668 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004669 // If a declaration declares a member function or member function
4670 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004671 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004672 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004673 // declarator.
4674 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004675
Alp Toker42a16a62014-01-25 23:51:36 +00004676 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004677 if (ResultType.isNull())
4678 return QualType();
4679 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004680 }
4681 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004682 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004683 if (ResultType.isNull())
4684 return QualType();
4685
Alp Toker9cacbab2014-01-20 20:26:09 +00004686 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004687 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004688 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004689 return QualType();
4690 }
4691
Richard Smith2e321552014-11-12 02:00:47 +00004692 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4693
4694 bool EPIChanged = false;
4695 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4696 return QualType();
4697
4698 // FIXME: Need to transform ConsumedParameters for variadic template
4699 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004700
John McCall550e0c22009-10-21 00:40:46 +00004701 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004702 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Alp Toker9cacbab2014-01-20 20:26:09 +00004703 T->getNumParams() != ParamTypes.size() ||
4704 !std::equal(T->param_type_begin(), T->param_type_end(),
Richard Smith2e321552014-11-12 02:00:47 +00004705 ParamTypes.begin()) || EPIChanged) {
4706 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004707 if (Result.isNull())
4708 return QualType();
4709 }
Mike Stump11289f42009-09-09 15:08:12 +00004710
John McCall550e0c22009-10-21 00:40:46 +00004711 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004712 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004713 NewTL.setLParenLoc(TL.getLParenLoc());
4714 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004715 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004716 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4717 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004718
4719 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregord6ff3322009-08-04 16:50:30 +00004722template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004723bool TreeTransform<Derived>::TransformExceptionSpec(
4724 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4725 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4726 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4727
4728 // Instantiate a dynamic noexcept expression, if any.
4729 if (ESI.Type == EST_ComputedNoexcept) {
4730 EnterExpressionEvaluationContext Unevaluated(getSema(),
4731 Sema::ConstantEvaluated);
4732 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4733 if (NoexceptExpr.isInvalid())
4734 return true;
4735
4736 NoexceptExpr = getSema().CheckBooleanCondition(
4737 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4738 if (NoexceptExpr.isInvalid())
4739 return true;
4740
4741 if (!NoexceptExpr.get()->isValueDependent()) {
4742 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4743 NoexceptExpr.get(), nullptr,
4744 diag::err_noexcept_needs_constant_expression,
4745 /*AllowFold*/false);
4746 if (NoexceptExpr.isInvalid())
4747 return true;
4748 }
4749
4750 if (ESI.NoexceptExpr != NoexceptExpr.get())
4751 Changed = true;
4752 ESI.NoexceptExpr = NoexceptExpr.get();
4753 }
4754
4755 if (ESI.Type != EST_Dynamic)
4756 return false;
4757
4758 // Instantiate a dynamic exception specification's type.
4759 for (QualType T : ESI.Exceptions) {
4760 if (const PackExpansionType *PackExpansion =
4761 T->getAs<PackExpansionType>()) {
4762 Changed = true;
4763
4764 // We have a pack expansion. Instantiate it.
4765 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4766 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4767 Unexpanded);
4768 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4769
4770 // Determine whether the set of unexpanded parameter packs can and
4771 // should
4772 // be expanded.
4773 bool Expand = false;
4774 bool RetainExpansion = false;
4775 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4776 // FIXME: Track the location of the ellipsis (and track source location
4777 // information for the types in the exception specification in general).
4778 if (getDerived().TryExpandParameterPacks(
4779 Loc, SourceRange(), Unexpanded, Expand,
4780 RetainExpansion, NumExpansions))
4781 return true;
4782
4783 if (!Expand) {
4784 // We can't expand this pack expansion into separate arguments yet;
4785 // just substitute into the pattern and create a new pack expansion
4786 // type.
4787 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4788 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4789 if (U.isNull())
4790 return true;
4791
4792 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4793 Exceptions.push_back(U);
4794 continue;
4795 }
4796
4797 // Substitute into the pack expansion pattern for each slice of the
4798 // pack.
4799 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4800 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4801
4802 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4803 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4804 return true;
4805
4806 Exceptions.push_back(U);
4807 }
4808 } else {
4809 QualType U = getDerived().TransformType(T);
4810 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4811 return true;
4812 if (T != U)
4813 Changed = true;
4814
4815 Exceptions.push_back(U);
4816 }
4817 }
4818
4819 ESI.Exceptions = Exceptions;
4820 return false;
4821}
4822
4823template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004824QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004825 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004826 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004827 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004828 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004829 if (ResultType.isNull())
4830 return QualType();
4831
4832 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004833 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004834 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4835
4836 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004837 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004838 NewTL.setLParenLoc(TL.getLParenLoc());
4839 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004840 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004841
4842 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004843}
Mike Stump11289f42009-09-09 15:08:12 +00004844
John McCallb96ec562009-12-04 22:46:56 +00004845template<typename Derived> QualType
4846TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004847 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004848 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004849 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004850 if (!D)
4851 return QualType();
4852
4853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4855 Result = getDerived().RebuildUnresolvedUsingType(D);
4856 if (Result.isNull())
4857 return QualType();
4858 }
4859
4860 // We might get an arbitrary type spec type back. We should at
4861 // least always get a type spec type, though.
4862 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4863 NewTL.setNameLoc(TL.getNameLoc());
4864
4865 return Result;
4866}
4867
Douglas Gregord6ff3322009-08-04 16:50:30 +00004868template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004869QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004870 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004871 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004872 TypedefNameDecl *Typedef
4873 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4874 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004875 if (!Typedef)
4876 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004877
John McCall550e0c22009-10-21 00:40:46 +00004878 QualType Result = TL.getType();
4879 if (getDerived().AlwaysRebuild() ||
4880 Typedef != T->getDecl()) {
4881 Result = getDerived().RebuildTypedefType(Typedef);
4882 if (Result.isNull())
4883 return QualType();
4884 }
Mike Stump11289f42009-09-09 15:08:12 +00004885
John McCall550e0c22009-10-21 00:40:46 +00004886 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4887 NewTL.setNameLoc(TL.getNameLoc());
4888
4889 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004890}
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004893QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004894 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004895 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004896 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4897 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004898
John McCalldadc5752010-08-24 06:29:42 +00004899 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004900 if (E.isInvalid())
4901 return QualType();
4902
Eli Friedmane4f22df2012-02-29 04:03:55 +00004903 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4904 if (E.isInvalid())
4905 return QualType();
4906
John McCall550e0c22009-10-21 00:40:46 +00004907 QualType Result = TL.getType();
4908 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004909 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004910 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004911 if (Result.isNull())
4912 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004913 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004914 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall550e0c22009-10-21 00:40:46 +00004916 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004917 NewTL.setTypeofLoc(TL.getTypeofLoc());
4918 NewTL.setLParenLoc(TL.getLParenLoc());
4919 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004920
4921 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004922}
Mike Stump11289f42009-09-09 15:08:12 +00004923
4924template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004925QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004926 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004927 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4928 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4929 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004930 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004931
John McCall550e0c22009-10-21 00:40:46 +00004932 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004933 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4934 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004935 if (Result.isNull())
4936 return QualType();
4937 }
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCall550e0c22009-10-21 00:40:46 +00004939 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004940 NewTL.setTypeofLoc(TL.getTypeofLoc());
4941 NewTL.setLParenLoc(TL.getLParenLoc());
4942 NewTL.setRParenLoc(TL.getRParenLoc());
4943 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004944
4945 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004946}
Mike Stump11289f42009-09-09 15:08:12 +00004947
4948template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004949QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004950 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004951 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004952
Douglas Gregore922c772009-08-04 22:27:00 +00004953 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004954 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4955 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004956
John McCalldadc5752010-08-24 06:29:42 +00004957 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004958 if (E.isInvalid())
4959 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004960
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004961 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004962 if (E.isInvalid())
4963 return QualType();
4964
John McCall550e0c22009-10-21 00:40:46 +00004965 QualType Result = TL.getType();
4966 if (getDerived().AlwaysRebuild() ||
4967 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004968 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004969 if (Result.isNull())
4970 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004971 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004972 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004973
John McCall550e0c22009-10-21 00:40:46 +00004974 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4975 NewTL.setNameLoc(TL.getNameLoc());
4976
4977 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004978}
4979
4980template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004981QualType TreeTransform<Derived>::TransformUnaryTransformType(
4982 TypeLocBuilder &TLB,
4983 UnaryTransformTypeLoc TL) {
4984 QualType Result = TL.getType();
4985 if (Result->isDependentType()) {
4986 const UnaryTransformType *T = TL.getTypePtr();
4987 QualType NewBase =
4988 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4989 Result = getDerived().RebuildUnaryTransformType(NewBase,
4990 T->getUTTKind(),
4991 TL.getKWLoc());
4992 if (Result.isNull())
4993 return QualType();
4994 }
4995
4996 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4997 NewTL.setKWLoc(TL.getKWLoc());
4998 NewTL.setParensRange(TL.getParensRange());
4999 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5000 return Result;
5001}
5002
5003template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005004QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5005 AutoTypeLoc TL) {
5006 const AutoType *T = TL.getTypePtr();
5007 QualType OldDeduced = T->getDeducedType();
5008 QualType NewDeduced;
5009 if (!OldDeduced.isNull()) {
5010 NewDeduced = getDerived().TransformType(OldDeduced);
5011 if (NewDeduced.isNull())
5012 return QualType();
5013 }
5014
5015 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005016 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5017 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005018 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005019 if (Result.isNull())
5020 return QualType();
5021 }
5022
5023 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5024 NewTL.setNameLoc(TL.getNameLoc());
5025
5026 return Result;
5027}
5028
5029template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005030QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005031 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005032 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005033 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005034 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5035 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005036 if (!Record)
5037 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005038
John McCall550e0c22009-10-21 00:40:46 +00005039 QualType Result = TL.getType();
5040 if (getDerived().AlwaysRebuild() ||
5041 Record != T->getDecl()) {
5042 Result = getDerived().RebuildRecordType(Record);
5043 if (Result.isNull())
5044 return QualType();
5045 }
Mike Stump11289f42009-09-09 15:08:12 +00005046
John McCall550e0c22009-10-21 00:40:46 +00005047 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5048 NewTL.setNameLoc(TL.getNameLoc());
5049
5050 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005051}
Mike Stump11289f42009-09-09 15:08:12 +00005052
5053template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005054QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005055 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005056 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005057 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005058 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5059 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060 if (!Enum)
5061 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005062
John McCall550e0c22009-10-21 00:40:46 +00005063 QualType Result = TL.getType();
5064 if (getDerived().AlwaysRebuild() ||
5065 Enum != T->getDecl()) {
5066 Result = getDerived().RebuildEnumType(Enum);
5067 if (Result.isNull())
5068 return QualType();
5069 }
Mike Stump11289f42009-09-09 15:08:12 +00005070
John McCall550e0c22009-10-21 00:40:46 +00005071 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5072 NewTL.setNameLoc(TL.getNameLoc());
5073
5074 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005075}
John McCallfcc33b02009-09-05 00:15:47 +00005076
John McCalle78aac42010-03-10 03:28:59 +00005077template<typename Derived>
5078QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5079 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005080 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005081 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5082 TL.getTypePtr()->getDecl());
5083 if (!D) return QualType();
5084
5085 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5086 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5087 return T;
5088}
5089
Douglas Gregord6ff3322009-08-04 16:50:30 +00005090template<typename Derived>
5091QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005092 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005093 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005094 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005095}
5096
Mike Stump11289f42009-09-09 15:08:12 +00005097template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005098QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005099 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005100 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005101 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005102
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005103 // Substitute into the replacement type, which itself might involve something
5104 // that needs to be transformed. This only tends to occur with default
5105 // template arguments of template template parameters.
5106 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5107 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5108 if (Replacement.isNull())
5109 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005110
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005111 // Always canonicalize the replacement type.
5112 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5113 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005114 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005115 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005117 // Propagate type-source information.
5118 SubstTemplateTypeParmTypeLoc NewTL
5119 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5120 NewTL.setNameLoc(TL.getNameLoc());
5121 return Result;
5122
John McCallcebee162009-10-18 09:09:24 +00005123}
5124
5125template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005126QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5127 TypeLocBuilder &TLB,
5128 SubstTemplateTypeParmPackTypeLoc TL) {
5129 return TransformTypeSpecType(TLB, TL);
5130}
5131
5132template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005133QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005134 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005135 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005136 const TemplateSpecializationType *T = TL.getTypePtr();
5137
Douglas Gregordf846d12011-03-02 18:46:51 +00005138 // The nested-name-specifier never matters in a TemplateSpecializationType,
5139 // because we can't have a dependent nested-name-specifier anyway.
5140 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005141 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005142 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5143 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005144 if (Template.isNull())
5145 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005146
John McCall31f82722010-11-12 08:19:04 +00005147 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5148}
5149
Eli Friedman0dfb8892011-10-06 23:00:33 +00005150template<typename Derived>
5151QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5152 AtomicTypeLoc TL) {
5153 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5154 if (ValueType.isNull())
5155 return QualType();
5156
5157 QualType Result = TL.getType();
5158 if (getDerived().AlwaysRebuild() ||
5159 ValueType != TL.getValueLoc().getType()) {
5160 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5161 if (Result.isNull())
5162 return QualType();
5163 }
5164
5165 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5166 NewTL.setKWLoc(TL.getKWLoc());
5167 NewTL.setLParenLoc(TL.getLParenLoc());
5168 NewTL.setRParenLoc(TL.getRParenLoc());
5169
5170 return Result;
5171}
5172
Chad Rosier1dcde962012-08-08 18:46:20 +00005173 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005174 /// container that provides a \c getArgLoc() member function.
5175 ///
5176 /// This iterator is intended to be used with the iterator form of
5177 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5178 template<typename ArgLocContainer>
5179 class TemplateArgumentLocContainerIterator {
5180 ArgLocContainer *Container;
5181 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005182
Douglas Gregorfe921a72010-12-20 23:36:19 +00005183 public:
5184 typedef TemplateArgumentLoc value_type;
5185 typedef TemplateArgumentLoc reference;
5186 typedef int difference_type;
5187 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005188
Douglas Gregorfe921a72010-12-20 23:36:19 +00005189 class pointer {
5190 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005191
Douglas Gregorfe921a72010-12-20 23:36:19 +00005192 public:
5193 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005194
Douglas Gregorfe921a72010-12-20 23:36:19 +00005195 const TemplateArgumentLoc *operator->() const {
5196 return &Arg;
5197 }
5198 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005199
5200
Douglas Gregorfe921a72010-12-20 23:36:19 +00005201 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
Douglas Gregorfe921a72010-12-20 23:36:19 +00005203 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5204 unsigned Index)
5205 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
Douglas Gregorfe921a72010-12-20 23:36:19 +00005207 TemplateArgumentLocContainerIterator &operator++() {
5208 ++Index;
5209 return *this;
5210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005211
Douglas Gregorfe921a72010-12-20 23:36:19 +00005212 TemplateArgumentLocContainerIterator operator++(int) {
5213 TemplateArgumentLocContainerIterator Old(*this);
5214 ++(*this);
5215 return Old;
5216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005217
Douglas Gregorfe921a72010-12-20 23:36:19 +00005218 TemplateArgumentLoc operator*() const {
5219 return Container->getArgLoc(Index);
5220 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005221
Douglas Gregorfe921a72010-12-20 23:36:19 +00005222 pointer operator->() const {
5223 return pointer(Container->getArgLoc(Index));
5224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
Douglas Gregorfe921a72010-12-20 23:36:19 +00005226 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005227 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005228 return X.Container == Y.Container && X.Index == Y.Index;
5229 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005230
Douglas Gregorfe921a72010-12-20 23:36:19 +00005231 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005232 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005233 return !(X == Y);
5234 }
5235 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005236
5237
John McCall31f82722010-11-12 08:19:04 +00005238template <typename Derived>
5239QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5240 TypeLocBuilder &TLB,
5241 TemplateSpecializationTypeLoc TL,
5242 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005243 TemplateArgumentListInfo NewTemplateArgs;
5244 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5245 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005246 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5247 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005248 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005249 ArgIterator(TL, TL.getNumArgs()),
5250 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005251 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005252
John McCall0ad16662009-10-29 08:12:44 +00005253 // FIXME: maybe don't rebuild if all the template arguments are the same.
5254
5255 QualType Result =
5256 getDerived().RebuildTemplateSpecializationType(Template,
5257 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005258 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005259
5260 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005261 // Specializations of template template parameters are represented as
5262 // TemplateSpecializationTypes, and substitution of type alias templates
5263 // within a dependent context can transform them into
5264 // DependentTemplateSpecializationTypes.
5265 if (isa<DependentTemplateSpecializationType>(Result)) {
5266 DependentTemplateSpecializationTypeLoc NewTL
5267 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005268 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005269 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005270 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005271 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005272 NewTL.setLAngleLoc(TL.getLAngleLoc());
5273 NewTL.setRAngleLoc(TL.getRAngleLoc());
5274 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5275 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5276 return Result;
5277 }
5278
John McCall0ad16662009-10-29 08:12:44 +00005279 TemplateSpecializationTypeLoc NewTL
5280 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005281 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005282 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5283 NewTL.setLAngleLoc(TL.getLAngleLoc());
5284 NewTL.setRAngleLoc(TL.getRAngleLoc());
5285 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5286 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005287 }
Mike Stump11289f42009-09-09 15:08:12 +00005288
John McCall0ad16662009-10-29 08:12:44 +00005289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005290}
Mike Stump11289f42009-09-09 15:08:12 +00005291
Douglas Gregor5a064722011-02-28 17:23:35 +00005292template <typename Derived>
5293QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5294 TypeLocBuilder &TLB,
5295 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005296 TemplateName Template,
5297 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005298 TemplateArgumentListInfo NewTemplateArgs;
5299 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5300 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5301 typedef TemplateArgumentLocContainerIterator<
5302 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005303 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005304 ArgIterator(TL, TL.getNumArgs()),
5305 NewTemplateArgs))
5306 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005307
Douglas Gregor5a064722011-02-28 17:23:35 +00005308 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005309
Douglas Gregor5a064722011-02-28 17:23:35 +00005310 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5311 QualType Result
5312 = getSema().Context.getDependentTemplateSpecializationType(
5313 TL.getTypePtr()->getKeyword(),
5314 DTN->getQualifier(),
5315 DTN->getIdentifier(),
5316 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005317
Douglas Gregor5a064722011-02-28 17:23:35 +00005318 DependentTemplateSpecializationTypeLoc NewTL
5319 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005321 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005322 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005323 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005324 NewTL.setLAngleLoc(TL.getLAngleLoc());
5325 NewTL.setRAngleLoc(TL.getRAngleLoc());
5326 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5327 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5328 return Result;
5329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005330
5331 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005332 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005333 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005334 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005335
Douglas Gregor5a064722011-02-28 17:23:35 +00005336 if (!Result.isNull()) {
5337 /// FIXME: Wrap this in an elaborated-type-specifier?
5338 TemplateSpecializationTypeLoc NewTL
5339 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005340 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005341 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005342 NewTL.setLAngleLoc(TL.getLAngleLoc());
5343 NewTL.setRAngleLoc(TL.getRAngleLoc());
5344 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5345 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
Douglas Gregor5a064722011-02-28 17:23:35 +00005348 return Result;
5349}
5350
Mike Stump11289f42009-09-09 15:08:12 +00005351template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005352QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005353TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005354 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005355 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005356
Douglas Gregor844cb502011-03-01 18:12:44 +00005357 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005358 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005359 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005360 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005361 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5362 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005363 return QualType();
5364 }
Mike Stump11289f42009-09-09 15:08:12 +00005365
John McCall31f82722010-11-12 08:19:04 +00005366 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5367 if (NamedT.isNull())
5368 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005369
Richard Smith3f1b5d02011-05-05 21:57:07 +00005370 // C++0x [dcl.type.elab]p2:
5371 // If the identifier resolves to a typedef-name or the simple-template-id
5372 // resolves to an alias template specialization, the
5373 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005374 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5375 if (const TemplateSpecializationType *TST =
5376 NamedT->getAs<TemplateSpecializationType>()) {
5377 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005378 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5379 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005380 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5381 diag::err_tag_reference_non_tag) << 4;
5382 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5383 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005384 }
5385 }
5386
John McCall550e0c22009-10-21 00:40:46 +00005387 QualType Result = TL.getType();
5388 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005389 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005390 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005391 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005392 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005393 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005394 if (Result.isNull())
5395 return QualType();
5396 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005397
Abramo Bagnara6150c882010-05-11 21:36:43 +00005398 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005399 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005400 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005401 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
5404template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005405QualType TreeTransform<Derived>::TransformAttributedType(
5406 TypeLocBuilder &TLB,
5407 AttributedTypeLoc TL) {
5408 const AttributedType *oldType = TL.getTypePtr();
5409 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5410 if (modifiedType.isNull())
5411 return QualType();
5412
5413 QualType result = TL.getType();
5414
5415 // FIXME: dependent operand expressions?
5416 if (getDerived().AlwaysRebuild() ||
5417 modifiedType != oldType->getModifiedType()) {
5418 // TODO: this is really lame; we should really be rebuilding the
5419 // equivalent type from first principles.
5420 QualType equivalentType
5421 = getDerived().TransformType(oldType->getEquivalentType());
5422 if (equivalentType.isNull())
5423 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005424
5425 // Check whether we can add nullability; it is only represented as
5426 // type sugar, and therefore cannot be diagnosed in any other way.
5427 if (auto nullability = oldType->getImmediateNullability()) {
5428 if (!modifiedType->canHaveNullability()) {
5429 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005430 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005431 return QualType();
5432 }
5433 }
5434
John McCall81904512011-01-06 01:58:22 +00005435 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5436 modifiedType,
5437 equivalentType);
5438 }
5439
5440 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5441 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5442 if (TL.hasAttrOperand())
5443 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5444 if (TL.hasAttrExprOperand())
5445 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5446 else if (TL.hasAttrEnumOperand())
5447 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5448
5449 return result;
5450}
5451
5452template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005453QualType
5454TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5455 ParenTypeLoc TL) {
5456 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5457 if (Inner.isNull())
5458 return QualType();
5459
5460 QualType Result = TL.getType();
5461 if (getDerived().AlwaysRebuild() ||
5462 Inner != TL.getInnerLoc().getType()) {
5463 Result = getDerived().RebuildParenType(Inner);
5464 if (Result.isNull())
5465 return QualType();
5466 }
5467
5468 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5469 NewTL.setLParenLoc(TL.getLParenLoc());
5470 NewTL.setRParenLoc(TL.getRParenLoc());
5471 return Result;
5472}
5473
5474template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005475QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005476 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005477 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005478
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005479 NestedNameSpecifierLoc QualifierLoc
5480 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5481 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005482 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005483
John McCallc392f372010-06-11 00:33:02 +00005484 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005485 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005486 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005487 QualifierLoc,
5488 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005489 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005490 if (Result.isNull())
5491 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005492
Abramo Bagnarad7548482010-05-19 21:37:53 +00005493 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5494 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005495 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5496
Abramo Bagnarad7548482010-05-19 21:37:53 +00005497 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005498 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005499 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005500 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005501 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005502 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005503 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005504 NewTL.setNameLoc(TL.getNameLoc());
5505 }
John McCall550e0c22009-10-21 00:40:46 +00005506 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005507}
Mike Stump11289f42009-09-09 15:08:12 +00005508
Douglas Gregord6ff3322009-08-04 16:50:30 +00005509template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005510QualType TreeTransform<Derived>::
5511 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005512 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005513 NestedNameSpecifierLoc QualifierLoc;
5514 if (TL.getQualifierLoc()) {
5515 QualifierLoc
5516 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5517 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005518 return QualType();
5519 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005520
John McCall31f82722010-11-12 08:19:04 +00005521 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005522 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005523}
5524
5525template<typename Derived>
5526QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005527TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5528 DependentTemplateSpecializationTypeLoc TL,
5529 NestedNameSpecifierLoc QualifierLoc) {
5530 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005531
Douglas Gregora7a795b2011-03-01 20:11:18 +00005532 TemplateArgumentListInfo NewTemplateArgs;
5533 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5534 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005535
Douglas Gregora7a795b2011-03-01 20:11:18 +00005536 typedef TemplateArgumentLocContainerIterator<
5537 DependentTemplateSpecializationTypeLoc> ArgIterator;
5538 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5539 ArgIterator(TL, TL.getNumArgs()),
5540 NewTemplateArgs))
5541 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregora7a795b2011-03-01 20:11:18 +00005543 QualType Result
5544 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5545 QualifierLoc,
5546 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005547 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005548 NewTemplateArgs);
5549 if (Result.isNull())
5550 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005551
Douglas Gregora7a795b2011-03-01 20:11:18 +00005552 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5553 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005554
Douglas Gregora7a795b2011-03-01 20:11:18 +00005555 // Copy information relevant to the template specialization.
5556 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005557 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005558 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005559 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005560 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5561 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005562 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005563 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005564
Douglas Gregora7a795b2011-03-01 20:11:18 +00005565 // Copy information relevant to the elaborated type.
5566 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005567 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005568 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005569 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5570 DependentTemplateSpecializationTypeLoc SpecTL
5571 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005572 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005573 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005574 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005575 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005576 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5577 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005578 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005579 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005580 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005581 TemplateSpecializationTypeLoc SpecTL
5582 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005583 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005584 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005585 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5586 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005587 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005588 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005589 }
5590 return Result;
5591}
5592
5593template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005594QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5595 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005596 QualType Pattern
5597 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005598 if (Pattern.isNull())
5599 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005600
5601 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005602 if (getDerived().AlwaysRebuild() ||
5603 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005604 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005605 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005606 TL.getEllipsisLoc(),
5607 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005608 if (Result.isNull())
5609 return QualType();
5610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005611
Douglas Gregor822d0302011-01-12 17:07:58 +00005612 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5613 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5614 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005615}
5616
5617template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005618QualType
5619TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005620 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005621 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005622 TLB.pushFullCopy(TL);
5623 return TL.getType();
5624}
5625
5626template<typename Derived>
5627QualType
5628TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005629 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005630 // Transform base type.
5631 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5632 if (BaseType.isNull())
5633 return QualType();
5634
5635 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5636
5637 // Transform type arguments.
5638 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5639 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5640 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5641 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5642 QualType TypeArg = TypeArgInfo->getType();
5643 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5644 AnyChanged = true;
5645
5646 // We have a pack expansion. Instantiate it.
5647 const auto *PackExpansion = PackExpansionLoc.getType()
5648 ->castAs<PackExpansionType>();
5649 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5650 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5651 Unexpanded);
5652 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5653
5654 // Determine whether the set of unexpanded parameter packs can
5655 // and should be expanded.
5656 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5657 bool Expand = false;
5658 bool RetainExpansion = false;
5659 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5660 if (getDerived().TryExpandParameterPacks(
5661 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5662 Unexpanded, Expand, RetainExpansion, NumExpansions))
5663 return QualType();
5664
5665 if (!Expand) {
5666 // We can't expand this pack expansion into separate arguments yet;
5667 // just substitute into the pattern and create a new pack expansion
5668 // type.
5669 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5670
5671 TypeLocBuilder TypeArgBuilder;
5672 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5673 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5674 PatternLoc);
5675 if (NewPatternType.isNull())
5676 return QualType();
5677
5678 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5679 NewPatternType, NumExpansions);
5680 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5681 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5682 NewTypeArgInfos.push_back(
5683 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5684 continue;
5685 }
5686
5687 // Substitute into the pack expansion pattern for each slice of the
5688 // pack.
5689 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5690 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5691
5692 TypeLocBuilder TypeArgBuilder;
5693 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5694
5695 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5696 PatternLoc);
5697 if (NewTypeArg.isNull())
5698 return QualType();
5699
5700 NewTypeArgInfos.push_back(
5701 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5702 }
5703
5704 continue;
5705 }
5706
5707 TypeLocBuilder TypeArgBuilder;
5708 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5709 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5710 if (NewTypeArg.isNull())
5711 return QualType();
5712
5713 // If nothing changed, just keep the old TypeSourceInfo.
5714 if (NewTypeArg == TypeArg) {
5715 NewTypeArgInfos.push_back(TypeArgInfo);
5716 continue;
5717 }
5718
5719 NewTypeArgInfos.push_back(
5720 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5721 AnyChanged = true;
5722 }
5723
5724 QualType Result = TL.getType();
5725 if (getDerived().AlwaysRebuild() || AnyChanged) {
5726 // Rebuild the type.
5727 Result = getDerived().RebuildObjCObjectType(
5728 BaseType,
5729 TL.getLocStart(),
5730 TL.getTypeArgsLAngleLoc(),
5731 NewTypeArgInfos,
5732 TL.getTypeArgsRAngleLoc(),
5733 TL.getProtocolLAngleLoc(),
5734 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5735 TL.getNumProtocols()),
5736 TL.getProtocolLocs(),
5737 TL.getProtocolRAngleLoc());
5738
5739 if (Result.isNull())
5740 return QualType();
5741 }
5742
5743 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5744 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5745 NewT.setHasBaseTypeAsWritten(true);
5746 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5747 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5748 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5749 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5750 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5751 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5752 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5753 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5754 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005755}
Mike Stump11289f42009-09-09 15:08:12 +00005756
5757template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005758QualType
5759TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005760 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005761 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5762 if (PointeeType.isNull())
5763 return QualType();
5764
5765 QualType Result = TL.getType();
5766 if (getDerived().AlwaysRebuild() ||
5767 PointeeType != TL.getPointeeLoc().getType()) {
5768 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5769 TL.getStarLoc());
5770 if (Result.isNull())
5771 return QualType();
5772 }
5773
5774 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5775 NewT.setStarLoc(TL.getStarLoc());
5776 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005777}
5778
Douglas Gregord6ff3322009-08-04 16:50:30 +00005779//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005780// Statement transformation
5781//===----------------------------------------------------------------------===//
5782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005783StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005784TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005785 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005786}
5787
5788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005789StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005790TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5791 return getDerived().TransformCompoundStmt(S, false);
5792}
5793
5794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005795StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005796TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005797 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005798 Sema::CompoundScopeRAII CompoundScope(getSema());
5799
John McCall1ababa62010-08-27 19:56:05 +00005800 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005801 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005802 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005803 for (auto *B : S->body()) {
5804 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005805 if (Result.isInvalid()) {
5806 // Immediately fail if this was a DeclStmt, since it's very
5807 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005808 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005809 return StmtError();
5810
5811 // Otherwise, just keep processing substatements and fail later.
5812 SubStmtInvalid = true;
5813 continue;
5814 }
Mike Stump11289f42009-09-09 15:08:12 +00005815
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005816 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005817 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 }
Mike Stump11289f42009-09-09 15:08:12 +00005819
John McCall1ababa62010-08-27 19:56:05 +00005820 if (SubStmtInvalid)
5821 return StmtError();
5822
Douglas Gregorebe10102009-08-20 07:17:43 +00005823 if (!getDerived().AlwaysRebuild() &&
5824 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005825 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005826
5827 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005828 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005829 S->getRBracLoc(),
5830 IsStmtExpr);
5831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregorebe10102009-08-20 07:17:43 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005835TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005836 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005837 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005838 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5839 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005840
Eli Friedman06577382009-11-19 03:14:00 +00005841 // Transform the left-hand case value.
5842 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005843 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005844 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005845 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005846
Eli Friedman06577382009-11-19 03:14:00 +00005847 // Transform the right-hand case value (for the GNU case-range extension).
5848 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005849 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005850 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005852 }
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregorebe10102009-08-20 07:17:43 +00005854 // Build the case statement.
5855 // Case statements are always rebuilt so that they will attached to their
5856 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005857 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005858 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005859 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005860 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005861 S->getColonLoc());
5862 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005863 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregorebe10102009-08-20 07:17:43 +00005865 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005866 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005867 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005869
Douglas Gregorebe10102009-08-20 07:17:43 +00005870 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005871 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005872}
5873
5874template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005875StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005876TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005877 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005878 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005879 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005881
Douglas Gregorebe10102009-08-20 07:17:43 +00005882 // Default statements are always rebuilt
5883 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005884 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005885}
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregorebe10102009-08-20 07:17:43 +00005887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005889TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005890 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005891 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005893
Chris Lattnercab02a62011-02-17 20:34:02 +00005894 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5895 S->getDecl());
5896 if (!LD)
5897 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005898
5899
Douglas Gregorebe10102009-08-20 07:17:43 +00005900 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005901 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005902 cast<LabelDecl>(LD), SourceLocation(),
5903 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005904}
Mike Stump11289f42009-09-09 15:08:12 +00005905
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005906template <typename Derived>
5907const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5908 if (!R)
5909 return R;
5910
5911 switch (R->getKind()) {
5912// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5913#define ATTR(X)
5914#define PRAGMA_SPELLING_ATTR(X) \
5915 case attr::X: \
5916 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5917#include "clang/Basic/AttrList.inc"
5918 default:
5919 return R;
5920 }
5921}
5922
5923template <typename Derived>
5924StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5925 bool AttrsChanged = false;
5926 SmallVector<const Attr *, 1> Attrs;
5927
5928 // Visit attributes and keep track if any are transformed.
5929 for (const auto *I : S->getAttrs()) {
5930 const Attr *R = getDerived().TransformAttr(I);
5931 AttrsChanged |= (I != R);
5932 Attrs.push_back(R);
5933 }
5934
Richard Smithc202b282012-04-14 00:33:13 +00005935 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5936 if (SubStmt.isInvalid())
5937 return StmtError();
5938
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005939 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005940 return S;
5941
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005942 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005943 SubStmt.get());
5944}
5945
5946template<typename Derived>
5947StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005948TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005949 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005950 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005951 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005952 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005953 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005954 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005955 getDerived().TransformDefinition(
5956 S->getConditionVariable()->getLocation(),
5957 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005958 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005959 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005960 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005961 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005962
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005963 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005964 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005965
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005966 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005967 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005968 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005969 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005970 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005972
John McCallb268a282010-08-23 23:25:46 +00005973 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005974 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005976
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005977 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005978 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005979 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005980
Douglas Gregorebe10102009-08-20 07:17:43 +00005981 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005982 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005983 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005984 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005985
Douglas Gregorebe10102009-08-20 07:17:43 +00005986 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005987 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005988 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregorebe10102009-08-20 07:17:43 +00005991 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005992 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005993 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005994 Then.get() == S->getThen() &&
5995 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005996 return S;
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005998 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005999 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006000 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006001}
6002
6003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006004StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006005TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006006 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006007 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006008 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006009 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006010 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006011 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006012 getDerived().TransformDefinition(
6013 S->getConditionVariable()->getLocation(),
6014 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006015 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006017 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006018 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006020 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006022 }
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006025 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006026 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006027 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006028 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006030
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006032 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregorebe10102009-08-20 07:17:43 +00006036 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006037 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6038 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006042StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006043TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006045 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006046 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006047 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006048 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006049 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006050 getDerived().TransformDefinition(
6051 S->getConditionVariable()->getLocation(),
6052 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006053 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006055 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006056 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006057
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006058 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006060
6061 if (S->getCond()) {
6062 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006063 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6064 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006065 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006066 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006068 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006069 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006070 }
Mike Stump11289f42009-09-09 15:08:12 +00006071
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006072 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006073 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006077 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006078 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregorebe10102009-08-20 07:17:43 +00006081 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006082 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006083 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006084 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006085 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006086
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006087 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006088 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregorebe10102009-08-20 07:17:43 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006093TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006094 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006095 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006096 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006098
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006099 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006100 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006101 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006102 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
Douglas Gregorebe10102009-08-20 07:17:43 +00006104 if (!getDerived().AlwaysRebuild() &&
6105 Cond.get() == S->getCond() &&
6106 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006107 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006108
John McCallb268a282010-08-23 23:25:46 +00006109 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6110 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006111 S->getRParenLoc());
6112}
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregorebe10102009-08-20 07:17:43 +00006114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006115StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006116TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006117 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006118 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006120 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregorebe10102009-08-20 07:17:43 +00006122 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006124 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006125 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006126 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006127 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006128 getDerived().TransformDefinition(
6129 S->getConditionVariable()->getLocation(),
6130 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006131 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006132 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006133 } else {
6134 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006135
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006136 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006138
6139 if (S->getCond()) {
6140 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006141 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6142 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006143 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006144 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006146
John McCallb268a282010-08-23 23:25:46 +00006147 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006148 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006149 }
Mike Stump11289f42009-09-09 15:08:12 +00006150
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006151 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006152 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006154
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006156 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006157 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006158 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006159
Richard Smith945f8d32013-01-14 22:39:08 +00006160 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006161 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006163
Douglas Gregorebe10102009-08-20 07:17:43 +00006164 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006165 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregorebe10102009-08-20 07:17:43 +00006169 if (!getDerived().AlwaysRebuild() &&
6170 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006171 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 Inc.get() == S->getInc() &&
6173 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006174 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006175
Douglas Gregorebe10102009-08-20 07:17:43 +00006176 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006177 Init.get(), FullCond, ConditionVar,
6178 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006179}
6180
6181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006182StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006183TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006184 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6185 S->getLabel());
6186 if (!LD)
6187 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006188
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006190 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006191 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006192}
6193
6194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006195StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006196TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006197 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006199 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006200 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregorebe10102009-08-20 07:17:43 +00006202 if (!getDerived().AlwaysRebuild() &&
6203 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006204 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006205
6206 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006207 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006208}
6209
6210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006211StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006212TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006213 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006214}
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregorebe10102009-08-20 07:17:43 +00006216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006217StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006218TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006219 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006220}
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregorebe10102009-08-20 07:17:43 +00006222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006223StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006224TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006225 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6226 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006227 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006229
Mike Stump11289f42009-09-09 15:08:12 +00006230 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006231 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006232 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006233}
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregorebe10102009-08-20 07:17:43 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006237TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006238 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006239 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006240 for (auto *D : S->decls()) {
6241 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006243 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006244
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006245 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006246 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 Decls.push_back(Transformed);
6249 }
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregorebe10102009-08-20 07:17:43 +00006251 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006252 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006253
Rafael Espindolaab417692013-07-09 12:05:01 +00006254 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006255}
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregorebe10102009-08-20 07:17:43 +00006257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006258StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006259TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006260
Benjamin Kramerf0623432012-08-23 22:51:59 +00006261 SmallVector<Expr*, 8> Constraints;
6262 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006263 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006264
John McCalldadc5752010-08-24 06:29:42 +00006265 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006266 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006267
6268 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006269
Anders Carlssonaaeef072010-01-24 05:50:09 +00006270 // Go through the outputs.
6271 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006272 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006273
Anders Carlssonaaeef072010-01-24 05:50:09 +00006274 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006275 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006276
Anders Carlssonaaeef072010-01-24 05:50:09 +00006277 // Transform the output expr.
6278 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006279 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006280 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006281 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006282
Anders Carlssonaaeef072010-01-24 05:50:09 +00006283 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006284
John McCallb268a282010-08-23 23:25:46 +00006285 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006287
Anders Carlssonaaeef072010-01-24 05:50:09 +00006288 // Go through the inputs.
6289 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006290 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006291
Anders Carlssonaaeef072010-01-24 05:50:09 +00006292 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006293 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006294
Anders Carlssonaaeef072010-01-24 05:50:09 +00006295 // Transform the input expr.
6296 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006297 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006298 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006299 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006300
Anders Carlssonaaeef072010-01-24 05:50:09 +00006301 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
John McCallb268a282010-08-23 23:25:46 +00006303 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006305
Anders Carlssonaaeef072010-01-24 05:50:09 +00006306 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006307 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006308
6309 // Go through the clobbers.
6310 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006311 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006312
6313 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006314 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006315 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6316 S->isVolatile(), S->getNumOutputs(),
6317 S->getNumInputs(), Names.data(),
6318 Constraints, Exprs, AsmString.get(),
6319 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006320}
6321
Chad Rosier32503022012-06-11 20:47:18 +00006322template<typename Derived>
6323StmtResult
6324TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006325 ArrayRef<Token> AsmToks =
6326 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006327
John McCallf413f5e2013-05-03 00:10:13 +00006328 bool HadError = false, HadChange = false;
6329
6330 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6331 SmallVector<Expr*, 8> TransformedExprs;
6332 TransformedExprs.reserve(SrcExprs.size());
6333 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6334 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6335 if (!Result.isUsable()) {
6336 HadError = true;
6337 } else {
6338 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006339 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006340 }
6341 }
6342
6343 if (HadError) return StmtError();
6344 if (!HadChange && !getDerived().AlwaysRebuild())
6345 return Owned(S);
6346
Chad Rosierb6f46c12012-08-15 16:53:30 +00006347 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006348 AsmToks, S->getAsmString(),
6349 S->getNumOutputs(), S->getNumInputs(),
6350 S->getAllConstraints(), S->getClobbers(),
6351 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006352}
Douglas Gregorebe10102009-08-20 07:17:43 +00006353
6354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006355StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006356TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006357 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006358 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006359 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006360 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006361
Douglas Gregor96c79492010-04-23 22:50:49 +00006362 // Transform the @catch statements (if present).
6363 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006364 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006365 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006366 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006367 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006368 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006369 if (Catch.get() != S->getCatchStmt(I))
6370 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006371 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006373
Douglas Gregor306de2f2010-04-22 23:59:56 +00006374 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006375 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006376 if (S->getFinallyStmt()) {
6377 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6378 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006379 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006380 }
6381
6382 // If nothing changed, just retain this statement.
6383 if (!getDerived().AlwaysRebuild() &&
6384 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006385 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006386 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006387 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006388
Douglas Gregor306de2f2010-04-22 23:59:56 +00006389 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006390 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006391 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006392}
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006396TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006397 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006398 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006399 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006400 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006401 if (FromVar->getTypeSourceInfo()) {
6402 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6403 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006404 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006406
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006407 QualType T;
6408 if (TSInfo)
6409 T = TSInfo->getType();
6410 else {
6411 T = getDerived().TransformType(FromVar->getType());
6412 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006413 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006415
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006416 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6417 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006420
John McCalldadc5752010-08-24 06:29:42 +00006421 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006422 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006424
6425 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006426 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006427 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006428}
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregorebe10102009-08-20 07:17:43 +00006430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006431StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006432TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006433 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006434 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006435 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006437
Douglas Gregor306de2f2010-04-22 23:59:56 +00006438 // If nothing changed, just retain this statement.
6439 if (!getDerived().AlwaysRebuild() &&
6440 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006441 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006442
6443 // Build a new statement.
6444 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006445 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006446}
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregorebe10102009-08-20 07:17:43 +00006448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006449StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006450TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006451 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006452 if (S->getThrowExpr()) {
6453 Operand = getDerived().TransformExpr(S->getThrowExpr());
6454 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006457
Douglas Gregor2900c162010-04-22 21:44:01 +00006458 if (!getDerived().AlwaysRebuild() &&
6459 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006460 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006461
John McCallb268a282010-08-23 23:25:46 +00006462 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006463}
Mike Stump11289f42009-09-09 15:08:12 +00006464
Douglas Gregorebe10102009-08-20 07:17:43 +00006465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006466StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006467TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006468 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006469 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006470 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006471 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006472 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006473 Object =
6474 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6475 Object.get());
6476 if (Object.isInvalid())
6477 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006478
Douglas Gregor6148de72010-04-22 22:01:21 +00006479 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006480 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006481 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006482 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006483
Douglas Gregor6148de72010-04-22 22:01:21 +00006484 // If nothing change, just retain the current statement.
6485 if (!getDerived().AlwaysRebuild() &&
6486 Object.get() == S->getSynchExpr() &&
6487 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006488 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006489
6490 // Build a new statement.
6491 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006492 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006493}
6494
6495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006496StmtResult
John McCall31168b02011-06-15 23:02:42 +00006497TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6498 ObjCAutoreleasePoolStmt *S) {
6499 // Transform the body.
6500 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6501 if (Body.isInvalid())
6502 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006503
John McCall31168b02011-06-15 23:02:42 +00006504 // If nothing changed, just retain this statement.
6505 if (!getDerived().AlwaysRebuild() &&
6506 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006507 return S;
John McCall31168b02011-06-15 23:02:42 +00006508
6509 // Build a new statement.
6510 return getDerived().RebuildObjCAutoreleasePoolStmt(
6511 S->getAtLoc(), Body.get());
6512}
6513
6514template<typename Derived>
6515StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006516TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006517 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006518 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006519 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006520 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006521 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006522
Douglas Gregorf68a5082010-04-22 23:10:45 +00006523 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006524 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006525 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006526 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006527
Douglas Gregorf68a5082010-04-22 23:10:45 +00006528 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006529 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006530 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006531 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006532
Douglas Gregorf68a5082010-04-22 23:10:45 +00006533 // If nothing changed, just retain this statement.
6534 if (!getDerived().AlwaysRebuild() &&
6535 Element.get() == S->getElement() &&
6536 Collection.get() == S->getCollection() &&
6537 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006538 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregorf68a5082010-04-22 23:10:45 +00006540 // Build a new statement.
6541 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006542 Element.get(),
6543 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006544 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006545 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006546}
6547
David Majnemer5f7efef2013-10-15 09:50:08 +00006548template <typename Derived>
6549StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006550 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006551 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006552 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6553 TypeSourceInfo *T =
6554 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006555 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006557
David Majnemer5f7efef2013-10-15 09:50:08 +00006558 Var = getDerived().RebuildExceptionDecl(
6559 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6560 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006561 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006562 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006563 }
Mike Stump11289f42009-09-09 15:08:12 +00006564
Douglas Gregorebe10102009-08-20 07:17:43 +00006565 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006566 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006567 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006569
David Majnemer5f7efef2013-10-15 09:50:08 +00006570 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006571 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006572 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006573
David Majnemer5f7efef2013-10-15 09:50:08 +00006574 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006575}
Mike Stump11289f42009-09-09 15:08:12 +00006576
David Majnemer5f7efef2013-10-15 09:50:08 +00006577template <typename Derived>
6578StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006579 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006580 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006581 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006582 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006583
Douglas Gregorebe10102009-08-20 07:17:43 +00006584 // Transform the handlers.
6585 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006586 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006587 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006588 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006589 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006590 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregorebe10102009-08-20 07:17:43 +00006592 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006593 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006594 }
Mike Stump11289f42009-09-09 15:08:12 +00006595
David Majnemer5f7efef2013-10-15 09:50:08 +00006596 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006597 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006598 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006599
John McCallb268a282010-08-23 23:25:46 +00006600 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006601 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006602}
Mike Stump11289f42009-09-09 15:08:12 +00006603
Richard Smith02e85f32011-04-14 22:09:26 +00006604template<typename Derived>
6605StmtResult
6606TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6607 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6608 if (Range.isInvalid())
6609 return StmtError();
6610
6611 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6612 if (BeginEnd.isInvalid())
6613 return StmtError();
6614
6615 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6616 if (Cond.isInvalid())
6617 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006618 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006619 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006620 if (Cond.isInvalid())
6621 return StmtError();
6622 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006623 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006624
6625 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6626 if (Inc.isInvalid())
6627 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006628 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006629 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006630
6631 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6632 if (LoopVar.isInvalid())
6633 return StmtError();
6634
6635 StmtResult NewStmt = S;
6636 if (getDerived().AlwaysRebuild() ||
6637 Range.get() != S->getRangeStmt() ||
6638 BeginEnd.get() != S->getBeginEndStmt() ||
6639 Cond.get() != S->getCond() ||
6640 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006641 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006642 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6643 S->getColonLoc(), Range.get(),
6644 BeginEnd.get(), Cond.get(),
6645 Inc.get(), LoopVar.get(),
6646 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006647 if (NewStmt.isInvalid())
6648 return StmtError();
6649 }
Richard Smith02e85f32011-04-14 22:09:26 +00006650
6651 StmtResult Body = getDerived().TransformStmt(S->getBody());
6652 if (Body.isInvalid())
6653 return StmtError();
6654
6655 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6656 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006657 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006658 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6659 S->getColonLoc(), Range.get(),
6660 BeginEnd.get(), Cond.get(),
6661 Inc.get(), LoopVar.get(),
6662 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006663 if (NewStmt.isInvalid())
6664 return StmtError();
6665 }
Richard Smith02e85f32011-04-14 22:09:26 +00006666
6667 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006668 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006669
6670 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6671}
6672
John Wiegley1c0675e2011-04-28 01:08:34 +00006673template<typename Derived>
6674StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006675TreeTransform<Derived>::TransformMSDependentExistsStmt(
6676 MSDependentExistsStmt *S) {
6677 // Transform the nested-name-specifier, if any.
6678 NestedNameSpecifierLoc QualifierLoc;
6679 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006680 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006681 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6682 if (!QualifierLoc)
6683 return StmtError();
6684 }
6685
6686 // Transform the declaration name.
6687 DeclarationNameInfo NameInfo = S->getNameInfo();
6688 if (NameInfo.getName()) {
6689 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6690 if (!NameInfo.getName())
6691 return StmtError();
6692 }
6693
6694 // Check whether anything changed.
6695 if (!getDerived().AlwaysRebuild() &&
6696 QualifierLoc == S->getQualifierLoc() &&
6697 NameInfo.getName() == S->getNameInfo().getName())
6698 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006699
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006700 // Determine whether this name exists, if we can.
6701 CXXScopeSpec SS;
6702 SS.Adopt(QualifierLoc);
6703 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006704 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006705 case Sema::IER_Exists:
6706 if (S->isIfExists())
6707 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006708
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006709 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6710
6711 case Sema::IER_DoesNotExist:
6712 if (S->isIfNotExists())
6713 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006714
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006715 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006716
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006717 case Sema::IER_Dependent:
6718 Dependent = true;
6719 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006720
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006721 case Sema::IER_Error:
6722 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006724
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006725 // We need to continue with the instantiation, so do so now.
6726 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6727 if (SubStmt.isInvalid())
6728 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006729
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006730 // If we have resolved the name, just transform to the substatement.
6731 if (!Dependent)
6732 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006734 // The name is still dependent, so build a dependent expression again.
6735 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6736 S->isIfExists(),
6737 QualifierLoc,
6738 NameInfo,
6739 SubStmt.get());
6740}
6741
6742template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006743ExprResult
6744TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6745 NestedNameSpecifierLoc QualifierLoc;
6746 if (E->getQualifierLoc()) {
6747 QualifierLoc
6748 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6749 if (!QualifierLoc)
6750 return ExprError();
6751 }
6752
6753 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6754 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6755 if (!PD)
6756 return ExprError();
6757
6758 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6759 if (Base.isInvalid())
6760 return ExprError();
6761
6762 return new (SemaRef.getASTContext())
6763 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6764 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6765 QualifierLoc, E->getMemberLoc());
6766}
6767
David Majnemerfad8f482013-10-15 09:33:02 +00006768template <typename Derived>
6769StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006770 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006771 if (TryBlock.isInvalid())
6772 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006773
6774 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006775 if (Handler.isInvalid())
6776 return StmtError();
6777
David Majnemerfad8f482013-10-15 09:33:02 +00006778 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6779 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006780 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006781
Warren Huntf6be4cb2014-07-25 20:52:51 +00006782 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6783 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006784}
6785
David Majnemerfad8f482013-10-15 09:33:02 +00006786template <typename Derived>
6787StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006788 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006789 if (Block.isInvalid())
6790 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006791
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006792 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006793}
6794
David Majnemerfad8f482013-10-15 09:33:02 +00006795template <typename Derived>
6796StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006797 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006798 if (FilterExpr.isInvalid())
6799 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006800
David Majnemer7e755502013-10-15 09:30:14 +00006801 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006802 if (Block.isInvalid())
6803 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006804
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006805 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6806 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006807}
6808
David Majnemerfad8f482013-10-15 09:33:02 +00006809template <typename Derived>
6810StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6811 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006812 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6813 else
6814 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6815}
6816
Nico Weber9b982072014-07-07 00:12:30 +00006817template<typename Derived>
6818StmtResult
6819TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6820 return S;
6821}
6822
Alexander Musman64d33f12014-06-04 07:53:32 +00006823//===----------------------------------------------------------------------===//
6824// OpenMP directive transformation
6825//===----------------------------------------------------------------------===//
6826template <typename Derived>
6827StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6828 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006829
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006830 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006831 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006832 ArrayRef<OMPClause *> Clauses = D->clauses();
6833 TClauses.reserve(Clauses.size());
6834 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6835 I != E; ++I) {
6836 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006837 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006838 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006839 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006840 if (Clause)
6841 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006842 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006843 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006844 }
6845 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006846 StmtResult AssociatedStmt;
6847 if (D->hasAssociatedStmt()) {
6848 if (!D->getAssociatedStmt()) {
6849 return StmtError();
6850 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006851 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6852 /*CurScope=*/nullptr);
6853 StmtResult Body;
6854 {
6855 Sema::CompoundScopeRAII CompoundScope(getSema());
6856 Body = getDerived().TransformStmt(
6857 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6858 }
6859 AssociatedStmt =
6860 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006861 if (AssociatedStmt.isInvalid()) {
6862 return StmtError();
6863 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006864 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006865 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006866 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006867 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006868
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006869 // Transform directive name for 'omp critical' directive.
6870 DeclarationNameInfo DirName;
6871 if (D->getDirectiveKind() == OMPD_critical) {
6872 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6873 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6874 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006875 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6876 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6877 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006878 } else if (D->getDirectiveKind() == OMPD_cancel) {
6879 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006880 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006881
Alexander Musman64d33f12014-06-04 07:53:32 +00006882 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006883 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6884 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006885}
6886
Alexander Musman64d33f12014-06-04 07:53:32 +00006887template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006888StmtResult
6889TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6890 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006891 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6892 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006893 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6894 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6895 return Res;
6896}
6897
Alexander Musman64d33f12014-06-04 07:53:32 +00006898template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006899StmtResult
6900TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6901 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006902 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6903 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006904 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6905 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006906 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006907}
6908
Alexey Bataevf29276e2014-06-18 04:14:57 +00006909template <typename Derived>
6910StmtResult
6911TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6912 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006913 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6914 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006915 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6916 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6917 return Res;
6918}
6919
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006920template <typename Derived>
6921StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006922TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6923 DeclarationNameInfo DirName;
6924 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6925 D->getLocStart());
6926 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6927 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6928 return Res;
6929}
6930
6931template <typename Derived>
6932StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006933TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6934 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006935 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6936 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006937 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6938 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6939 return Res;
6940}
6941
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006942template <typename Derived>
6943StmtResult
6944TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6945 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006946 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6947 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006948 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6949 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6950 return Res;
6951}
6952
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006953template <typename Derived>
6954StmtResult
6955TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6956 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006957 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6958 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006959 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6960 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6961 return Res;
6962}
6963
Alexey Bataev4acb8592014-07-07 13:01:15 +00006964template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006965StmtResult
6966TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6967 DeclarationNameInfo DirName;
6968 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6969 D->getLocStart());
6970 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6971 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6972 return Res;
6973}
6974
6975template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006976StmtResult
6977TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6978 getDerived().getSema().StartOpenMPDSABlock(
6979 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6980 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6981 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6982 return Res;
6983}
6984
6985template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00006986StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
6987 OMPParallelForDirective *D) {
6988 DeclarationNameInfo DirName;
6989 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
6990 nullptr, D->getLocStart());
6991 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6992 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6993 return Res;
6994}
6995
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00006996template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00006997StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
6998 OMPParallelForSimdDirective *D) {
6999 DeclarationNameInfo DirName;
7000 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7001 nullptr, D->getLocStart());
7002 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7003 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7004 return Res;
7005}
7006
7007template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007008StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7009 OMPParallelSectionsDirective *D) {
7010 DeclarationNameInfo DirName;
7011 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7012 nullptr, D->getLocStart());
7013 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7014 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7015 return Res;
7016}
7017
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007018template <typename Derived>
7019StmtResult
7020TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7021 DeclarationNameInfo DirName;
7022 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7023 D->getLocStart());
7024 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7025 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7026 return Res;
7027}
7028
Alexey Bataev68446b72014-07-18 07:47:19 +00007029template <typename Derived>
7030StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7031 OMPTaskyieldDirective *D) {
7032 DeclarationNameInfo DirName;
7033 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7034 D->getLocStart());
7035 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7036 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7037 return Res;
7038}
7039
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007040template <typename Derived>
7041StmtResult
7042TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7043 DeclarationNameInfo DirName;
7044 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7045 D->getLocStart());
7046 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7047 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7048 return Res;
7049}
7050
Alexey Bataev2df347a2014-07-18 10:17:07 +00007051template <typename Derived>
7052StmtResult
7053TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7054 DeclarationNameInfo DirName;
7055 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7056 D->getLocStart());
7057 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7058 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7059 return Res;
7060}
7061
Alexey Bataev6125da92014-07-21 11:26:11 +00007062template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007063StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7064 OMPTaskgroupDirective *D) {
7065 DeclarationNameInfo DirName;
7066 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7067 D->getLocStart());
7068 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7069 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7070 return Res;
7071}
7072
7073template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007074StmtResult
7075TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7076 DeclarationNameInfo DirName;
7077 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7078 D->getLocStart());
7079 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7080 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7081 return Res;
7082}
7083
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007084template <typename Derived>
7085StmtResult
7086TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7087 DeclarationNameInfo DirName;
7088 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7089 D->getLocStart());
7090 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7091 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7092 return Res;
7093}
7094
Alexey Bataev0162e452014-07-22 10:10:35 +00007095template <typename Derived>
7096StmtResult
7097TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7098 DeclarationNameInfo DirName;
7099 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7100 D->getLocStart());
7101 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7102 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7103 return Res;
7104}
7105
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007106template <typename Derived>
7107StmtResult
7108TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7109 DeclarationNameInfo DirName;
7110 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7111 D->getLocStart());
7112 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7113 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7114 return Res;
7115}
7116
Alexey Bataev13314bf2014-10-09 04:18:56 +00007117template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007118StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7119 OMPTargetDataDirective *D) {
7120 DeclarationNameInfo DirName;
7121 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7122 D->getLocStart());
7123 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7124 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7125 return Res;
7126}
7127
7128template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007129StmtResult
7130TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7131 DeclarationNameInfo DirName;
7132 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7133 D->getLocStart());
7134 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7135 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7136 return Res;
7137}
7138
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007139template <typename Derived>
7140StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7141 OMPCancellationPointDirective *D) {
7142 DeclarationNameInfo DirName;
7143 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7144 nullptr, D->getLocStart());
7145 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7146 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7147 return Res;
7148}
7149
Alexey Bataev80909872015-07-02 11:25:17 +00007150template <typename Derived>
7151StmtResult
7152TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7153 DeclarationNameInfo DirName;
7154 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7155 D->getLocStart());
7156 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7157 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7158 return Res;
7159}
7160
Alexander Musman64d33f12014-06-04 07:53:32 +00007161//===----------------------------------------------------------------------===//
7162// OpenMP clause transformation
7163//===----------------------------------------------------------------------===//
7164template <typename Derived>
7165OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007166 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7167 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007168 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007169 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007170 C->getLParenLoc(), C->getLocEnd());
7171}
7172
Alexander Musman64d33f12014-06-04 07:53:32 +00007173template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007174OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7175 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7176 if (Cond.isInvalid())
7177 return nullptr;
7178 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7179 C->getLParenLoc(), C->getLocEnd());
7180}
7181
7182template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007183OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007184TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7185 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7186 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007187 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007188 return getDerived().RebuildOMPNumThreadsClause(
7189 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007190}
7191
Alexey Bataev62c87d22014-03-21 04:51:18 +00007192template <typename Derived>
7193OMPClause *
7194TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7195 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7196 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007197 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007198 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007199 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007200}
7201
Alexander Musman8bd31e62014-05-27 15:12:19 +00007202template <typename Derived>
7203OMPClause *
7204TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7205 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7206 if (E.isInvalid())
7207 return 0;
7208 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007209 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007210}
7211
Alexander Musman64d33f12014-06-04 07:53:32 +00007212template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007213OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007214TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007215 return getDerived().RebuildOMPDefaultClause(
7216 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7217 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007218}
7219
Alexander Musman64d33f12014-06-04 07:53:32 +00007220template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007221OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007222TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007223 return getDerived().RebuildOMPProcBindClause(
7224 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7225 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007226}
7227
Alexander Musman64d33f12014-06-04 07:53:32 +00007228template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007229OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007230TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7231 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7232 if (E.isInvalid())
7233 return nullptr;
7234 return getDerived().RebuildOMPScheduleClause(
7235 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7236 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7237}
7238
7239template <typename Derived>
7240OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007241TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
7242 // No need to rebuild this clause, no template-dependent parameters.
7243 return C;
7244}
7245
7246template <typename Derived>
7247OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007248TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7249 // No need to rebuild this clause, no template-dependent parameters.
7250 return C;
7251}
7252
7253template <typename Derived>
7254OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007255TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7256 // No need to rebuild this clause, no template-dependent parameters.
7257 return C;
7258}
7259
7260template <typename Derived>
7261OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007262TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7263 // No need to rebuild this clause, no template-dependent parameters.
7264 return C;
7265}
7266
7267template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007268OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7269 // No need to rebuild this clause, no template-dependent parameters.
7270 return C;
7271}
7272
7273template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007274OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7275 // No need to rebuild this clause, no template-dependent parameters.
7276 return C;
7277}
7278
7279template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007280OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007281TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7282 // No need to rebuild this clause, no template-dependent parameters.
7283 return C;
7284}
7285
7286template <typename Derived>
7287OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007288TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7289 // No need to rebuild this clause, no template-dependent parameters.
7290 return C;
7291}
7292
7293template <typename Derived>
7294OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007295TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7296 // No need to rebuild this clause, no template-dependent parameters.
7297 return C;
7298}
7299
7300template <typename Derived>
7301OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007302TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007303 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007304 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007305 for (auto *VE : C->varlists()) {
7306 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007307 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007308 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007309 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007310 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007311 return getDerived().RebuildOMPPrivateClause(
7312 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007313}
7314
Alexander Musman64d33f12014-06-04 07:53:32 +00007315template <typename Derived>
7316OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7317 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007318 llvm::SmallVector<Expr *, 16> Vars;
7319 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007320 for (auto *VE : C->varlists()) {
7321 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007322 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007323 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007324 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007325 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007326 return getDerived().RebuildOMPFirstprivateClause(
7327 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007328}
7329
Alexander Musman64d33f12014-06-04 07:53:32 +00007330template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007331OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007332TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7333 llvm::SmallVector<Expr *, 16> Vars;
7334 Vars.reserve(C->varlist_size());
7335 for (auto *VE : C->varlists()) {
7336 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7337 if (EVar.isInvalid())
7338 return nullptr;
7339 Vars.push_back(EVar.get());
7340 }
7341 return getDerived().RebuildOMPLastprivateClause(
7342 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7343}
7344
7345template <typename Derived>
7346OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007347TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7348 llvm::SmallVector<Expr *, 16> Vars;
7349 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007350 for (auto *VE : C->varlists()) {
7351 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007352 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007353 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007354 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007355 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007356 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7357 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007358}
7359
Alexander Musman64d33f12014-06-04 07:53:32 +00007360template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007361OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007362TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7363 llvm::SmallVector<Expr *, 16> Vars;
7364 Vars.reserve(C->varlist_size());
7365 for (auto *VE : C->varlists()) {
7366 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7367 if (EVar.isInvalid())
7368 return nullptr;
7369 Vars.push_back(EVar.get());
7370 }
7371 CXXScopeSpec ReductionIdScopeSpec;
7372 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7373
7374 DeclarationNameInfo NameInfo = C->getNameInfo();
7375 if (NameInfo.getName()) {
7376 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7377 if (!NameInfo.getName())
7378 return nullptr;
7379 }
7380 return getDerived().RebuildOMPReductionClause(
7381 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7382 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7383}
7384
7385template <typename Derived>
7386OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007387TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7388 llvm::SmallVector<Expr *, 16> Vars;
7389 Vars.reserve(C->varlist_size());
7390 for (auto *VE : C->varlists()) {
7391 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7392 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007393 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007394 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007395 }
7396 ExprResult Step = getDerived().TransformExpr(C->getStep());
7397 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007398 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007399 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7400 C->getLParenLoc(),
7401 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007402}
7403
Alexander Musman64d33f12014-06-04 07:53:32 +00007404template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007405OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007406TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7407 llvm::SmallVector<Expr *, 16> Vars;
7408 Vars.reserve(C->varlist_size());
7409 for (auto *VE : C->varlists()) {
7410 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7411 if (EVar.isInvalid())
7412 return nullptr;
7413 Vars.push_back(EVar.get());
7414 }
7415 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7416 if (Alignment.isInvalid())
7417 return nullptr;
7418 return getDerived().RebuildOMPAlignedClause(
7419 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7420 C->getColonLoc(), C->getLocEnd());
7421}
7422
Alexander Musman64d33f12014-06-04 07:53:32 +00007423template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007424OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007425TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7426 llvm::SmallVector<Expr *, 16> Vars;
7427 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007428 for (auto *VE : C->varlists()) {
7429 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007430 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007431 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007432 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007433 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007434 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7435 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007436}
7437
Alexey Bataevbae9a792014-06-27 10:37:06 +00007438template <typename Derived>
7439OMPClause *
7440TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7441 llvm::SmallVector<Expr *, 16> Vars;
7442 Vars.reserve(C->varlist_size());
7443 for (auto *VE : C->varlists()) {
7444 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7445 if (EVar.isInvalid())
7446 return nullptr;
7447 Vars.push_back(EVar.get());
7448 }
7449 return getDerived().RebuildOMPCopyprivateClause(
7450 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7451}
7452
Alexey Bataev6125da92014-07-21 11:26:11 +00007453template <typename Derived>
7454OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7455 llvm::SmallVector<Expr *, 16> Vars;
7456 Vars.reserve(C->varlist_size());
7457 for (auto *VE : C->varlists()) {
7458 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7459 if (EVar.isInvalid())
7460 return nullptr;
7461 Vars.push_back(EVar.get());
7462 }
7463 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7464 C->getLParenLoc(), C->getLocEnd());
7465}
7466
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007467template <typename Derived>
7468OMPClause *
7469TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7470 llvm::SmallVector<Expr *, 16> Vars;
7471 Vars.reserve(C->varlist_size());
7472 for (auto *VE : C->varlists()) {
7473 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7474 if (EVar.isInvalid())
7475 return nullptr;
7476 Vars.push_back(EVar.get());
7477 }
7478 return getDerived().RebuildOMPDependClause(
7479 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7480 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7481}
7482
Douglas Gregorebe10102009-08-20 07:17:43 +00007483//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007484// Expression transformation
7485//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007487ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007488TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007489 if (!E->isTypeDependent())
7490 return E;
7491
7492 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7493 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007494}
Mike Stump11289f42009-09-09 15:08:12 +00007495
7496template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007497ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007498TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007499 NestedNameSpecifierLoc QualifierLoc;
7500 if (E->getQualifierLoc()) {
7501 QualifierLoc
7502 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7503 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007504 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007505 }
John McCallce546572009-12-08 09:08:17 +00007506
7507 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007508 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7509 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007510 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007512
John McCall815039a2010-08-17 21:27:17 +00007513 DeclarationNameInfo NameInfo = E->getNameInfo();
7514 if (NameInfo.getName()) {
7515 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7516 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007517 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007518 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007519
7520 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007521 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007522 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007523 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007524 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007525
7526 // Mark it referenced in the new context regardless.
7527 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007528 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007529
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007530 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007531 }
John McCallce546572009-12-08 09:08:17 +00007532
Craig Topperc3ec1492014-05-26 06:22:03 +00007533 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007534 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007535 TemplateArgs = &TransArgs;
7536 TransArgs.setLAngleLoc(E->getLAngleLoc());
7537 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007538 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7539 E->getNumTemplateArgs(),
7540 TransArgs))
7541 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007542 }
7543
Chad Rosier1dcde962012-08-08 18:46:20 +00007544 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007545 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007546}
Mike Stump11289f42009-09-09 15:08:12 +00007547
Douglas Gregora16548e2009-08-11 05:31:07 +00007548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007550TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007551 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007552}
Mike Stump11289f42009-09-09 15:08:12 +00007553
Douglas Gregora16548e2009-08-11 05:31:07 +00007554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007556TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007557 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007558}
Mike Stump11289f42009-09-09 15:08:12 +00007559
Douglas Gregora16548e2009-08-11 05:31:07 +00007560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007562TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007563 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007564}
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregora16548e2009-08-11 05:31:07 +00007566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007568TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007569 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007570}
Mike Stump11289f42009-09-09 15:08:12 +00007571
Douglas Gregora16548e2009-08-11 05:31:07 +00007572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007574TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007575 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007576}
7577
7578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007579ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007580TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007581 if (FunctionDecl *FD = E->getDirectCallee())
7582 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007583 return SemaRef.MaybeBindToTemporary(E);
7584}
7585
7586template<typename Derived>
7587ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007588TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7589 ExprResult ControllingExpr =
7590 getDerived().TransformExpr(E->getControllingExpr());
7591 if (ControllingExpr.isInvalid())
7592 return ExprError();
7593
Chris Lattner01cf8db2011-07-20 06:58:45 +00007594 SmallVector<Expr *, 4> AssocExprs;
7595 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007596 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7597 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7598 if (TS) {
7599 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7600 if (!AssocType)
7601 return ExprError();
7602 AssocTypes.push_back(AssocType);
7603 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007604 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007605 }
7606
7607 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7608 if (AssocExpr.isInvalid())
7609 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007610 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007611 }
7612
7613 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7614 E->getDefaultLoc(),
7615 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007616 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007617 AssocTypes,
7618 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007619}
7620
7621template<typename Derived>
7622ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007623TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007624 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007625 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007626 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007627
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007629 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007630
John McCallb268a282010-08-23 23:25:46 +00007631 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 E->getRParen());
7633}
7634
Richard Smithdb2630f2012-10-21 03:28:35 +00007635/// \brief The operand of a unary address-of operator has special rules: it's
7636/// allowed to refer to a non-static member of a class even if there's no 'this'
7637/// object available.
7638template<typename Derived>
7639ExprResult
7640TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7641 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007642 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007643 else
7644 return getDerived().TransformExpr(E);
7645}
7646
Mike Stump11289f42009-09-09 15:08:12 +00007647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007649TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007650 ExprResult SubExpr;
7651 if (E->getOpcode() == UO_AddrOf)
7652 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7653 else
7654 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007655 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007656 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007657
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007659 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7662 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007663 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007664}
Mike Stump11289f42009-09-09 15:08:12 +00007665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007667ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007668TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7669 // Transform the type.
7670 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7671 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007672 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007673
Douglas Gregor882211c2010-04-28 22:16:22 +00007674 // Transform all of the components into components similar to what the
7675 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007676 // FIXME: It would be slightly more efficient in the non-dependent case to
7677 // just map FieldDecls, rather than requiring the rebuilder to look for
7678 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007679 // template code that we don't care.
7680 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007681 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007682 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007683 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007684 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7685 const Node &ON = E->getComponent(I);
7686 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007687 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007688 Comp.LocStart = ON.getSourceRange().getBegin();
7689 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007690 switch (ON.getKind()) {
7691 case Node::Array: {
7692 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007693 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007694 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007695 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007696
Douglas Gregor882211c2010-04-28 22:16:22 +00007697 ExprChanged = ExprChanged || Index.get() != FromIndex;
7698 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007699 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007700 break;
7701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007702
Douglas Gregor882211c2010-04-28 22:16:22 +00007703 case Node::Field:
7704 case Node::Identifier:
7705 Comp.isBrackets = false;
7706 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007707 if (!Comp.U.IdentInfo)
7708 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007709
Douglas Gregor882211c2010-04-28 22:16:22 +00007710 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007711
Douglas Gregord1702062010-04-29 00:18:15 +00007712 case Node::Base:
7713 // Will be recomputed during the rebuild.
7714 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007716
Douglas Gregor882211c2010-04-28 22:16:22 +00007717 Components.push_back(Comp);
7718 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007719
Douglas Gregor882211c2010-04-28 22:16:22 +00007720 // If nothing changed, retain the existing expression.
7721 if (!getDerived().AlwaysRebuild() &&
7722 Type == E->getTypeSourceInfo() &&
7723 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007724 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007725
Douglas Gregor882211c2010-04-28 22:16:22 +00007726 // Build a new offsetof expression.
7727 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7728 Components.data(), Components.size(),
7729 E->getRParenLoc());
7730}
7731
7732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007733ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007734TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7735 assert(getDerived().AlreadyTransformed(E->getType()) &&
7736 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007737 return E;
John McCall8d69a212010-11-15 23:31:06 +00007738}
7739
7740template<typename Derived>
7741ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007742TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7743 return E;
7744}
7745
7746template<typename Derived>
7747ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007748TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007749 // Rebuild the syntactic form. The original syntactic form has
7750 // opaque-value expressions in it, so strip those away and rebuild
7751 // the result. This is a really awful way of doing this, but the
7752 // better solution (rebuilding the semantic expressions and
7753 // rebinding OVEs as necessary) doesn't work; we'd need
7754 // TreeTransform to not strip away implicit conversions.
7755 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7756 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007757 if (result.isInvalid()) return ExprError();
7758
7759 // If that gives us a pseudo-object result back, the pseudo-object
7760 // expression must have been an lvalue-to-rvalue conversion which we
7761 // should reapply.
7762 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007763 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007764
7765 return result;
7766}
7767
7768template<typename Derived>
7769ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007770TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7771 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007772 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007773 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007774
John McCallbcd03502009-12-07 02:54:59 +00007775 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007776 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007778
John McCall4c98fd82009-11-04 07:28:41 +00007779 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007780 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007781
Peter Collingbournee190dee2011-03-11 19:24:49 +00007782 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7783 E->getKind(),
7784 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007785 }
Mike Stump11289f42009-09-09 15:08:12 +00007786
Eli Friedmane4f22df2012-02-29 04:03:55 +00007787 // C++0x [expr.sizeof]p1:
7788 // The operand is either an expression, which is an unevaluated operand
7789 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007790 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7791 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007792
Reid Kleckner32506ed2014-06-12 23:03:48 +00007793 // Try to recover if we have something like sizeof(T::X) where X is a type.
7794 // Notably, there must be *exactly* one set of parens if X is a type.
7795 TypeSourceInfo *RecoveryTSI = nullptr;
7796 ExprResult SubExpr;
7797 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7798 if (auto *DRE =
7799 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7800 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7801 PE, DRE, false, &RecoveryTSI);
7802 else
7803 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7804
7805 if (RecoveryTSI) {
7806 return getDerived().RebuildUnaryExprOrTypeTrait(
7807 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7808 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007810
Eli Friedmane4f22df2012-02-29 04:03:55 +00007811 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007812 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007813
Peter Collingbournee190dee2011-03-11 19:24:49 +00007814 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7815 E->getOperatorLoc(),
7816 E->getKind(),
7817 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007818}
Mike Stump11289f42009-09-09 15:08:12 +00007819
Douglas Gregora16548e2009-08-11 05:31:07 +00007820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007822TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007823 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007824 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007825 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007826
John McCalldadc5752010-08-24 06:29:42 +00007827 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007828 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007829 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007830
7831
Douglas Gregora16548e2009-08-11 05:31:07 +00007832 if (!getDerived().AlwaysRebuild() &&
7833 LHS.get() == E->getLHS() &&
7834 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007835 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007836
John McCallb268a282010-08-23 23:25:46 +00007837 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007838 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007839 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007840 E->getRBracketLoc());
7841}
Mike Stump11289f42009-09-09 15:08:12 +00007842
7843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007845TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007846 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007847 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007848 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007849 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007850
7851 // Transform arguments.
7852 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007853 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007854 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007855 &ArgChanged))
7856 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007857
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 if (!getDerived().AlwaysRebuild() &&
7859 Callee.get() == E->getCallee() &&
7860 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007861 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007862
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007864 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007866 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007867 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 E->getRParenLoc());
7869}
Mike Stump11289f42009-09-09 15:08:12 +00007870
7871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007874 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007875 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007877
Douglas Gregorea972d32011-02-28 21:54:11 +00007878 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007879 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007880 QualifierLoc
7881 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007882
Douglas Gregorea972d32011-02-28 21:54:11 +00007883 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007884 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007885 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007886 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007887
Eli Friedman2cfcef62009-12-04 06:40:45 +00007888 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007889 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7890 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007891 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007893
John McCall16df1e52010-03-30 21:47:33 +00007894 NamedDecl *FoundDecl = E->getFoundDecl();
7895 if (FoundDecl == E->getMemberDecl()) {
7896 FoundDecl = Member;
7897 } else {
7898 FoundDecl = cast_or_null<NamedDecl>(
7899 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7900 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007901 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007902 }
7903
Douglas Gregora16548e2009-08-11 05:31:07 +00007904 if (!getDerived().AlwaysRebuild() &&
7905 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007906 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007907 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007908 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007909 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007910
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007911 // Mark it referenced in the new context regardless.
7912 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007913 SemaRef.MarkMemberReferenced(E);
7914
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007915 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007916 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007917
John McCall6b51f282009-11-23 01:53:49 +00007918 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007919 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007920 TransArgs.setLAngleLoc(E->getLAngleLoc());
7921 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007922 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7923 E->getNumTemplateArgs(),
7924 TransArgs))
7925 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007927
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007929 SourceLocation FakeOperatorLoc =
7930 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007931
John McCall38836f02010-01-15 08:34:02 +00007932 // FIXME: to do this check properly, we will need to preserve the
7933 // first-qualifier-in-scope here, just in case we had a dependent
7934 // base (and therefore couldn't do the check) and a
7935 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007936 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007937
John McCallb268a282010-08-23 23:25:46 +00007938 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007939 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007940 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007941 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007942 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007943 Member,
John McCall16df1e52010-03-30 21:47:33 +00007944 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007945 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007946 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007947 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007948}
Mike Stump11289f42009-09-09 15:08:12 +00007949
Douglas Gregora16548e2009-08-11 05:31:07 +00007950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007951ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007952TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007953 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007954 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007955 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007956
John McCalldadc5752010-08-24 06:29:42 +00007957 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007958 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007959 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 if (!getDerived().AlwaysRebuild() &&
7962 LHS.get() == E->getLHS() &&
7963 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007964 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007965
Lang Hames5de91cc2012-10-02 04:45:10 +00007966 Sema::FPContractStateRAII FPContractState(getSema());
7967 getSema().FPFeatures.fp_contract = E->isFPContractable();
7968
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007970 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007971}
7972
Mike Stump11289f42009-09-09 15:08:12 +00007973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007974ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007975TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00007976 CompoundAssignOperator *E) {
7977 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007978}
Mike Stump11289f42009-09-09 15:08:12 +00007979
Douglas Gregora16548e2009-08-11 05:31:07 +00007980template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00007981ExprResult TreeTransform<Derived>::
7982TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
7983 // Just rebuild the common and RHS expressions and see whether we
7984 // get any changes.
7985
7986 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
7987 if (commonExpr.isInvalid())
7988 return ExprError();
7989
7990 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
7991 if (rhs.isInvalid())
7992 return ExprError();
7993
7994 if (!getDerived().AlwaysRebuild() &&
7995 commonExpr.get() == e->getCommon() &&
7996 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007997 return e;
John McCallc07a0c72011-02-17 10:25:35 +00007998
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007999 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008000 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008001 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008002 e->getColonLoc(),
8003 rhs.get());
8004}
8005
8006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008008TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008009 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008012
John McCalldadc5752010-08-24 06:29:42 +00008013 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008014 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008016
John McCalldadc5752010-08-24 06:29:42 +00008017 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008018 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008020
Douglas Gregora16548e2009-08-11 05:31:07 +00008021 if (!getDerived().AlwaysRebuild() &&
8022 Cond.get() == E->getCond() &&
8023 LHS.get() == E->getLHS() &&
8024 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008025 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008026
John McCallb268a282010-08-23 23:25:46 +00008027 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008028 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008029 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008030 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008031 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008032}
Mike Stump11289f42009-09-09 15:08:12 +00008033
8034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008036TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008037 // Implicit casts are eliminated during transformation, since they
8038 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008039 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008040}
Mike Stump11289f42009-09-09 15:08:12 +00008041
Douglas Gregora16548e2009-08-11 05:31:07 +00008042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008044TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008045 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8046 if (!Type)
8047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008048
John McCalldadc5752010-08-24 06:29:42 +00008049 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008050 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008051 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008052 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008053
Douglas Gregora16548e2009-08-11 05:31:07 +00008054 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008055 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008056 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008057 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008058
John McCall97513962010-01-15 18:39:57 +00008059 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008060 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008061 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008062 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008063}
Mike Stump11289f42009-09-09 15:08:12 +00008064
Douglas Gregora16548e2009-08-11 05:31:07 +00008065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008067TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008068 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8069 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8070 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008072
John McCalldadc5752010-08-24 06:29:42 +00008073 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008074 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008076
Douglas Gregora16548e2009-08-11 05:31:07 +00008077 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008078 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008079 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008080 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008081
John McCall5d7aa7f2010-01-19 22:33:45 +00008082 // Note: the expression type doesn't necessarily match the
8083 // type-as-written, but that's okay, because it should always be
8084 // derivable from the initializer.
8085
John McCalle15bbff2010-01-18 19:35:47 +00008086 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008087 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008088 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008089}
Mike Stump11289f42009-09-09 15:08:12 +00008090
Douglas Gregora16548e2009-08-11 05:31:07 +00008091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008093TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008094 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008095 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008097
Douglas Gregora16548e2009-08-11 05:31:07 +00008098 if (!getDerived().AlwaysRebuild() &&
8099 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008100 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008101
Douglas Gregora16548e2009-08-11 05:31:07 +00008102 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008103 SourceLocation FakeOperatorLoc =
8104 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008105 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008106 E->getAccessorLoc(),
8107 E->getAccessor());
8108}
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregora16548e2009-08-11 05:31:07 +00008110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008112TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008113 if (InitListExpr *Syntactic = E->getSyntacticForm())
8114 E = Syntactic;
8115
Douglas Gregora16548e2009-08-11 05:31:07 +00008116 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008117
Benjamin Kramerf0623432012-08-23 22:51:59 +00008118 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008119 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008120 Inits, &InitChanged))
8121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008122
Richard Smith520449d2015-02-05 06:15:50 +00008123 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8124 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8125 // in some cases. We can't reuse it in general, because the syntactic and
8126 // semantic forms are linked, and we can't know that semantic form will
8127 // match even if the syntactic form does.
8128 }
Mike Stump11289f42009-09-09 15:08:12 +00008129
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008130 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008131 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008132}
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregora16548e2009-08-11 05:31:07 +00008134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008136TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008138
Douglas Gregorebe10102009-08-20 07:17:43 +00008139 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008140 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008141 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008143
Douglas Gregorebe10102009-08-20 07:17:43 +00008144 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008145 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008146 bool ExprChanged = false;
8147 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8148 DEnd = E->designators_end();
8149 D != DEnd; ++D) {
8150 if (D->isFieldDesignator()) {
8151 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8152 D->getDotLoc(),
8153 D->getFieldLoc()));
8154 continue;
8155 }
Mike Stump11289f42009-09-09 15:08:12 +00008156
Douglas Gregora16548e2009-08-11 05:31:07 +00008157 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008158 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008159 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008161
8162 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008163 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008164
Douglas Gregora16548e2009-08-11 05:31:07 +00008165 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008166 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008167 continue;
8168 }
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008171 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8173 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008175
John McCalldadc5752010-08-24 06:29:42 +00008176 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008179
8180 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008181 End.get(),
8182 D->getLBracketLoc(),
8183 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008184
Douglas Gregora16548e2009-08-11 05:31:07 +00008185 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8186 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008187
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008188 ArrayExprs.push_back(Start.get());
8189 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 }
Mike Stump11289f42009-09-09 15:08:12 +00008191
Douglas Gregora16548e2009-08-11 05:31:07 +00008192 if (!getDerived().AlwaysRebuild() &&
8193 Init.get() == E->getInit() &&
8194 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008195 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008196
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008197 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008199 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008200}
Mike Stump11289f42009-09-09 15:08:12 +00008201
Yunzhong Gaocb779302015-06-10 00:27:52 +00008202// Seems that if TransformInitListExpr() only works on the syntactic form of an
8203// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8204template<typename Derived>
8205ExprResult
8206TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8207 DesignatedInitUpdateExpr *E) {
8208 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8209 "initializer");
8210 return ExprError();
8211}
8212
8213template<typename Derived>
8214ExprResult
8215TreeTransform<Derived>::TransformNoInitExpr(
8216 NoInitExpr *E) {
8217 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8218 return ExprError();
8219}
8220
Douglas Gregora16548e2009-08-11 05:31:07 +00008221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008222ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008223TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008224 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008225 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008226
Douglas Gregor3da3c062009-10-28 00:29:27 +00008227 // FIXME: Will we ever have proper type location here? Will we actually
8228 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008229 QualType T = getDerived().TransformType(E->getType());
8230 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregora16548e2009-08-11 05:31:07 +00008233 if (!getDerived().AlwaysRebuild() &&
8234 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008235 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237 return getDerived().RebuildImplicitValueInitExpr(T);
8238}
Mike Stump11289f42009-09-09 15:08:12 +00008239
Douglas Gregora16548e2009-08-11 05:31:07 +00008240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008242TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008243 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8244 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008246
John McCalldadc5752010-08-24 06:29:42 +00008247 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008248 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008249 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008250
Douglas Gregora16548e2009-08-11 05:31:07 +00008251 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008252 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008253 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008254 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008255
John McCallb268a282010-08-23 23:25:46 +00008256 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008257 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008258}
8259
8260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008262TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008263 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008264 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008265 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8266 &ArgumentChanged))
8267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008268
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008270 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 E->getRParenLoc());
8272}
Mike Stump11289f42009-09-09 15:08:12 +00008273
Douglas Gregora16548e2009-08-11 05:31:07 +00008274/// \brief Transform an address-of-label expression.
8275///
8276/// By default, the transformation of an address-of-label expression always
8277/// rebuilds the expression, so that the label identifier can be resolved to
8278/// the corresponding label statement by semantic analysis.
8279template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008281TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008282 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8283 E->getLabel());
8284 if (!LD)
8285 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008286
Douglas Gregora16548e2009-08-11 05:31:07 +00008287 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008288 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008289}
Mike Stump11289f42009-09-09 15:08:12 +00008290
8291template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008292ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008293TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008294 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008295 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008297 if (SubStmt.isInvalid()) {
8298 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008299 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008300 }
Mike Stump11289f42009-09-09 15:08:12 +00008301
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008303 SubStmt.get() == E->getSubStmt()) {
8304 // Calling this an 'error' is unintuitive, but it does the right thing.
8305 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008306 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008307 }
Mike Stump11289f42009-09-09 15:08:12 +00008308
8309 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008310 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 E->getRParenLoc());
8312}
Mike Stump11289f42009-09-09 15:08:12 +00008313
Douglas Gregora16548e2009-08-11 05:31:07 +00008314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008316TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008317 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008318 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008320
John McCalldadc5752010-08-24 06:29:42 +00008321 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008322 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008324
John McCalldadc5752010-08-24 06:29:42 +00008325 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008326 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008328
Douglas Gregora16548e2009-08-11 05:31:07 +00008329 if (!getDerived().AlwaysRebuild() &&
8330 Cond.get() == E->getCond() &&
8331 LHS.get() == E->getLHS() &&
8332 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008333 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008336 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008337 E->getRParenLoc());
8338}
Mike Stump11289f42009-09-09 15:08:12 +00008339
Douglas Gregora16548e2009-08-11 05:31:07 +00008340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008341ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008342TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008343 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008344}
8345
8346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008347ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008348TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008349 switch (E->getOperator()) {
8350 case OO_New:
8351 case OO_Delete:
8352 case OO_Array_New:
8353 case OO_Array_Delete:
8354 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008355
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008356 case OO_Call: {
8357 // This is a call to an object's operator().
8358 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8359
8360 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008361 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008362 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008363 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008364
8365 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008366 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8367 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008368
8369 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008370 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008371 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008372 Args))
8373 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008374
John McCallb268a282010-08-23 23:25:46 +00008375 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008376 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008377 E->getLocEnd());
8378 }
8379
8380#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8381 case OO_##Name:
8382#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8383#include "clang/Basic/OperatorKinds.def"
8384 case OO_Subscript:
8385 // Handled below.
8386 break;
8387
8388 case OO_Conditional:
8389 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008390
8391 case OO_None:
8392 case NUM_OVERLOADED_OPERATORS:
8393 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008394 }
8395
John McCalldadc5752010-08-24 06:29:42 +00008396 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008397 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008399
Richard Smithdb2630f2012-10-21 03:28:35 +00008400 ExprResult First;
8401 if (E->getOperator() == OO_Amp)
8402 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8403 else
8404 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008405 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008406 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008407
John McCalldadc5752010-08-24 06:29:42 +00008408 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008409 if (E->getNumArgs() == 2) {
8410 Second = getDerived().TransformExpr(E->getArg(1));
8411 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008412 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008413 }
Mike Stump11289f42009-09-09 15:08:12 +00008414
Douglas Gregora16548e2009-08-11 05:31:07 +00008415 if (!getDerived().AlwaysRebuild() &&
8416 Callee.get() == E->getCallee() &&
8417 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008418 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008419 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008420
Lang Hames5de91cc2012-10-02 04:45:10 +00008421 Sema::FPContractStateRAII FPContractState(getSema());
8422 getSema().FPFeatures.fp_contract = E->isFPContractable();
8423
Douglas Gregora16548e2009-08-11 05:31:07 +00008424 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8425 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008426 Callee.get(),
8427 First.get(),
8428 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008429}
Mike Stump11289f42009-09-09 15:08:12 +00008430
Douglas Gregora16548e2009-08-11 05:31:07 +00008431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008433TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8434 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008435}
Mike Stump11289f42009-09-09 15:08:12 +00008436
Douglas Gregora16548e2009-08-11 05:31:07 +00008437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008438ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008439TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8440 // Transform the callee.
8441 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8442 if (Callee.isInvalid())
8443 return ExprError();
8444
8445 // Transform exec config.
8446 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8447 if (EC.isInvalid())
8448 return ExprError();
8449
8450 // Transform arguments.
8451 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008452 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008453 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008454 &ArgChanged))
8455 return ExprError();
8456
8457 if (!getDerived().AlwaysRebuild() &&
8458 Callee.get() == E->getCallee() &&
8459 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008460 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008461
8462 // FIXME: Wrong source location information for the '('.
8463 SourceLocation FakeLParenLoc
8464 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8465 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008466 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008467 E->getRParenLoc(), EC.get());
8468}
8469
8470template<typename Derived>
8471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008472TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008473 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8474 if (!Type)
8475 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
John McCalldadc5752010-08-24 06:29:42 +00008477 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008478 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008479 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008481
Douglas Gregora16548e2009-08-11 05:31:07 +00008482 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008483 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008484 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008485 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008486 return getDerived().RebuildCXXNamedCastExpr(
8487 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8488 Type, E->getAngleBrackets().getEnd(),
8489 // FIXME. this should be '(' location
8490 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008491}
Mike Stump11289f42009-09-09 15:08:12 +00008492
Douglas Gregora16548e2009-08-11 05:31:07 +00008493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008495TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8496 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008497}
Mike Stump11289f42009-09-09 15:08:12 +00008498
8499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008501TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8502 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008503}
8504
Douglas Gregora16548e2009-08-11 05:31:07 +00008505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008506ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008507TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008508 CXXReinterpretCastExpr *E) {
8509 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008510}
Mike Stump11289f42009-09-09 15:08:12 +00008511
Douglas Gregora16548e2009-08-11 05:31:07 +00008512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008513ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008514TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8515 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008516}
Mike Stump11289f42009-09-09 15:08:12 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008519ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008520TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008521 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008522 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8523 if (!Type)
8524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008525
John McCalldadc5752010-08-24 06:29:42 +00008526 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008527 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008528 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008530
Douglas Gregora16548e2009-08-11 05:31:07 +00008531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008532 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008533 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008534 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008536 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008537 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008538 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008539 E->getRParenLoc());
8540}
Mike Stump11289f42009-09-09 15:08:12 +00008541
Douglas Gregora16548e2009-08-11 05:31:07 +00008542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008544TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008545 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008546 TypeSourceInfo *TInfo
8547 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8548 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008550
Douglas Gregora16548e2009-08-11 05:31:07 +00008551 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008552 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008553 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008554
Douglas Gregor9da64192010-04-26 22:37:10 +00008555 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8556 E->getLocStart(),
8557 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008558 E->getLocEnd());
8559 }
Mike Stump11289f42009-09-09 15:08:12 +00008560
Eli Friedman456f0182012-01-20 01:26:23 +00008561 // We don't know whether the subexpression is potentially evaluated until
8562 // after we perform semantic analysis. We speculatively assume it is
8563 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008565 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8566 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008567
John McCalldadc5752010-08-24 06:29:42 +00008568 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008571
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 if (!getDerived().AlwaysRebuild() &&
8573 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008574 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008575
Douglas Gregor9da64192010-04-26 22:37:10 +00008576 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8577 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008578 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008579 E->getLocEnd());
8580}
8581
8582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008583ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008584TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8585 if (E->isTypeOperand()) {
8586 TypeSourceInfo *TInfo
8587 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8588 if (!TInfo)
8589 return ExprError();
8590
8591 if (!getDerived().AlwaysRebuild() &&
8592 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008593 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008594
Douglas Gregor69735112011-03-06 17:40:41 +00008595 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008596 E->getLocStart(),
8597 TInfo,
8598 E->getLocEnd());
8599 }
8600
Francois Pichet9f4f2072010-09-08 12:20:18 +00008601 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8602
8603 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8604 if (SubExpr.isInvalid())
8605 return ExprError();
8606
8607 if (!getDerived().AlwaysRebuild() &&
8608 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008609 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008610
8611 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8612 E->getLocStart(),
8613 SubExpr.get(),
8614 E->getLocEnd());
8615}
8616
8617template<typename Derived>
8618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008619TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008620 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008621}
Mike Stump11289f42009-09-09 15:08:12 +00008622
Douglas Gregora16548e2009-08-11 05:31:07 +00008623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008624ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008625TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008626 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008627 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008628}
Mike Stump11289f42009-09-09 15:08:12 +00008629
Douglas Gregora16548e2009-08-11 05:31:07 +00008630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008632TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008633 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008634
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008635 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8636 // Make sure that we capture 'this'.
8637 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008638 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008640
Douglas Gregorb15af892010-01-07 23:12:05 +00008641 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008642}
Mike Stump11289f42009-09-09 15:08:12 +00008643
Douglas Gregora16548e2009-08-11 05:31:07 +00008644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008646TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008647 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008648 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008649 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008650
Douglas Gregora16548e2009-08-11 05:31:07 +00008651 if (!getDerived().AlwaysRebuild() &&
8652 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008653 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008654
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008655 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8656 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008657}
Mike Stump11289f42009-09-09 15:08:12 +00008658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008660ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008661TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008662 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008663 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8664 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008665 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008667
Chandler Carruth794da4c2010-02-08 06:42:49 +00008668 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008669 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008670 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008671
Douglas Gregor033f6752009-12-23 23:03:06 +00008672 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008673}
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregora16548e2009-08-11 05:31:07 +00008675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008676ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008677TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8678 FieldDecl *Field
8679 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8680 E->getField()));
8681 if (!Field)
8682 return ExprError();
8683
8684 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008685 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008686
8687 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8688}
8689
8690template<typename Derived>
8691ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008692TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8693 CXXScalarValueInitExpr *E) {
8694 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8695 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008696 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008697
Douglas Gregora16548e2009-08-11 05:31:07 +00008698 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008699 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008700 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008701
Chad Rosier1dcde962012-08-08 18:46:20 +00008702 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008703 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008704 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008705}
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregora16548e2009-08-11 05:31:07 +00008707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008711 TypeSourceInfo *AllocTypeInfo
8712 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8713 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008714 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008715
Douglas Gregora16548e2009-08-11 05:31:07 +00008716 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008717 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008718 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008719 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008720
Douglas Gregora16548e2009-08-11 05:31:07 +00008721 // Transform the placement arguments (if any).
8722 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008723 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008724 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008725 E->getNumPlacementArgs(), true,
8726 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008728
Sebastian Redl6047f072012-02-16 12:22:20 +00008729 // Transform the initializer (if any).
8730 Expr *OldInit = E->getInitializer();
8731 ExprResult NewInit;
8732 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008733 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008734 if (NewInit.isInvalid())
8735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008736
Sebastian Redl6047f072012-02-16 12:22:20 +00008737 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008738 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008739 if (E->getOperatorNew()) {
8740 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008741 getDerived().TransformDecl(E->getLocStart(),
8742 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008743 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008744 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008745 }
8746
Craig Topperc3ec1492014-05-26 06:22:03 +00008747 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008748 if (E->getOperatorDelete()) {
8749 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008750 getDerived().TransformDecl(E->getLocStart(),
8751 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008752 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008753 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008755
Douglas Gregora16548e2009-08-11 05:31:07 +00008756 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008757 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008759 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008760 OperatorNew == E->getOperatorNew() &&
8761 OperatorDelete == E->getOperatorDelete() &&
8762 !ArgumentChanged) {
8763 // Mark any declarations we need as referenced.
8764 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008765 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008766 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008767 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008768 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008769
Sebastian Redl6047f072012-02-16 12:22:20 +00008770 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008771 QualType ElementType
8772 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8773 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8774 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8775 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008776 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008777 }
8778 }
8779 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008780
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008781 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008782 }
Mike Stump11289f42009-09-09 15:08:12 +00008783
Douglas Gregor0744ef62010-09-07 21:49:58 +00008784 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008785 if (!ArraySize.get()) {
8786 // If no array size was specified, but the new expression was
8787 // instantiated with an array type (e.g., "new T" where T is
8788 // instantiated with "int[4]"), extract the outer bound from the
8789 // array type as our array size. We do this with constant and
8790 // dependently-sized array types.
8791 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8792 if (!ArrayT) {
8793 // Do nothing
8794 } else if (const ConstantArrayType *ConsArrayT
8795 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008796 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8797 SemaRef.Context.getSizeType(),
8798 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008799 AllocType = ConsArrayT->getElementType();
8800 } else if (const DependentSizedArrayType *DepArrayT
8801 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8802 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008803 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008804 AllocType = DepArrayT->getElementType();
8805 }
8806 }
8807 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008808
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8810 E->isGlobalNew(),
8811 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008812 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008813 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008814 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008816 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008817 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008818 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008819 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008820}
Mike Stump11289f42009-09-09 15:08:12 +00008821
Douglas Gregora16548e2009-08-11 05:31:07 +00008822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008823ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008824TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008825 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008826 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008828
Douglas Gregord2d9da02010-02-26 00:38:10 +00008829 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008830 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008831 if (E->getOperatorDelete()) {
8832 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008833 getDerived().TransformDecl(E->getLocStart(),
8834 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008835 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008836 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008838
Douglas Gregora16548e2009-08-11 05:31:07 +00008839 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008840 Operand.get() == E->getArgument() &&
8841 OperatorDelete == E->getOperatorDelete()) {
8842 // Mark any declarations we need as referenced.
8843 // FIXME: instantiation-specific.
8844 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008845 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008846
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008847 if (!E->getArgument()->isTypeDependent()) {
8848 QualType Destroyed = SemaRef.Context.getBaseElementType(
8849 E->getDestroyedType());
8850 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8851 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008852 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008853 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008854 }
8855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008856
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008857 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008858 }
Mike Stump11289f42009-09-09 15:08:12 +00008859
Douglas Gregora16548e2009-08-11 05:31:07 +00008860 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8861 E->isGlobalDelete(),
8862 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008863 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008864}
Mike Stump11289f42009-09-09 15:08:12 +00008865
Douglas Gregora16548e2009-08-11 05:31:07 +00008866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008867ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008868TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008869 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008870 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008871 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008873
John McCallba7bf592010-08-24 05:47:05 +00008874 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008875 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008876 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008877 E->getOperatorLoc(),
8878 E->isArrow()? tok::arrow : tok::period,
8879 ObjectTypePtr,
8880 MayBePseudoDestructor);
8881 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008882 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
John McCallba7bf592010-08-24 05:47:05 +00008884 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008885 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8886 if (QualifierLoc) {
8887 QualifierLoc
8888 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8889 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008890 return ExprError();
8891 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008892 CXXScopeSpec SS;
8893 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008894
Douglas Gregor678f90d2010-02-25 01:56:36 +00008895 PseudoDestructorTypeStorage Destroyed;
8896 if (E->getDestroyedTypeInfo()) {
8897 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008898 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008899 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008900 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008901 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008902 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008903 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008904 // We aren't likely to be able to resolve the identifier down to a type
8905 // now anyway, so just retain the identifier.
8906 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8907 E->getDestroyedTypeLoc());
8908 } else {
8909 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008910 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008911 *E->getDestroyedTypeIdentifier(),
8912 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008913 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008914 SS, ObjectTypePtr,
8915 false);
8916 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008917 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008918
Douglas Gregor678f90d2010-02-25 01:56:36 +00008919 Destroyed
8920 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8921 E->getDestroyedTypeLoc());
8922 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008923
Craig Topperc3ec1492014-05-26 06:22:03 +00008924 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008925 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008926 CXXScopeSpec EmptySS;
8927 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008928 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008929 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008930 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008932
John McCallb268a282010-08-23 23:25:46 +00008933 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008934 E->getOperatorLoc(),
8935 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008936 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008937 ScopeTypeInfo,
8938 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008939 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008940 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008941}
Mike Stump11289f42009-09-09 15:08:12 +00008942
Douglas Gregorad8a3362009-09-04 17:36:40 +00008943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008944ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008945TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008946 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008947 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8948 Sema::LookupOrdinaryName);
8949
8950 // Transform all the decls.
8951 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8952 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008953 NamedDecl *InstD = static_cast<NamedDecl*>(
8954 getDerived().TransformDecl(Old->getNameLoc(),
8955 *I));
John McCall84d87672009-12-10 09:41:52 +00008956 if (!InstD) {
8957 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8958 // This can happen because of dependent hiding.
8959 if (isa<UsingShadowDecl>(*I))
8960 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008961 else {
8962 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008964 }
John McCall84d87672009-12-10 09:41:52 +00008965 }
John McCalle66edc12009-11-24 19:00:30 +00008966
8967 // Expand using declarations.
8968 if (isa<UsingDecl>(InstD)) {
8969 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00008970 for (auto *I : UD->shadows())
8971 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00008972 continue;
8973 }
8974
8975 R.addDecl(InstD);
8976 }
8977
8978 // Resolve a kind, but don't do any further analysis. If it's
8979 // ambiguous, the callee needs to deal with it.
8980 R.resolveKind();
8981
8982 // Rebuild the nested-name qualifier, if present.
8983 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00008984 if (Old->getQualifierLoc()) {
8985 NestedNameSpecifierLoc QualifierLoc
8986 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8987 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008988 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008989
Douglas Gregor0da1d432011-02-28 20:01:57 +00008990 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00008991 }
8992
Douglas Gregor9262f472010-04-27 18:19:34 +00008993 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00008994 CXXRecordDecl *NamingClass
8995 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
8996 Old->getNameLoc(),
8997 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00008998 if (!NamingClass) {
8999 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009000 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009002
Douglas Gregorda7be082010-04-27 16:10:10 +00009003 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009004 }
9005
Abramo Bagnara7945c982012-01-27 09:46:47 +00009006 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9007
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009008 // If we have neither explicit template arguments, nor the template keyword,
9009 // it's a normal declaration name.
9010 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009011 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9012
9013 // If we have template arguments, rebuild them, then rebuild the
9014 // templateid expression.
9015 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009016 if (Old->hasExplicitTemplateArgs() &&
9017 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009018 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009019 TransArgs)) {
9020 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009021 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009022 }
John McCalle66edc12009-11-24 19:00:30 +00009023
Abramo Bagnara7945c982012-01-27 09:46:47 +00009024 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009025 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009026}
Mike Stump11289f42009-09-09 15:08:12 +00009027
Douglas Gregora16548e2009-08-11 05:31:07 +00009028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009029ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009030TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9031 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009032 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009033 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9034 TypeSourceInfo *From = E->getArg(I);
9035 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009036 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009037 TypeLocBuilder TLB;
9038 TLB.reserve(FromTL.getFullDataSize());
9039 QualType To = getDerived().TransformType(TLB, FromTL);
9040 if (To.isNull())
9041 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009042
Douglas Gregor29c42f22012-02-24 07:38:34 +00009043 if (To == From->getType())
9044 Args.push_back(From);
9045 else {
9046 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9047 ArgChanged = true;
9048 }
9049 continue;
9050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009051
Douglas Gregor29c42f22012-02-24 07:38:34 +00009052 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
Douglas Gregor29c42f22012-02-24 07:38:34 +00009054 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009055 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009056 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9057 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9058 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009059
Douglas Gregor29c42f22012-02-24 07:38:34 +00009060 // Determine whether the set of unexpanded parameter packs can and should
9061 // be expanded.
9062 bool Expand = true;
9063 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009064 Optional<unsigned> OrigNumExpansions =
9065 ExpansionTL.getTypePtr()->getNumExpansions();
9066 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009067 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9068 PatternTL.getSourceRange(),
9069 Unexpanded,
9070 Expand, RetainExpansion,
9071 NumExpansions))
9072 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009073
Douglas Gregor29c42f22012-02-24 07:38:34 +00009074 if (!Expand) {
9075 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009076 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009077 // expansion.
9078 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009079
Douglas Gregor29c42f22012-02-24 07:38:34 +00009080 TypeLocBuilder TLB;
9081 TLB.reserve(From->getTypeLoc().getFullDataSize());
9082
9083 QualType To = getDerived().TransformType(TLB, PatternTL);
9084 if (To.isNull())
9085 return ExprError();
9086
Chad Rosier1dcde962012-08-08 18:46:20 +00009087 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009088 PatternTL.getSourceRange(),
9089 ExpansionTL.getEllipsisLoc(),
9090 NumExpansions);
9091 if (To.isNull())
9092 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009093
Douglas Gregor29c42f22012-02-24 07:38:34 +00009094 PackExpansionTypeLoc ToExpansionTL
9095 = TLB.push<PackExpansionTypeLoc>(To);
9096 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9097 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9098 continue;
9099 }
9100
9101 // Expand the pack expansion by substituting for each argument in the
9102 // pack(s).
9103 for (unsigned I = 0; I != *NumExpansions; ++I) {
9104 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9105 TypeLocBuilder TLB;
9106 TLB.reserve(PatternTL.getFullDataSize());
9107 QualType To = getDerived().TransformType(TLB, PatternTL);
9108 if (To.isNull())
9109 return ExprError();
9110
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009111 if (To->containsUnexpandedParameterPack()) {
9112 To = getDerived().RebuildPackExpansionType(To,
9113 PatternTL.getSourceRange(),
9114 ExpansionTL.getEllipsisLoc(),
9115 NumExpansions);
9116 if (To.isNull())
9117 return ExprError();
9118
9119 PackExpansionTypeLoc ToExpansionTL
9120 = TLB.push<PackExpansionTypeLoc>(To);
9121 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9122 }
9123
Douglas Gregor29c42f22012-02-24 07:38:34 +00009124 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009126
Douglas Gregor29c42f22012-02-24 07:38:34 +00009127 if (!RetainExpansion)
9128 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009129
Douglas Gregor29c42f22012-02-24 07:38:34 +00009130 // If we're supposed to retain a pack expansion, do so by temporarily
9131 // forgetting the partially-substituted parameter pack.
9132 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9133
9134 TypeLocBuilder TLB;
9135 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009136
Douglas Gregor29c42f22012-02-24 07:38:34 +00009137 QualType To = getDerived().TransformType(TLB, PatternTL);
9138 if (To.isNull())
9139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
9141 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009142 PatternTL.getSourceRange(),
9143 ExpansionTL.getEllipsisLoc(),
9144 NumExpansions);
9145 if (To.isNull())
9146 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009147
Douglas Gregor29c42f22012-02-24 07:38:34 +00009148 PackExpansionTypeLoc ToExpansionTL
9149 = TLB.push<PackExpansionTypeLoc>(To);
9150 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9151 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009153
Douglas Gregor29c42f22012-02-24 07:38:34 +00009154 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009155 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009156
9157 return getDerived().RebuildTypeTrait(E->getTrait(),
9158 E->getLocStart(),
9159 Args,
9160 E->getLocEnd());
9161}
9162
9163template<typename Derived>
9164ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009165TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9166 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9167 if (!T)
9168 return ExprError();
9169
9170 if (!getDerived().AlwaysRebuild() &&
9171 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009172 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009173
9174 ExprResult SubExpr;
9175 {
9176 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9177 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9178 if (SubExpr.isInvalid())
9179 return ExprError();
9180
9181 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009182 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009183 }
9184
9185 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9186 E->getLocStart(),
9187 T,
9188 SubExpr.get(),
9189 E->getLocEnd());
9190}
9191
9192template<typename Derived>
9193ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009194TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9195 ExprResult SubExpr;
9196 {
9197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9198 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9199 if (SubExpr.isInvalid())
9200 return ExprError();
9201
9202 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009203 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009204 }
9205
9206 return getDerived().RebuildExpressionTrait(
9207 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9208}
9209
Reid Kleckner32506ed2014-06-12 23:03:48 +00009210template <typename Derived>
9211ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9212 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9213 TypeSourceInfo **RecoveryTSI) {
9214 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9215 DRE, AddrTaken, RecoveryTSI);
9216
9217 // Propagate both errors and recovered types, which return ExprEmpty.
9218 if (!NewDRE.isUsable())
9219 return NewDRE;
9220
9221 // We got an expr, wrap it up in parens.
9222 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9223 return PE;
9224 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9225 PE->getRParen());
9226}
9227
9228template <typename Derived>
9229ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9230 DependentScopeDeclRefExpr *E) {
9231 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9232 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009233}
9234
9235template<typename Derived>
9236ExprResult
9237TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9238 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009239 bool IsAddressOfOperand,
9240 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009241 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009242 NestedNameSpecifierLoc QualifierLoc
9243 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9244 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009245 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009246 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009247
John McCall31f82722010-11-12 08:19:04 +00009248 // TODO: If this is a conversion-function-id, verify that the
9249 // destination type name (if present) resolves the same way after
9250 // instantiation as it did in the local scope.
9251
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009252 DeclarationNameInfo NameInfo
9253 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9254 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009256
John McCalle66edc12009-11-24 19:00:30 +00009257 if (!E->hasExplicitTemplateArgs()) {
9258 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009259 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009260 // Note: it is sufficient to compare the Name component of NameInfo:
9261 // if name has not changed, DNLoc has not changed either.
9262 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009263 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009264
Reid Kleckner32506ed2014-06-12 23:03:48 +00009265 return getDerived().RebuildDependentScopeDeclRefExpr(
9266 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9267 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009268 }
John McCall6b51f282009-11-23 01:53:49 +00009269
9270 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009271 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9272 E->getNumTemplateArgs(),
9273 TransArgs))
9274 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009275
Reid Kleckner32506ed2014-06-12 23:03:48 +00009276 return getDerived().RebuildDependentScopeDeclRefExpr(
9277 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9278 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009279}
9280
9281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009283TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009284 // CXXConstructExprs other than for list-initialization and
9285 // CXXTemporaryObjectExpr are always implicit, so when we have
9286 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009287 if ((E->getNumArgs() == 1 ||
9288 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009289 (!getDerived().DropCallArgument(E->getArg(0))) &&
9290 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009291 return getDerived().TransformExpr(E->getArg(0));
9292
Douglas Gregora16548e2009-08-11 05:31:07 +00009293 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9294
9295 QualType T = getDerived().TransformType(E->getType());
9296 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009297 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009298
9299 CXXConstructorDecl *Constructor
9300 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009301 getDerived().TransformDecl(E->getLocStart(),
9302 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009303 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009304 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009305
Douglas Gregora16548e2009-08-11 05:31:07 +00009306 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009307 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009308 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009309 &ArgumentChanged))
9310 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009311
Douglas Gregora16548e2009-08-11 05:31:07 +00009312 if (!getDerived().AlwaysRebuild() &&
9313 T == E->getType() &&
9314 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009315 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009316 // Mark the constructor as referenced.
9317 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009318 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009319 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009320 }
Mike Stump11289f42009-09-09 15:08:12 +00009321
Douglas Gregordb121ba2009-12-14 16:27:04 +00009322 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9323 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009324 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009325 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009326 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009327 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009328 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009329 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009330 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009331}
Mike Stump11289f42009-09-09 15:08:12 +00009332
Douglas Gregora16548e2009-08-11 05:31:07 +00009333/// \brief Transform a C++ temporary-binding expression.
9334///
Douglas Gregor363b1512009-12-24 18:51:59 +00009335/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9336/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009339TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009340 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009341}
Mike Stump11289f42009-09-09 15:08:12 +00009342
John McCall5d413782010-12-06 08:20:24 +00009343/// \brief Transform a C++ expression that contains cleanups that should
9344/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009345///
John McCall5d413782010-12-06 08:20:24 +00009346/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009347/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009349ExprResult
John McCall5d413782010-12-06 08:20:24 +00009350TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009351 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009352}
Mike Stump11289f42009-09-09 15:08:12 +00009353
Douglas Gregora16548e2009-08-11 05:31:07 +00009354template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009355ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009356TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009357 CXXTemporaryObjectExpr *E) {
9358 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9359 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009361
Douglas Gregora16548e2009-08-11 05:31:07 +00009362 CXXConstructorDecl *Constructor
9363 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009364 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009365 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009366 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009368
Douglas Gregora16548e2009-08-11 05:31:07 +00009369 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009370 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009371 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009372 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009373 &ArgumentChanged))
9374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009375
Douglas Gregora16548e2009-08-11 05:31:07 +00009376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009377 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009378 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009379 !ArgumentChanged) {
9380 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009381 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009382 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009384
Richard Smithd59b8322012-12-19 01:39:02 +00009385 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009386 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9387 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009388 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009389 E->getLocEnd());
9390}
Mike Stump11289f42009-09-09 15:08:12 +00009391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009393ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009394TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009395 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009396 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009397 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009398 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9399 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009400 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009401 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009402 CEnd = E->capture_end();
9403 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009404 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009405 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009406 EnterExpressionEvaluationContext EEEC(getSema(),
9407 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009408 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9409 C->getCapturedVar()->getInit(),
9410 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009411
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009412 if (NewExprInitResult.isInvalid())
9413 return ExprError();
9414 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009415
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009416 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009417 QualType NewInitCaptureType =
9418 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9419 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009420 NewExprInit);
9421 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009422 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9423 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009424 }
9425
Faisal Vali2cba1332013-10-23 06:44:28 +00009426 // Transform the template parameters, and add them to the current
9427 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009428 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009429 E->getTemplateParameterList());
9430
Richard Smith01014ce2014-11-20 23:53:14 +00009431 // Transform the type of the original lambda's call operator.
9432 // The transformation MUST be done in the CurrentInstantiationScope since
9433 // it introduces a mapping of the original to the newly created
9434 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009435 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009436 {
9437 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9438 FunctionProtoTypeLoc OldCallOpFPTL =
9439 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009440
9441 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009442 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009443 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009444 QualType NewCallOpType = TransformFunctionProtoType(
9445 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009446 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9447 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9448 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009449 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009450 if (NewCallOpType.isNull())
9451 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009452 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9453 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009454 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009455
Richard Smithc38498f2015-04-27 21:27:54 +00009456 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9457 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9458 LSI->GLTemplateParameterList = TPL;
9459
Eli Friedmand564afb2012-09-19 01:18:11 +00009460 // Create the local class that will describe the lambda.
9461 CXXRecordDecl *Class
9462 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009463 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009464 /*KnownDependent=*/false,
9465 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009466 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9467
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009468 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009469 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9470 Class, E->getIntroducerRange(), NewCallOpTSI,
9471 E->getCallOperator()->getLocEnd(),
9472 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009473 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009474
Faisal Vali2cba1332013-10-23 06:44:28 +00009475 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009476 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009477
Douglas Gregorb4328232012-02-14 00:00:48 +00009478 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009479 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009480 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009481
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009482 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009483 getSema().buildLambdaScope(LSI, NewCallOperator,
9484 E->getIntroducerRange(),
9485 E->getCaptureDefault(),
9486 E->getCaptureDefaultLoc(),
9487 E->hasExplicitParameters(),
9488 E->hasExplicitResultType(),
9489 E->isMutable());
9490
9491 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009492
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009493 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009494 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009495 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009496 CEnd = E->capture_end();
9497 C != CEnd; ++C) {
9498 // When we hit the first implicit capture, tell Sema that we've finished
9499 // the list of explicit captures.
9500 if (!FinishedExplicitCaptures && C->isImplicit()) {
9501 getSema().finishLambdaExplicitCaptures(LSI);
9502 FinishedExplicitCaptures = true;
9503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009504
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009505 // Capturing 'this' is trivial.
9506 if (C->capturesThis()) {
9507 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9508 continue;
9509 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009510 // Captured expression will be recaptured during captured variables
9511 // rebuilding.
9512 if (C->capturesVLAType())
9513 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009514
Richard Smithba71c082013-05-16 06:20:58 +00009515 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009516 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009517 InitCaptureInfoTy InitExprTypePair =
9518 InitCaptureExprsAndTypes[C - E->capture_begin()];
9519 ExprResult Init = InitExprTypePair.first;
9520 QualType InitQualType = InitExprTypePair.second;
9521 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009522 Invalid = true;
9523 continue;
9524 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009525 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009526 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9527 OldVD->getLocation(), InitExprTypePair.second,
9528 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009529 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009530 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009531 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009532 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009533 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009534 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009535 continue;
9536 }
9537
9538 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9539
Douglas Gregor3e308b12012-02-14 19:27:52 +00009540 // Determine the capture kind for Sema.
9541 Sema::TryCaptureKind Kind
9542 = C->isImplicit()? Sema::TryCapture_Implicit
9543 : C->getCaptureKind() == LCK_ByCopy
9544 ? Sema::TryCapture_ExplicitByVal
9545 : Sema::TryCapture_ExplicitByRef;
9546 SourceLocation EllipsisLoc;
9547 if (C->isPackExpansion()) {
9548 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9549 bool ShouldExpand = false;
9550 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009551 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009552 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9553 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009554 Unexpanded,
9555 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009556 NumExpansions)) {
9557 Invalid = true;
9558 continue;
9559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009560
Douglas Gregor3e308b12012-02-14 19:27:52 +00009561 if (ShouldExpand) {
9562 // The transform has determined that we should perform an expansion;
9563 // transform and capture each of the arguments.
9564 // expansion of the pattern. Do so.
9565 VarDecl *Pack = C->getCapturedVar();
9566 for (unsigned I = 0; I != *NumExpansions; ++I) {
9567 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9568 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009569 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009570 Pack));
9571 if (!CapturedVar) {
9572 Invalid = true;
9573 continue;
9574 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009575
Douglas Gregor3e308b12012-02-14 19:27:52 +00009576 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009577 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9578 }
Richard Smith9467be42014-06-06 17:33:35 +00009579
9580 // FIXME: Retain a pack expansion if RetainExpansion is true.
9581
Douglas Gregor3e308b12012-02-14 19:27:52 +00009582 continue;
9583 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009584
Douglas Gregor3e308b12012-02-14 19:27:52 +00009585 EllipsisLoc = C->getEllipsisLoc();
9586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009588 // Transform the captured variable.
9589 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009590 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009591 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009592 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009593 Invalid = true;
9594 continue;
9595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009596
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009597 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009598 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9599 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009600 }
9601 if (!FinishedExplicitCaptures)
9602 getSema().finishLambdaExplicitCaptures(LSI);
9603
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009604 // Enter a new evaluation context to insulate the lambda from any
9605 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009606 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009607
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009608 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009609 StmtResult Body =
9610 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9611
9612 // ActOnLambda* will pop the function scope for us.
9613 FuncScopeCleanup.disable();
9614
Douglas Gregorb4328232012-02-14 00:00:48 +00009615 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009616 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009617 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009618 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009619 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009620 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009621
Richard Smithc38498f2015-04-27 21:27:54 +00009622 // Copy the LSI before ActOnFinishFunctionBody removes it.
9623 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9624 // the call operator.
9625 auto LSICopy = *LSI;
9626 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9627 /*IsInstantiation*/ true);
9628 SavedContext.pop();
9629
9630 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9631 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009632}
9633
9634template<typename Derived>
9635ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009636TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009637 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009638 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9639 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009641
Douglas Gregora16548e2009-08-11 05:31:07 +00009642 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009643 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009644 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009645 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009646 &ArgumentChanged))
9647 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009648
Douglas Gregora16548e2009-08-11 05:31:07 +00009649 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009650 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009651 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009653
Douglas Gregora16548e2009-08-11 05:31:07 +00009654 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009655 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009657 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009658 E->getRParenLoc());
9659}
Mike Stump11289f42009-09-09 15:08:12 +00009660
Douglas Gregora16548e2009-08-11 05:31:07 +00009661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009662ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009663TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009664 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009665 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009666 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009667 Expr *OldBase;
9668 QualType BaseType;
9669 QualType ObjectType;
9670 if (!E->isImplicitAccess()) {
9671 OldBase = E->getBase();
9672 Base = getDerived().TransformExpr(OldBase);
9673 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009674 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009675
John McCall2d74de92009-12-01 22:10:20 +00009676 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009677 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009678 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009679 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009680 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009681 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009682 ObjectTy,
9683 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009684 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009685 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009686
John McCallba7bf592010-08-24 05:47:05 +00009687 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009688 BaseType = ((Expr*) Base.get())->getType();
9689 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009690 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009691 BaseType = getDerived().TransformType(E->getBaseType());
9692 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9693 }
Mike Stump11289f42009-09-09 15:08:12 +00009694
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009695 // Transform the first part of the nested-name-specifier that qualifies
9696 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009697 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009698 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009699 E->getFirstQualifierFoundInScope(),
9700 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009701
Douglas Gregore16af532011-02-28 18:50:33 +00009702 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009703 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009704 QualifierLoc
9705 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9706 ObjectType,
9707 FirstQualifierInScope);
9708 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009709 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009710 }
Mike Stump11289f42009-09-09 15:08:12 +00009711
Abramo Bagnara7945c982012-01-27 09:46:47 +00009712 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9713
John McCall31f82722010-11-12 08:19:04 +00009714 // TODO: If this is a conversion-function-id, verify that the
9715 // destination type name (if present) resolves the same way after
9716 // instantiation as it did in the local scope.
9717
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009718 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009719 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009720 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009722
John McCall2d74de92009-12-01 22:10:20 +00009723 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009724 // This is a reference to a member without an explicitly-specified
9725 // template argument list. Optimize for this common case.
9726 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009727 Base.get() == OldBase &&
9728 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009729 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009730 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009731 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009732 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009733
John McCallb268a282010-08-23 23:25:46 +00009734 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009735 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009736 E->isArrow(),
9737 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009738 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009739 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009740 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009741 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009742 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009743 }
9744
John McCall6b51f282009-11-23 01:53:49 +00009745 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009746 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9747 E->getNumTemplateArgs(),
9748 TransArgs))
9749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009750
John McCallb268a282010-08-23 23:25:46 +00009751 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009752 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 E->isArrow(),
9754 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009755 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009756 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009757 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009758 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009759 &TransArgs);
9760}
9761
9762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009764TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009765 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009766 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009767 QualType BaseType;
9768 if (!Old->isImplicitAccess()) {
9769 Base = getDerived().TransformExpr(Old->getBase());
9770 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009771 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009772 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009773 Old->isArrow());
9774 if (Base.isInvalid())
9775 return ExprError();
9776 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009777 } else {
9778 BaseType = getDerived().TransformType(Old->getBaseType());
9779 }
John McCall10eae182009-11-30 22:42:35 +00009780
Douglas Gregor0da1d432011-02-28 20:01:57 +00009781 NestedNameSpecifierLoc QualifierLoc;
9782 if (Old->getQualifierLoc()) {
9783 QualifierLoc
9784 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9785 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009786 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009787 }
9788
Abramo Bagnara7945c982012-01-27 09:46:47 +00009789 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9790
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009791 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009792 Sema::LookupOrdinaryName);
9793
9794 // Transform all the decls.
9795 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9796 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009797 NamedDecl *InstD = static_cast<NamedDecl*>(
9798 getDerived().TransformDecl(Old->getMemberLoc(),
9799 *I));
John McCall84d87672009-12-10 09:41:52 +00009800 if (!InstD) {
9801 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9802 // This can happen because of dependent hiding.
9803 if (isa<UsingShadowDecl>(*I))
9804 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009805 else {
9806 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009807 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009808 }
John McCall84d87672009-12-10 09:41:52 +00009809 }
John McCall10eae182009-11-30 22:42:35 +00009810
9811 // Expand using declarations.
9812 if (isa<UsingDecl>(InstD)) {
9813 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009814 for (auto *I : UD->shadows())
9815 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009816 continue;
9817 }
9818
9819 R.addDecl(InstD);
9820 }
9821
9822 R.resolveKind();
9823
Douglas Gregor9262f472010-04-27 18:19:34 +00009824 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009825 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009826 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009827 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009828 Old->getMemberLoc(),
9829 Old->getNamingClass()));
9830 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009831 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009832
Douglas Gregorda7be082010-04-27 16:10:10 +00009833 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009834 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009835
John McCall10eae182009-11-30 22:42:35 +00009836 TemplateArgumentListInfo TransArgs;
9837 if (Old->hasExplicitTemplateArgs()) {
9838 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9839 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009840 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9841 Old->getNumTemplateArgs(),
9842 TransArgs))
9843 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009844 }
John McCall38836f02010-01-15 08:34:02 +00009845
9846 // FIXME: to do this check properly, we will need to preserve the
9847 // first-qualifier-in-scope here, just in case we had a dependent
9848 // base (and therefore couldn't do the check) and a
9849 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009850 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009851
John McCallb268a282010-08-23 23:25:46 +00009852 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009853 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009854 Old->getOperatorLoc(),
9855 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009856 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009857 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009858 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009859 R,
9860 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009861 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009862}
9863
9864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009865ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009866TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009867 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009868 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9869 if (SubExpr.isInvalid())
9870 return ExprError();
9871
9872 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009873 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009874
9875 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9876}
9877
9878template<typename Derived>
9879ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009880TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009881 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9882 if (Pattern.isInvalid())
9883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009884
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009885 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009886 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009887
Douglas Gregorb8840002011-01-14 21:20:45 +00009888 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9889 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009890}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009891
9892template<typename Derived>
9893ExprResult
9894TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9895 // If E is not value-dependent, then nothing will change when we transform it.
9896 // Note: This is an instantiation-centric view.
9897 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009898 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009899
9900 // Note: None of the implementations of TryExpandParameterPacks can ever
9901 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009902 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009903 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9904 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009905 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009906 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009907 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009908 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009909 ShouldExpand, RetainExpansion,
9910 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009911 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009912
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009913 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009914 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009915
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009916 NamedDecl *Pack = E->getPack();
9917 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009918 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009919 Pack));
9920 if (!Pack)
9921 return ExprError();
9922 }
9923
Chad Rosier1dcde962012-08-08 18:46:20 +00009924
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009925 // We now know the length of the parameter pack, so build a new expression
9926 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009927 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9928 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009929 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009930}
9931
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009932template<typename Derived>
9933ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009934TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9935 SubstNonTypeTemplateParmPackExpr *E) {
9936 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009937 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009938}
9939
9940template<typename Derived>
9941ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009942TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9943 SubstNonTypeTemplateParmExpr *E) {
9944 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009945 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009946}
9947
9948template<typename Derived>
9949ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009950TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9951 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009952 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009953}
9954
9955template<typename Derived>
9956ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009957TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9958 MaterializeTemporaryExpr *E) {
9959 return getDerived().TransformExpr(E->GetTemporaryExpr());
9960}
Chad Rosier1dcde962012-08-08 18:46:20 +00009961
Douglas Gregorfe314812011-06-21 17:03:29 +00009962template<typename Derived>
9963ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009964TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9965 Expr *Pattern = E->getPattern();
9966
9967 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9968 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
9969 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
9970
9971 // Determine whether the set of unexpanded parameter packs can and should
9972 // be expanded.
9973 bool Expand = true;
9974 bool RetainExpansion = false;
9975 Optional<unsigned> NumExpansions;
9976 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
9977 Pattern->getSourceRange(),
9978 Unexpanded,
9979 Expand, RetainExpansion,
9980 NumExpansions))
9981 return true;
9982
9983 if (!Expand) {
9984 // Do not expand any packs here, just transform and rebuild a fold
9985 // expression.
9986 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
9987
9988 ExprResult LHS =
9989 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
9990 if (LHS.isInvalid())
9991 return true;
9992
9993 ExprResult RHS =
9994 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
9995 if (RHS.isInvalid())
9996 return true;
9997
9998 if (!getDerived().AlwaysRebuild() &&
9999 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10000 return E;
10001
10002 return getDerived().RebuildCXXFoldExpr(
10003 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10004 RHS.get(), E->getLocEnd());
10005 }
10006
10007 // The transform has determined that we should perform an elementwise
10008 // expansion of the pattern. Do so.
10009 ExprResult Result = getDerived().TransformExpr(E->getInit());
10010 if (Result.isInvalid())
10011 return true;
10012 bool LeftFold = E->isLeftFold();
10013
10014 // If we're retaining an expansion for a right fold, it is the innermost
10015 // component and takes the init (if any).
10016 if (!LeftFold && RetainExpansion) {
10017 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10018
10019 ExprResult Out = getDerived().TransformExpr(Pattern);
10020 if (Out.isInvalid())
10021 return true;
10022
10023 Result = getDerived().RebuildCXXFoldExpr(
10024 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10025 Result.get(), E->getLocEnd());
10026 if (Result.isInvalid())
10027 return true;
10028 }
10029
10030 for (unsigned I = 0; I != *NumExpansions; ++I) {
10031 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10032 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10033 ExprResult Out = getDerived().TransformExpr(Pattern);
10034 if (Out.isInvalid())
10035 return true;
10036
10037 if (Out.get()->containsUnexpandedParameterPack()) {
10038 // We still have a pack; retain a pack expansion for this slice.
10039 Result = getDerived().RebuildCXXFoldExpr(
10040 E->getLocStart(),
10041 LeftFold ? Result.get() : Out.get(),
10042 E->getOperator(), E->getEllipsisLoc(),
10043 LeftFold ? Out.get() : Result.get(),
10044 E->getLocEnd());
10045 } else if (Result.isUsable()) {
10046 // We've got down to a single element; build a binary operator.
10047 Result = getDerived().RebuildBinaryOperator(
10048 E->getEllipsisLoc(), E->getOperator(),
10049 LeftFold ? Result.get() : Out.get(),
10050 LeftFold ? Out.get() : Result.get());
10051 } else
10052 Result = Out;
10053
10054 if (Result.isInvalid())
10055 return true;
10056 }
10057
10058 // If we're retaining an expansion for a left fold, it is the outermost
10059 // component and takes the complete expansion so far as its init (if any).
10060 if (LeftFold && RetainExpansion) {
10061 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10062
10063 ExprResult Out = getDerived().TransformExpr(Pattern);
10064 if (Out.isInvalid())
10065 return true;
10066
10067 Result = getDerived().RebuildCXXFoldExpr(
10068 E->getLocStart(), Result.get(),
10069 E->getOperator(), E->getEllipsisLoc(),
10070 Out.get(), E->getLocEnd());
10071 if (Result.isInvalid())
10072 return true;
10073 }
10074
10075 // If we had no init and an empty pack, and we're not retaining an expansion,
10076 // then produce a fallback value or error.
10077 if (Result.isUnset())
10078 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10079 E->getOperator());
10080
10081 return Result;
10082}
10083
10084template<typename Derived>
10085ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010086TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10087 CXXStdInitializerListExpr *E) {
10088 return getDerived().TransformExpr(E->getSubExpr());
10089}
10090
10091template<typename Derived>
10092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010093TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010094 return SemaRef.MaybeBindToTemporary(E);
10095}
10096
10097template<typename Derived>
10098ExprResult
10099TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010100 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010101}
10102
10103template<typename Derived>
10104ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010105TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10106 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10107 if (SubExpr.isInvalid())
10108 return ExprError();
10109
10110 if (!getDerived().AlwaysRebuild() &&
10111 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010112 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010113
10114 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010115}
10116
10117template<typename Derived>
10118ExprResult
10119TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10120 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010121 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010122 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010123 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010124 /*IsCall=*/false, Elements, &ArgChanged))
10125 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010126
Ted Kremeneke65b0862012-03-06 20:05:56 +000010127 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10128 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010129
Ted Kremeneke65b0862012-03-06 20:05:56 +000010130 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10131 Elements.data(),
10132 Elements.size());
10133}
10134
10135template<typename Derived>
10136ExprResult
10137TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010138 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010139 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010140 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010141 bool ArgChanged = false;
10142 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10143 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010144
Ted Kremeneke65b0862012-03-06 20:05:56 +000010145 if (OrigElement.isPackExpansion()) {
10146 // This key/value element is a pack expansion.
10147 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10148 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10149 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10150 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10151
10152 // Determine whether the set of unexpanded parameter packs can
10153 // and should be expanded.
10154 bool Expand = true;
10155 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010156 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10157 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010158 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10159 OrigElement.Value->getLocEnd());
10160 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10161 PatternRange,
10162 Unexpanded,
10163 Expand, RetainExpansion,
10164 NumExpansions))
10165 return ExprError();
10166
10167 if (!Expand) {
10168 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010169 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010170 // expansion.
10171 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10172 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10173 if (Key.isInvalid())
10174 return ExprError();
10175
10176 if (Key.get() != OrigElement.Key)
10177 ArgChanged = true;
10178
10179 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10180 if (Value.isInvalid())
10181 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010182
Ted Kremeneke65b0862012-03-06 20:05:56 +000010183 if (Value.get() != OrigElement.Value)
10184 ArgChanged = true;
10185
Chad Rosier1dcde962012-08-08 18:46:20 +000010186 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010187 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10188 };
10189 Elements.push_back(Expansion);
10190 continue;
10191 }
10192
10193 // Record right away that the argument was changed. This needs
10194 // to happen even if the array expands to nothing.
10195 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010196
Ted Kremeneke65b0862012-03-06 20:05:56 +000010197 // The transform has determined that we should perform an elementwise
10198 // expansion of the pattern. Do so.
10199 for (unsigned I = 0; I != *NumExpansions; ++I) {
10200 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10201 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10202 if (Key.isInvalid())
10203 return ExprError();
10204
10205 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10206 if (Value.isInvalid())
10207 return ExprError();
10208
Chad Rosier1dcde962012-08-08 18:46:20 +000010209 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010210 Key.get(), Value.get(), SourceLocation(), NumExpansions
10211 };
10212
10213 // If any unexpanded parameter packs remain, we still have a
10214 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010215 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010216 if (Key.get()->containsUnexpandedParameterPack() ||
10217 Value.get()->containsUnexpandedParameterPack())
10218 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010219
Ted Kremeneke65b0862012-03-06 20:05:56 +000010220 Elements.push_back(Element);
10221 }
10222
Richard Smith9467be42014-06-06 17:33:35 +000010223 // FIXME: Retain a pack expansion if RetainExpansion is true.
10224
Ted Kremeneke65b0862012-03-06 20:05:56 +000010225 // We've finished with this pack expansion.
10226 continue;
10227 }
10228
10229 // Transform and check key.
10230 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10231 if (Key.isInvalid())
10232 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010233
Ted Kremeneke65b0862012-03-06 20:05:56 +000010234 if (Key.get() != OrigElement.Key)
10235 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010236
Ted Kremeneke65b0862012-03-06 20:05:56 +000010237 // Transform and check value.
10238 ExprResult Value
10239 = getDerived().TransformExpr(OrigElement.Value);
10240 if (Value.isInvalid())
10241 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010242
Ted Kremeneke65b0862012-03-06 20:05:56 +000010243 if (Value.get() != OrigElement.Value)
10244 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010245
10246 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010247 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010248 };
10249 Elements.push_back(Element);
10250 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010251
Ted Kremeneke65b0862012-03-06 20:05:56 +000010252 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10253 return SemaRef.MaybeBindToTemporary(E);
10254
10255 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10256 Elements.data(),
10257 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010258}
10259
Mike Stump11289f42009-09-09 15:08:12 +000010260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010262TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010263 TypeSourceInfo *EncodedTypeInfo
10264 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10265 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010267
Douglas Gregora16548e2009-08-11 05:31:07 +000010268 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010269 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010270 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010271
10272 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010273 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010274 E->getRParenLoc());
10275}
Mike Stump11289f42009-09-09 15:08:12 +000010276
Douglas Gregora16548e2009-08-11 05:31:07 +000010277template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010278ExprResult TreeTransform<Derived>::
10279TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010280 // This is a kind of implicit conversion, and it needs to get dropped
10281 // and recomputed for the same general reasons that ImplicitCastExprs
10282 // do, as well a more specific one: this expression is only valid when
10283 // it appears *immediately* as an argument expression.
10284 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010285}
10286
10287template<typename Derived>
10288ExprResult TreeTransform<Derived>::
10289TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010290 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010291 = getDerived().TransformType(E->getTypeInfoAsWritten());
10292 if (!TSInfo)
10293 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010294
John McCall31168b02011-06-15 23:02:42 +000010295 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010296 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010297 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010298
John McCall31168b02011-06-15 23:02:42 +000010299 if (!getDerived().AlwaysRebuild() &&
10300 TSInfo == E->getTypeInfoAsWritten() &&
10301 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010302 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010303
John McCall31168b02011-06-15 23:02:42 +000010304 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010305 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010306 Result.get());
10307}
10308
10309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010310ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010311TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010312 // Transform arguments.
10313 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010314 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010315 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010316 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010317 &ArgChanged))
10318 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010319
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010320 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10321 // Class message: transform the receiver type.
10322 TypeSourceInfo *ReceiverTypeInfo
10323 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10324 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010325 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010326
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010327 // If nothing changed, just retain the existing message send.
10328 if (!getDerived().AlwaysRebuild() &&
10329 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010330 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010331
10332 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010333 SmallVector<SourceLocation, 16> SelLocs;
10334 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010335 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10336 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010337 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010338 E->getMethodDecl(),
10339 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010340 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010341 E->getRightLoc());
10342 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010343 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10344 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10345 // Build a new class message send to 'super'.
10346 SmallVector<SourceLocation, 16> SelLocs;
10347 E->getSelectorLocs(SelLocs);
10348 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10349 E->getSelector(),
10350 SelLocs,
10351 E->getMethodDecl(),
10352 E->getLeftLoc(),
10353 Args,
10354 E->getRightLoc());
10355 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010356
10357 // Instance message: transform the receiver
10358 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10359 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010360 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010361 = getDerived().TransformExpr(E->getInstanceReceiver());
10362 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010363 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010364
10365 // If nothing changed, just retain the existing message send.
10366 if (!getDerived().AlwaysRebuild() &&
10367 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010368 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010369
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010370 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010371 SmallVector<SourceLocation, 16> SelLocs;
10372 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010373 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010374 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010375 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010376 E->getMethodDecl(),
10377 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010378 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010379 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010380}
10381
Mike Stump11289f42009-09-09 15:08:12 +000010382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010384TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010385 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010386}
10387
Mike Stump11289f42009-09-09 15:08:12 +000010388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010389ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010390TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010391 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010392}
10393
Mike Stump11289f42009-09-09 15:08:12 +000010394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010396TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010397 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010398 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010399 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010400 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010401
10402 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010403
Douglas Gregord51d90d2010-04-26 20:11:03 +000010404 // If nothing changed, just retain the existing expression.
10405 if (!getDerived().AlwaysRebuild() &&
10406 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010407 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010408
John McCallb268a282010-08-23 23:25:46 +000010409 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010410 E->getLocation(),
10411 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010412}
10413
Mike Stump11289f42009-09-09 15:08:12 +000010414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010416TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010417 // 'super' and types never change. Property never changes. Just
10418 // retain the existing expression.
10419 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010420 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010421
Douglas Gregor9faee212010-04-26 20:47:02 +000010422 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010423 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010424 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010425 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010426
Douglas Gregor9faee212010-04-26 20:47:02 +000010427 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010428
Douglas Gregor9faee212010-04-26 20:47:02 +000010429 // If nothing changed, just retain the existing expression.
10430 if (!getDerived().AlwaysRebuild() &&
10431 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010432 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010433
John McCallb7bd14f2010-12-02 01:19:52 +000010434 if (E->isExplicitProperty())
10435 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10436 E->getExplicitProperty(),
10437 E->getLocation());
10438
10439 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010440 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010441 E->getImplicitPropertyGetter(),
10442 E->getImplicitPropertySetter(),
10443 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010444}
10445
Mike Stump11289f42009-09-09 15:08:12 +000010446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010447ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010448TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10449 // Transform the base expression.
10450 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10451 if (Base.isInvalid())
10452 return ExprError();
10453
10454 // Transform the key expression.
10455 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10456 if (Key.isInvalid())
10457 return ExprError();
10458
10459 // If nothing changed, just retain the existing expression.
10460 if (!getDerived().AlwaysRebuild() &&
10461 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010462 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010463
Chad Rosier1dcde962012-08-08 18:46:20 +000010464 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010465 Base.get(), Key.get(),
10466 E->getAtIndexMethodDecl(),
10467 E->setAtIndexMethodDecl());
10468}
10469
10470template<typename Derived>
10471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010472TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010473 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010474 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010475 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010476 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010477
Douglas Gregord51d90d2010-04-26 20:11:03 +000010478 // If nothing changed, just retain the existing expression.
10479 if (!getDerived().AlwaysRebuild() &&
10480 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010481 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010482
John McCallb268a282010-08-23 23:25:46 +000010483 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010484 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010485 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010486}
10487
Mike Stump11289f42009-09-09 15:08:12 +000010488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010490TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010491 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010492 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010493 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010494 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010495 SubExprs, &ArgumentChanged))
10496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010497
Douglas Gregora16548e2009-08-11 05:31:07 +000010498 if (!getDerived().AlwaysRebuild() &&
10499 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010500 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010501
Douglas Gregora16548e2009-08-11 05:31:07 +000010502 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010503 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010504 E->getRParenLoc());
10505}
10506
Mike Stump11289f42009-09-09 15:08:12 +000010507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010508ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010509TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10510 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10511 if (SrcExpr.isInvalid())
10512 return ExprError();
10513
10514 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10515 if (!Type)
10516 return ExprError();
10517
10518 if (!getDerived().AlwaysRebuild() &&
10519 Type == E->getTypeSourceInfo() &&
10520 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010521 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010522
10523 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10524 SrcExpr.get(), Type,
10525 E->getRParenLoc());
10526}
10527
10528template<typename Derived>
10529ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010530TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010531 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010532
Craig Topperc3ec1492014-05-26 06:22:03 +000010533 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010534 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10535
10536 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010537 blockScope->TheDecl->setBlockMissingReturnType(
10538 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010539
Chris Lattner01cf8db2011-07-20 06:58:45 +000010540 SmallVector<ParmVarDecl*, 4> params;
10541 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010542
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010543 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010544 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10545 oldBlock->param_begin(),
10546 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010547 nullptr, paramTypes, &params)) {
10548 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010549 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010550 }
John McCall490112f2011-02-04 18:33:18 +000010551
Jordan Rosea0a86be2013-03-08 22:25:36 +000010552 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010553 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010554 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010555
Jordan Rose5c382722013-03-08 21:51:21 +000010556 QualType functionType =
10557 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010558 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010559 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010560
10561 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010562 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010563 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010564
10565 if (!oldBlock->blockMissingReturnType()) {
10566 blockScope->HasImplicitReturnType = false;
10567 blockScope->ReturnType = exprResultType;
10568 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010569
John McCall3882ace2011-01-05 12:14:39 +000010570 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010571 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010572 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010573 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010574 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010575 }
John McCall3882ace2011-01-05 12:14:39 +000010576
John McCall490112f2011-02-04 18:33:18 +000010577#ifndef NDEBUG
10578 // In builds with assertions, make sure that we captured everything we
10579 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010580 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010581 for (const auto &I : oldBlock->captures()) {
10582 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010583
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010584 // Ignore parameter packs.
10585 if (isa<ParmVarDecl>(oldCapture) &&
10586 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10587 continue;
John McCall490112f2011-02-04 18:33:18 +000010588
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010589 VarDecl *newCapture =
10590 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10591 oldCapture));
10592 assert(blockScope->CaptureMap.count(newCapture));
10593 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010594 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010595 }
10596#endif
10597
10598 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010599 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010600}
10601
Mike Stump11289f42009-09-09 15:08:12 +000010602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010603ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010604TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010605 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010606}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010607
10608template<typename Derived>
10609ExprResult
10610TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010611 QualType RetTy = getDerived().TransformType(E->getType());
10612 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010613 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010614 SubExprs.reserve(E->getNumSubExprs());
10615 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10616 SubExprs, &ArgumentChanged))
10617 return ExprError();
10618
10619 if (!getDerived().AlwaysRebuild() &&
10620 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010621 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010622
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010623 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010624 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010625}
Chad Rosier1dcde962012-08-08 18:46:20 +000010626
Douglas Gregora16548e2009-08-11 05:31:07 +000010627//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010628// Type reconstruction
10629//===----------------------------------------------------------------------===//
10630
Mike Stump11289f42009-09-09 15:08:12 +000010631template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010632QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10633 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010634 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010635 getDerived().getBaseEntity());
10636}
10637
Mike Stump11289f42009-09-09 15:08:12 +000010638template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010639QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10640 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010641 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010642 getDerived().getBaseEntity());
10643}
10644
Mike Stump11289f42009-09-09 15:08:12 +000010645template<typename Derived>
10646QualType
John McCall70dd5f62009-10-30 00:06:24 +000010647TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10648 bool WrittenAsLValue,
10649 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010650 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010651 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010652}
10653
10654template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010655QualType
John McCall70dd5f62009-10-30 00:06:24 +000010656TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10657 QualType ClassType,
10658 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010659 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10660 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010661}
10662
10663template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010664QualType TreeTransform<Derived>::RebuildObjCObjectType(
10665 QualType BaseType,
10666 SourceLocation Loc,
10667 SourceLocation TypeArgsLAngleLoc,
10668 ArrayRef<TypeSourceInfo *> TypeArgs,
10669 SourceLocation TypeArgsRAngleLoc,
10670 SourceLocation ProtocolLAngleLoc,
10671 ArrayRef<ObjCProtocolDecl *> Protocols,
10672 ArrayRef<SourceLocation> ProtocolLocs,
10673 SourceLocation ProtocolRAngleLoc) {
10674 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10675 TypeArgs, TypeArgsRAngleLoc,
10676 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10677 ProtocolRAngleLoc,
10678 /*FailOnError=*/true);
10679}
10680
10681template<typename Derived>
10682QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10683 QualType PointeeType,
10684 SourceLocation Star) {
10685 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10686}
10687
10688template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010689QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010690TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10691 ArrayType::ArraySizeModifier SizeMod,
10692 const llvm::APInt *Size,
10693 Expr *SizeExpr,
10694 unsigned IndexTypeQuals,
10695 SourceRange BracketsRange) {
10696 if (SizeExpr || !Size)
10697 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10698 IndexTypeQuals, BracketsRange,
10699 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010700
10701 QualType Types[] = {
10702 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10703 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10704 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010705 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010706 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010707 QualType SizeType;
10708 for (unsigned I = 0; I != NumTypes; ++I)
10709 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10710 SizeType = Types[I];
10711 break;
10712 }
Mike Stump11289f42009-09-09 15:08:12 +000010713
Eli Friedman9562f392012-01-25 23:20:27 +000010714 // Note that we can return a VariableArrayType here in the case where
10715 // the element type was a dependent VariableArrayType.
10716 IntegerLiteral *ArraySize
10717 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10718 /*FIXME*/BracketsRange.getBegin());
10719 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010720 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010721 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010722}
Mike Stump11289f42009-09-09 15:08:12 +000010723
Douglas Gregord6ff3322009-08-04 16:50:30 +000010724template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010725QualType
10726TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010727 ArrayType::ArraySizeModifier SizeMod,
10728 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010729 unsigned IndexTypeQuals,
10730 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010731 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010732 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010733}
10734
10735template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010736QualType
Mike Stump11289f42009-09-09 15:08:12 +000010737TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010738 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010739 unsigned IndexTypeQuals,
10740 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010741 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010742 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010743}
Mike Stump11289f42009-09-09 15:08:12 +000010744
Douglas Gregord6ff3322009-08-04 16:50:30 +000010745template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010746QualType
10747TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010748 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010749 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010750 unsigned IndexTypeQuals,
10751 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010752 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010753 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010754 IndexTypeQuals, BracketsRange);
10755}
10756
10757template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010758QualType
10759TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010760 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010761 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010762 unsigned IndexTypeQuals,
10763 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010764 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010765 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010766 IndexTypeQuals, BracketsRange);
10767}
10768
10769template<typename Derived>
10770QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010771 unsigned NumElements,
10772 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010773 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010774 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010775}
Mike Stump11289f42009-09-09 15:08:12 +000010776
Douglas Gregord6ff3322009-08-04 16:50:30 +000010777template<typename Derived>
10778QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10779 unsigned NumElements,
10780 SourceLocation AttributeLoc) {
10781 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10782 NumElements, true);
10783 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010784 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10785 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010786 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010787}
Mike Stump11289f42009-09-09 15:08:12 +000010788
Douglas Gregord6ff3322009-08-04 16:50:30 +000010789template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010790QualType
10791TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010792 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010793 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010794 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010795}
Mike Stump11289f42009-09-09 15:08:12 +000010796
Douglas Gregord6ff3322009-08-04 16:50:30 +000010797template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010798QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10799 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010800 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010801 const FunctionProtoType::ExtProtoInfo &EPI) {
10802 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010803 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010804 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010805 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010806}
Mike Stump11289f42009-09-09 15:08:12 +000010807
Douglas Gregord6ff3322009-08-04 16:50:30 +000010808template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010809QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10810 return SemaRef.Context.getFunctionNoProtoType(T);
10811}
10812
10813template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010814QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10815 assert(D && "no decl found");
10816 if (D->isInvalidDecl()) return QualType();
10817
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010818 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010819 TypeDecl *Ty;
10820 if (isa<UsingDecl>(D)) {
10821 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010822 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010823 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10824
10825 // A valid resolved using typename decl points to exactly one type decl.
10826 assert(++Using->shadow_begin() == Using->shadow_end());
10827 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010828
John McCallb96ec562009-12-04 22:46:56 +000010829 } else {
10830 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10831 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10832 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10833 }
10834
10835 return SemaRef.Context.getTypeDeclType(Ty);
10836}
10837
10838template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010839QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10840 SourceLocation Loc) {
10841 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010842}
10843
10844template<typename Derived>
10845QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10846 return SemaRef.Context.getTypeOfType(Underlying);
10847}
10848
10849template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010850QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10851 SourceLocation Loc) {
10852 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010853}
10854
10855template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010856QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10857 UnaryTransformType::UTTKind UKind,
10858 SourceLocation Loc) {
10859 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10860}
10861
10862template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010863QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010864 TemplateName Template,
10865 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010866 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010867 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010868}
Mike Stump11289f42009-09-09 15:08:12 +000010869
Douglas Gregor1135c352009-08-06 05:28:30 +000010870template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010871QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10872 SourceLocation KWLoc) {
10873 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10874}
10875
10876template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010877TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010878TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010879 bool TemplateKW,
10880 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010881 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010882 Template);
10883}
10884
10885template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010886TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010887TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10888 const IdentifierInfo &Name,
10889 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010890 QualType ObjectType,
10891 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010892 UnqualifiedId TemplateName;
10893 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010894 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010895 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010896 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010897 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010898 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010899 /*EnteringContext=*/false,
10900 Template);
John McCall31f82722010-11-12 08:19:04 +000010901 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010902}
Mike Stump11289f42009-09-09 15:08:12 +000010903
Douglas Gregora16548e2009-08-11 05:31:07 +000010904template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010905TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010906TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010907 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010908 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010909 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010910 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010911 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010912 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010913 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010914 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010915 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010916 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010917 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010918 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010919 /*EnteringContext=*/false,
10920 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010921 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010922}
Chad Rosier1dcde962012-08-08 18:46:20 +000010923
Douglas Gregor71395fa2009-11-04 00:56:37 +000010924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010925ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010926TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10927 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010928 Expr *OrigCallee,
10929 Expr *First,
10930 Expr *Second) {
10931 Expr *Callee = OrigCallee->IgnoreParenCasts();
10932 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010933
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010934 if (First->getObjectKind() == OK_ObjCProperty) {
10935 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10936 if (BinaryOperator::isAssignmentOp(Opc))
10937 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10938 First, Second);
10939 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10940 if (Result.isInvalid())
10941 return ExprError();
10942 First = Result.get();
10943 }
10944
10945 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10946 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10947 if (Result.isInvalid())
10948 return ExprError();
10949 Second = Result.get();
10950 }
10951
Douglas Gregora16548e2009-08-11 05:31:07 +000010952 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010953 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010954 if (!First->getType()->isOverloadableType() &&
10955 !Second->getType()->isOverloadableType())
10956 return getSema().CreateBuiltinArraySubscriptExpr(First,
10957 Callee->getLocStart(),
10958 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010959 } else if (Op == OO_Arrow) {
10960 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010961 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10962 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010963 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010964 // The argument is not of overloadable type, so try to create a
10965 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000010966 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000010967 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000010968
John McCallb268a282010-08-23 23:25:46 +000010969 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000010970 }
10971 } else {
John McCallb268a282010-08-23 23:25:46 +000010972 if (!First->getType()->isOverloadableType() &&
10973 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010974 // Neither of the arguments is an overloadable type, so try to
10975 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000010976 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000010977 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000010978 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000010979 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010980 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010981
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010982 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000010983 }
10984 }
Mike Stump11289f42009-09-09 15:08:12 +000010985
10986 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000010987 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000010988 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000010989
John McCallb268a282010-08-23 23:25:46 +000010990 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000010991 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000010992 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000010993 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000010994 // If we've resolved this to a particular non-member function, just call
10995 // that function. If we resolved it to a member function,
10996 // CreateOverloaded* will find that function for us.
10997 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
10998 if (!isa<CXXMethodDecl>(ND))
10999 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011000 }
Mike Stump11289f42009-09-09 15:08:12 +000011001
Douglas Gregora16548e2009-08-11 05:31:07 +000011002 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011003 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011004 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011005
Douglas Gregora16548e2009-08-11 05:31:07 +000011006 // Create the overloaded operator invocation for unary operators.
11007 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011008 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011009 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011010 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011011 }
Mike Stump11289f42009-09-09 15:08:12 +000011012
Douglas Gregore9d62932011-07-15 16:25:15 +000011013 if (Op == OO_Subscript) {
11014 SourceLocation LBrace;
11015 SourceLocation RBrace;
11016
11017 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011018 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011019 LBrace = SourceLocation::getFromRawEncoding(
11020 NameLoc.CXXOperatorName.BeginOpNameLoc);
11021 RBrace = SourceLocation::getFromRawEncoding(
11022 NameLoc.CXXOperatorName.EndOpNameLoc);
11023 } else {
11024 LBrace = Callee->getLocStart();
11025 RBrace = OpLoc;
11026 }
11027
11028 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11029 First, Second);
11030 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011031
Douglas Gregora16548e2009-08-11 05:31:07 +000011032 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011033 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011034 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011035 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11036 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011038
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011039 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011040}
Mike Stump11289f42009-09-09 15:08:12 +000011041
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011042template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011043ExprResult
John McCallb268a282010-08-23 23:25:46 +000011044TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011045 SourceLocation OperatorLoc,
11046 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011047 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011048 TypeSourceInfo *ScopeType,
11049 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011050 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011051 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011052 QualType BaseType = Base->getType();
11053 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011054 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011055 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011056 !BaseType->getAs<PointerType>()->getPointeeType()
11057 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011058 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011059 return SemaRef.BuildPseudoDestructorExpr(
11060 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11061 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011062 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011063
Douglas Gregor678f90d2010-02-25 01:56:36 +000011064 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011065 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11066 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11067 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11068 NameInfo.setNamedTypeInfo(DestroyedType);
11069
Richard Smith8e4a3862012-05-15 06:15:11 +000011070 // The scope type is now known to be a valid nested name specifier
11071 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011072 if (ScopeType) {
11073 if (!ScopeType->getType()->getAs<TagType>()) {
11074 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11075 diag::err_expected_class_or_namespace)
11076 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11077 return ExprError();
11078 }
11079 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11080 CCLoc);
11081 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011082
Abramo Bagnara7945c982012-01-27 09:46:47 +000011083 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011084 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011085 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011086 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011087 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011088 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011089 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011090}
11091
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011092template<typename Derived>
11093StmtResult
11094TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011095 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011096 CapturedDecl *CD = S->getCapturedDecl();
11097 unsigned NumParams = CD->getNumParams();
11098 unsigned ContextParamPos = CD->getContextParamPosition();
11099 SmallVector<Sema::CapturedParamNameType, 4> Params;
11100 for (unsigned I = 0; I < NumParams; ++I) {
11101 if (I != ContextParamPos) {
11102 Params.push_back(
11103 std::make_pair(
11104 CD->getParam(I)->getName(),
11105 getDerived().TransformType(CD->getParam(I)->getType())));
11106 } else {
11107 Params.push_back(std::make_pair(StringRef(), QualType()));
11108 }
11109 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011110 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011111 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011112 StmtResult Body;
11113 {
11114 Sema::CompoundScopeRAII CompoundScope(getSema());
11115 Body = getDerived().TransformStmt(S->getCapturedStmt());
11116 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011117
11118 if (Body.isInvalid()) {
11119 getSema().ActOnCapturedRegionError();
11120 return StmtError();
11121 }
11122
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011123 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011124}
11125
Douglas Gregord6ff3322009-08-04 16:50:30 +000011126} // end namespace clang
11127
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011128#endif