blob: d285db597c40f49ffa87f2ec4a1ba28090c82a24 [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 Bataev10e775f2015-07-30 11:36:16 +00001450 /// \brief Build a new OpenMP 'ordered' clause.
1451 ///
1452 /// By default, performs semantic analysis to build the new OpenMP clause.
1453 /// Subclasses may override this routine to provide different behavior.
1454 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1455 SourceLocation EndLoc,
1456 SourceLocation LParenLoc, Expr *Num) {
1457 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1458 }
1459
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001460 /// \brief Build a new OpenMP 'private' clause.
1461 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001462 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001463 /// Subclasses may override this routine to provide different behavior.
1464 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1465 SourceLocation StartLoc,
1466 SourceLocation LParenLoc,
1467 SourceLocation EndLoc) {
1468 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1469 EndLoc);
1470 }
1471
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001472 /// \brief Build a new OpenMP 'firstprivate' clause.
1473 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001474 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001475 /// Subclasses may override this routine to provide different behavior.
1476 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1477 SourceLocation StartLoc,
1478 SourceLocation LParenLoc,
1479 SourceLocation EndLoc) {
1480 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1481 EndLoc);
1482 }
1483
Alexander Musman1bb328c2014-06-04 13:06:39 +00001484 /// \brief Build a new OpenMP 'lastprivate' clause.
1485 ///
1486 /// By default, performs semantic analysis to build the new OpenMP clause.
1487 /// Subclasses may override this routine to provide different behavior.
1488 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1489 SourceLocation StartLoc,
1490 SourceLocation LParenLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1493 EndLoc);
1494 }
1495
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001496 /// \brief Build a new OpenMP 'shared' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001499 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001500 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataevc5e02582014-06-16 07:08:35 +00001508 /// \brief Build a new OpenMP 'reduction' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new statement.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation ColonLoc,
1516 SourceLocation EndLoc,
1517 CXXScopeSpec &ReductionIdScopeSpec,
1518 const DeclarationNameInfo &ReductionId) {
1519 return getSema().ActOnOpenMPReductionClause(
1520 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1521 ReductionId);
1522 }
1523
Alexander Musman8dba6642014-04-22 13:09:42 +00001524 /// \brief Build a new OpenMP 'linear' clause.
1525 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001526 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001527 /// Subclasses may override this routine to provide different behavior.
1528 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1529 SourceLocation StartLoc,
1530 SourceLocation LParenLoc,
1531 SourceLocation ColonLoc,
1532 SourceLocation EndLoc) {
1533 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1534 ColonLoc, EndLoc);
1535 }
1536
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001537 /// \brief Build a new OpenMP 'aligned' clause.
1538 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001539 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001540 /// Subclasses may override this routine to provide different behavior.
1541 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1542 SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation ColonLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1547 LParenLoc, ColonLoc, EndLoc);
1548 }
1549
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001550 /// \brief Build a new OpenMP 'copyin' clause.
1551 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001552 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001553 /// Subclasses may override this routine to provide different behavior.
1554 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1555 SourceLocation StartLoc,
1556 SourceLocation LParenLoc,
1557 SourceLocation EndLoc) {
1558 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1559 EndLoc);
1560 }
1561
Alexey Bataevbae9a792014-06-27 10:37:06 +00001562 /// \brief Build a new OpenMP 'copyprivate' clause.
1563 ///
1564 /// By default, performs semantic analysis to build the new OpenMP clause.
1565 /// Subclasses may override this routine to provide different behavior.
1566 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1567 SourceLocation StartLoc,
1568 SourceLocation LParenLoc,
1569 SourceLocation EndLoc) {
1570 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1571 EndLoc);
1572 }
1573
Alexey Bataev6125da92014-07-21 11:26:11 +00001574 /// \brief Build a new OpenMP 'flush' pseudo clause.
1575 ///
1576 /// By default, performs semantic analysis to build the new OpenMP clause.
1577 /// Subclasses may override this routine to provide different behavior.
1578 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1579 SourceLocation StartLoc,
1580 SourceLocation LParenLoc,
1581 SourceLocation EndLoc) {
1582 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1583 EndLoc);
1584 }
1585
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001586 /// \brief Build a new OpenMP 'depend' pseudo clause.
1587 ///
1588 /// By default, performs semantic analysis to build the new OpenMP clause.
1589 /// Subclasses may override this routine to provide different behavior.
1590 OMPClause *
1591 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1592 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1593 SourceLocation StartLoc, SourceLocation LParenLoc,
1594 SourceLocation EndLoc) {
1595 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1596 StartLoc, LParenLoc, EndLoc);
1597 }
1598
Michael Wonge710d542015-08-07 16:16:36 +00001599 /// \brief Build a new OpenMP 'device' clause.
1600 ///
1601 /// By default, performs semantic analysis to build the new statement.
1602 /// Subclasses may override this routine to provide different behavior.
1603 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1604 SourceLocation LParenLoc,
1605 SourceLocation EndLoc) {
1606 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1607 EndLoc);
1608 }
1609
James Dennett2a4d13c2012-06-15 07:13:21 +00001610 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001611 ///
1612 /// By default, performs semantic analysis to build the new statement.
1613 /// Subclasses may override this routine to provide different behavior.
1614 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1615 Expr *object) {
1616 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1617 }
1618
James Dennett2a4d13c2012-06-15 07:13:21 +00001619 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001620 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001621 /// By default, performs semantic analysis to build the new statement.
1622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001623 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001624 Expr *Object, Stmt *Body) {
1625 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001626 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001627
James Dennett2a4d13c2012-06-15 07:13:21 +00001628 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001629 ///
1630 /// By default, performs semantic analysis to build the new statement.
1631 /// Subclasses may override this routine to provide different behavior.
1632 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1633 Stmt *Body) {
1634 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1635 }
John McCall53848232011-07-27 01:07:15 +00001636
Douglas Gregorf68a5082010-04-22 23:10:45 +00001637 /// \brief Build a new Objective-C fast enumeration statement.
1638 ///
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001642 Stmt *Element,
1643 Expr *Collection,
1644 SourceLocation RParenLoc,
1645 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001646 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001647 Element,
John McCallb268a282010-08-23 23:25:46 +00001648 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001649 RParenLoc);
1650 if (ForEachStmt.isInvalid())
1651 return StmtError();
1652
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001653 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001654 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001655
Douglas Gregorebe10102009-08-20 07:17:43 +00001656 /// \brief Build a new C++ exception declaration.
1657 ///
1658 /// By default, performs semantic analysis to build the new decaration.
1659 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001660 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001661 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001662 SourceLocation StartLoc,
1663 SourceLocation IdLoc,
1664 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001665 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001666 StartLoc, IdLoc, Id);
1667 if (Var)
1668 getSema().CurContext->addDecl(Var);
1669 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001670 }
1671
1672 /// \brief Build a new C++ catch statement.
1673 ///
1674 /// By default, performs semantic analysis to build the new statement.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001677 VarDecl *ExceptionDecl,
1678 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001679 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1680 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregorebe10102009-08-20 07:17:43 +00001683 /// \brief Build a new C++ try statement.
1684 ///
1685 /// By default, performs semantic analysis to build the new statement.
1686 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001687 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1688 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001689 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001690 }
Mike Stump11289f42009-09-09 15:08:12 +00001691
Richard Smith02e85f32011-04-14 22:09:26 +00001692 /// \brief Build a new C++0x range-based for statement.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1697 SourceLocation ColonLoc,
1698 Stmt *Range, Stmt *BeginEnd,
1699 Expr *Cond, Expr *Inc,
1700 Stmt *LoopVar,
1701 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001702 // If we've just learned that the range is actually an Objective-C
1703 // collection, treat this as an Objective-C fast enumeration loop.
1704 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1705 if (RangeStmt->isSingleDecl()) {
1706 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001707 if (RangeVar->isInvalidDecl())
1708 return StmtError();
1709
Douglas Gregorf7106af2013-04-08 18:40:13 +00001710 Expr *RangeExpr = RangeVar->getInit();
1711 if (!RangeExpr->isTypeDependent() &&
1712 RangeExpr->getType()->isObjCObjectPointerType())
1713 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1714 RParenLoc);
1715 }
1716 }
1717 }
1718
Richard Smith02e85f32011-04-14 22:09:26 +00001719 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001720 Cond, Inc, LoopVar, RParenLoc,
1721 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001722 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001723
1724 /// \brief Build a new C++0x range-based for statement.
1725 ///
1726 /// By default, performs semantic analysis to build the new statement.
1727 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001728 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001729 bool IsIfExists,
1730 NestedNameSpecifierLoc QualifierLoc,
1731 DeclarationNameInfo NameInfo,
1732 Stmt *Nested) {
1733 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1734 QualifierLoc, NameInfo, Nested);
1735 }
1736
Richard Smith02e85f32011-04-14 22:09:26 +00001737 /// \brief Attach body to a C++0x range-based for statement.
1738 ///
1739 /// By default, performs semantic analysis to finish the new statement.
1740 /// Subclasses may override this routine to provide different behavior.
1741 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1742 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001744
David Majnemerfad8f482013-10-15 09:33:02 +00001745 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001746 Stmt *TryBlock, Stmt *Handler) {
1747 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001748 }
1749
David Majnemerfad8f482013-10-15 09:33:02 +00001750 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001751 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001752 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001753 }
1754
David Majnemerfad8f482013-10-15 09:33:02 +00001755 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001756 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001757 }
1758
Alexey Bataevec474782014-10-09 08:45:04 +00001759 /// \brief Build a new predefined expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
1763 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1764 PredefinedExpr::IdentType IT) {
1765 return getSema().BuildPredefinedExpr(Loc, IT);
1766 }
1767
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// \brief Build a new expression that references a declaration.
1769 ///
1770 /// By default, performs semantic analysis to build the new expression.
1771 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001773 LookupResult &R,
1774 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001775 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1776 }
1777
1778
1779 /// \brief Build a new expression that references a declaration.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001783 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001784 ValueDecl *VD,
1785 const DeclarationNameInfo &NameInfo,
1786 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001787 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001788 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001789
1790 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001791
1792 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
Mike Stump11289f42009-09-09 15:08:12 +00001794
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001796 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001799 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001801 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 }
1803
Douglas Gregorad8a3362009-09-04 17:36:40 +00001804 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001805 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001809 SourceLocation OperatorLoc,
1810 bool isArrow,
1811 CXXScopeSpec &SS,
1812 TypeSourceInfo *ScopeType,
1813 SourceLocation CCLoc,
1814 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001815 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001816
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001818 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 /// By default, performs semantic analysis to build the new expression.
1820 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001821 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001822 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001823 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001824 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 }
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregor882211c2010-04-28 22:16:22 +00001827 /// \brief Build a new builtin offsetof expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001832 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001833 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001834 unsigned NumComponents,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1837 NumComponents, RParenLoc);
1838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001839
1840 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001841 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001842 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001845 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1846 SourceLocation OpLoc,
1847 UnaryExprOrTypeTrait ExprKind,
1848 SourceRange R) {
1849 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
1851
Peter Collingbournee190dee2011-03-11 19:24:49 +00001852 /// \brief Build a new sizeof, alignof or vec step expression with an
1853 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001854 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001857 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1858 UnaryExprOrTypeTrait ExprKind,
1859 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001860 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001861 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001864
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001865 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001866 }
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregora16548e2009-08-11 05:31:07 +00001868 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001869 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001872 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001874 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001876 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001877 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 RBracketLoc);
1879 }
1880
1881 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 /// By default, performs semantic analysis to build the new expression.
1884 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001885 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001887 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001888 Expr *ExecConfig = nullptr) {
1889 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001890 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 }
1892
1893 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001894 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001897 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001898 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001899 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001900 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001901 const DeclarationNameInfo &MemberNameInfo,
1902 ValueDecl *Member,
1903 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001904 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001905 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001906 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1907 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001908 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001909 // We have a reference to an unnamed field. This is always the
1910 // base of an anonymous struct/union member access, i.e. the
1911 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001912 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001913 assert(Member->getType()->isRecordType() &&
1914 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001915
Richard Smithcab9a7d2011-10-26 19:06:56 +00001916 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001917 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001918 QualifierLoc.getNestedNameSpecifier(),
1919 FoundDecl, Member);
1920 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001921 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001922 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001923 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001924 MemberExpr *ME = new (getSema().Context)
1925 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1926 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001927 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001928 }
Mike Stump11289f42009-09-09 15:08:12 +00001929
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001930 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001931 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001932
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001933 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001934 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001935
John McCall16df1e52010-03-30 21:47:33 +00001936 // FIXME: this involves duplicating earlier analysis in a lot of
1937 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001938 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001939 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001940 R.resolveKind();
1941
John McCallb268a282010-08-23 23:25:46 +00001942 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001943 SS, TemplateKWLoc,
1944 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001945 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001949 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001952 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001953 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001954 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001955 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 }
1957
1958 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001959 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001963 SourceLocation QuestionLoc,
1964 Expr *LHS,
1965 SourceLocation ColonLoc,
1966 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001967 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1968 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 }
1970
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001972 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001975 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001976 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001977 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001978 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001979 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001980 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001984 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001988 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001990 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001991 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001992 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 }
Mike Stump11289f42009-09-09 15:08:12 +00001994
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001996 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// By default, performs semantic analysis to build the new expression.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 SourceLocation OpLoc,
2001 SourceLocation AccessorLoc,
2002 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002003
John McCall10eae182009-11-30 22:42:35 +00002004 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002005 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002006 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002007 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002008 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002009 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002010 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002011 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002015 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002018 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002019 MultiExprArg Inits,
2020 SourceLocation RBraceLoc,
2021 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002023 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002024 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002025 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002026
Douglas Gregord3d93062009-11-09 17:16:50 +00002027 // Patch in the result type we were given, which may have been computed
2028 // when the initial InitListExpr was built.
2029 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2030 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002031 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002035 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 MultiExprArg ArrayExprs,
2040 SourceLocation EqualOrColonLoc,
2041 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002042 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002043 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002045 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002048
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002049 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
Mike Stump11289f42009-09-09 15:08:12 +00002051
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002053 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// By default, builds the implicit value initialization without performing
2055 /// any semantic analysis. Subclasses may override this routine to provide
2056 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002058 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 }
Mike Stump11289f42009-09-09 15:08:12 +00002060
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002062 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 /// By default, performs semantic analysis to build the new expression.
2064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002065 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002066 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002067 SourceLocation RParenLoc) {
2068 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002070 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 }
2072
2073 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002074 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 /// By default, performs semantic analysis to build the new expression.
2076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002078 MultiExprArg SubExprs,
2079 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002080 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 }
Mike Stump11289f42009-09-09 15:08:12 +00002082
Douglas Gregora16548e2009-08-11 05:31:07 +00002083 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002084 ///
2085 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// rather than attempting to map the label statement itself.
2087 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002088 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002089 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002090 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 }
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002094 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002098 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002100 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 /// \brief Build a new __builtin_choose_expr expression.
2104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002108 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 SourceLocation RParenLoc) {
2110 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002111 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 RParenLoc);
2113 }
Mike Stump11289f42009-09-09 15:08:12 +00002114
Peter Collingbourne91147592011-04-15 00:35:48 +00002115 /// \brief Build a new generic selection expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
2119 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2120 SourceLocation DefaultLoc,
2121 SourceLocation RParenLoc,
2122 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002123 ArrayRef<TypeSourceInfo *> Types,
2124 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002125 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002126 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002127 }
2128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new overloaded operator call expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// The semantic analysis provides the behavior of template instantiation,
2133 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002134 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 /// argument-dependent lookup, etc. Subclasses may override this routine to
2136 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002139 Expr *Callee,
2140 Expr *First,
2141 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002142
2143 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 /// reinterpret_cast.
2145 ///
2146 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002147 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002149 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 Stmt::StmtClass Class,
2151 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002152 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 SourceLocation RAngleLoc,
2154 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002155 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 SourceLocation RParenLoc) {
2157 switch (Class) {
2158 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002159 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002160 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002161 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002162
2163 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002164 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002165 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002166 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002169 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002170 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002171 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002175 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002176 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002177 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002180 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 }
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// \brief Build a new C++ static_cast expression.
2185 ///
2186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002190 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation RAngleLoc,
2192 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002193 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002195 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002196 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002197 SourceRange(LAngleLoc, RAngleLoc),
2198 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 }
2200
2201 /// \brief Build a new C++ dynamic_cast expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002207 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 SourceLocation RAngleLoc,
2209 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002210 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002212 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002213 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002214 SourceRange(LAngleLoc, RAngleLoc),
2215 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 }
2217
2218 /// \brief Build a new C++ reinterpret_cast expression.
2219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002222 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002224 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 SourceLocation RAngleLoc,
2226 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002227 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002229 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002230 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002231 SourceRange(LAngleLoc, RAngleLoc),
2232 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
2235 /// \brief Build a new C++ const_cast expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002241 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 SourceLocation RAngleLoc,
2243 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002244 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002246 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002247 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002248 SourceRange(LAngleLoc, RAngleLoc),
2249 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
Mike Stump11289f42009-09-09 15:08:12 +00002251
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// \brief Build a new C++ functional-style cast expression.
2253 ///
2254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002256 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2257 SourceLocation LParenLoc,
2258 Expr *Sub,
2259 SourceLocation RParenLoc) {
2260 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002261 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 RParenLoc);
2263 }
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 /// \brief Build a new C++ typeid(type) expression.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002269 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002270 SourceLocation TypeidLoc,
2271 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002273 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002274 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 }
Mike Stump11289f42009-09-09 15:08:12 +00002276
Francois Pichet9f4f2072010-09-08 12:20:18 +00002277
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// \brief Build a new C++ typeid(expr) expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002283 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002284 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002286 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002287 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002288 }
2289
Francois Pichet9f4f2072010-09-08 12:20:18 +00002290 /// \brief Build a new C++ __uuidof(type) expression.
2291 ///
2292 /// By default, performs semantic analysis to build the new expression.
2293 /// Subclasses may override this routine to provide different behavior.
2294 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2295 SourceLocation TypeidLoc,
2296 TypeSourceInfo *Operand,
2297 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002298 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002299 RParenLoc);
2300 }
2301
2302 /// \brief Build a new C++ __uuidof(expr) expression.
2303 ///
2304 /// By default, performs semantic analysis to build the new expression.
2305 /// Subclasses may override this routine to provide different behavior.
2306 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2307 SourceLocation TypeidLoc,
2308 Expr *Operand,
2309 SourceLocation RParenLoc) {
2310 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2311 RParenLoc);
2312 }
2313
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 /// \brief Build a new C++ "this" expression.
2315 ///
2316 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002317 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002319 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002320 QualType ThisType,
2321 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002322 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002323 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 }
2325
2326 /// \brief Build a new C++ throw expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002330 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2331 bool IsThrownVariableInScope) {
2332 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 }
2334
2335 /// \brief Build a new C++ default-argument expression.
2336 ///
2337 /// By default, builds a new default-argument expression, which does not
2338 /// require any semantic analysis. Subclasses may override this routine to
2339 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002340 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002341 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002342 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 }
2344
Richard Smith852c9db2013-04-20 22:23:05 +00002345 /// \brief Build a new C++11 default-initialization expression.
2346 ///
2347 /// By default, builds a new default field initialization expression, which
2348 /// does not require any semantic analysis. Subclasses may override this
2349 /// routine to provide different behavior.
2350 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2351 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002352 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002353 }
2354
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 /// \brief Build a new C++ zero-initialization expression.
2356 ///
2357 /// By default, performs semantic analysis to build the new expression.
2358 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002359 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2360 SourceLocation LParenLoc,
2361 SourceLocation RParenLoc) {
2362 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002363 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 }
Mike Stump11289f42009-09-09 15:08:12 +00002365
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// \brief Build a new C++ "new" expression.
2367 ///
2368 /// By default, performs semantic analysis to build the new expression.
2369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002370 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002371 bool UseGlobal,
2372 SourceLocation PlacementLParen,
2373 MultiExprArg PlacementArgs,
2374 SourceLocation PlacementRParen,
2375 SourceRange TypeIdParens,
2376 QualType AllocatedType,
2377 TypeSourceInfo *AllocatedTypeInfo,
2378 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002379 SourceRange DirectInitRange,
2380 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002381 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002383 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002385 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002386 AllocatedType,
2387 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002388 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002389 DirectInitRange,
2390 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 }
Mike Stump11289f42009-09-09 15:08:12 +00002392
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 /// \brief Build a new C++ "delete" expression.
2394 ///
2395 /// By default, performs semantic analysis to build the new expression.
2396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 bool IsGlobalDelete,
2399 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002400 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002402 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 }
Mike Stump11289f42009-09-09 15:08:12 +00002404
Douglas Gregor29c42f22012-02-24 07:38:34 +00002405 /// \brief Build a new type trait expression.
2406 ///
2407 /// By default, performs semantic analysis to build the new expression.
2408 /// Subclasses may override this routine to provide different behavior.
2409 ExprResult RebuildTypeTrait(TypeTrait Trait,
2410 SourceLocation StartLoc,
2411 ArrayRef<TypeSourceInfo *> Args,
2412 SourceLocation RParenLoc) {
2413 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2414 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002415
John Wiegley6242b6a2011-04-28 00:16:57 +00002416 /// \brief Build a new array type trait expression.
2417 ///
2418 /// By default, performs semantic analysis to build the new expression.
2419 /// Subclasses may override this routine to provide different behavior.
2420 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2421 SourceLocation StartLoc,
2422 TypeSourceInfo *TSInfo,
2423 Expr *DimExpr,
2424 SourceLocation RParenLoc) {
2425 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2426 }
2427
John Wiegleyf9f65842011-04-25 06:54:41 +00002428 /// \brief Build a new expression trait expression.
2429 ///
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
2432 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2433 SourceLocation StartLoc,
2434 Expr *Queried,
2435 SourceLocation RParenLoc) {
2436 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2437 }
2438
Mike Stump11289f42009-09-09 15:08:12 +00002439 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002444 ExprResult RebuildDependentScopeDeclRefExpr(
2445 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002446 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002447 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002448 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002449 bool IsAddressOfOperand,
2450 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002452 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002453
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002454 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002455 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2456 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002457
Reid Kleckner32506ed2014-06-12 23:03:48 +00002458 return getSema().BuildQualifiedDeclarationNameExpr(
2459 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
2462 /// \brief Build a new template-id expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002466 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002467 SourceLocation TemplateKWLoc,
2468 LookupResult &R,
2469 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002470 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002471 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2472 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 }
2474
2475 /// \brief Build a new object-construction expression.
2476 ///
2477 /// By default, performs semantic analysis to build the new expression.
2478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002479 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002480 SourceLocation Loc,
2481 CXXConstructorDecl *Constructor,
2482 bool IsElidable,
2483 MultiExprArg Args,
2484 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002485 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002486 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002487 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002488 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002489 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002490 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002491 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002492 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002493 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002494
Douglas Gregordb121ba2009-12-14 16:27:04 +00002495 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002496 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002497 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002498 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002499 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002500 RequiresZeroInit, ConstructKind,
2501 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002502 }
2503
2504 /// \brief Build a new object-construction expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002508 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2509 SourceLocation LParenLoc,
2510 MultiExprArg Args,
2511 SourceLocation RParenLoc) {
2512 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002514 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 RParenLoc);
2516 }
2517
2518 /// \brief Build a new object-construction expression.
2519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002522 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2523 SourceLocation LParenLoc,
2524 MultiExprArg Args,
2525 SourceLocation RParenLoc) {
2526 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002527 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002528 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 RParenLoc);
2530 }
Mike Stump11289f42009-09-09 15:08:12 +00002531
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 /// \brief Build a new member reference expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002536 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002537 QualType BaseType,
2538 bool IsArrow,
2539 SourceLocation OperatorLoc,
2540 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002541 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002542 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002543 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002544 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002546 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002547
John McCallb268a282010-08-23 23:25:46 +00002548 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002549 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002550 SS, TemplateKWLoc,
2551 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002552 MemberNameInfo,
2553 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 }
2555
John McCall10eae182009-11-30 22:42:35 +00002556 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002557 ///
2558 /// By default, performs semantic analysis to build the new expression.
2559 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002560 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2561 SourceLocation OperatorLoc,
2562 bool IsArrow,
2563 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002564 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002565 NamedDecl *FirstQualifierInScope,
2566 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002567 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002568 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002569 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002570
John McCallb268a282010-08-23 23:25:46 +00002571 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002572 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002573 SS, TemplateKWLoc,
2574 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002575 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002576 }
Mike Stump11289f42009-09-09 15:08:12 +00002577
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002578 /// \brief Build a new noexcept expression.
2579 ///
2580 /// By default, performs semantic analysis to build the new expression.
2581 /// Subclasses may override this routine to provide different behavior.
2582 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2583 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2584 }
2585
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002586 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002587 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2588 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002589 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002590 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002591 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002592 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2593 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002594 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002595
2596 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2597 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002598 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002599 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002600
Patrick Beard0caa3942012-04-19 00:25:12 +00002601 /// \brief Build a new Objective-C boxed expression.
2602 ///
2603 /// By default, performs semantic analysis to build the new expression.
2604 /// Subclasses may override this routine to provide different behavior.
2605 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2606 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002608
Ted Kremeneke65b0862012-03-06 20:05:56 +00002609 /// \brief Build a new Objective-C array literal.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
2613 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2614 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002615 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002616 MultiExprArg(Elements, NumElements));
2617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002618
2619 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002620 Expr *Base, Expr *Key,
2621 ObjCMethodDecl *getterMethod,
2622 ObjCMethodDecl *setterMethod) {
2623 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2624 getterMethod, setterMethod);
2625 }
2626
2627 /// \brief Build a new Objective-C dictionary literal.
2628 ///
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2632 ObjCDictionaryElement *Elements,
2633 unsigned NumElements) {
2634 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002636
James Dennett2a4d13c2012-06-15 07:13:21 +00002637 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002638 ///
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002641 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002642 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002643 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002644 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002645 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002646
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002647 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002648 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002649 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002650 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002651 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002652 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002653 MultiExprArg Args,
2654 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002655 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2656 ReceiverTypeInfo->getType(),
2657 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002658 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002659 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002660 }
2661
2662 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002663 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002664 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002665 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002666 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002667 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002668 MultiExprArg Args,
2669 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002670 return SemaRef.BuildInstanceMessage(Receiver,
2671 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002672 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002673 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002674 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002675 }
2676
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002677 /// \brief Build a new Objective-C instance/class message to 'super'.
2678 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2679 Selector Sel,
2680 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002681 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002682 ObjCMethodDecl *Method,
2683 SourceLocation LBracLoc,
2684 MultiExprArg Args,
2685 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002686 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002687 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002688 SuperLoc,
2689 Sel, Method, LBracLoc, SelectorLocs,
2690 RBracLoc, Args)
2691 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002692 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002693 SuperLoc,
2694 Sel, Method, LBracLoc, SelectorLocs,
2695 RBracLoc, Args);
2696
2697
2698 }
2699
Douglas Gregord51d90d2010-04-26 20:11:03 +00002700 /// \brief Build a new Objective-C ivar reference expression.
2701 ///
2702 /// By default, performs semantic analysis to build the new expression.
2703 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002704 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002705 SourceLocation IvarLoc,
2706 bool IsArrow, bool IsFreeIvar) {
2707 // FIXME: We lose track of the IsFreeIvar bit.
2708 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002709 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2710 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002711 /*FIXME:*/IvarLoc, IsArrow,
2712 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002713 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002714 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002715 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002716 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002717
2718 /// \brief Build a new Objective-C property reference expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002722 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002723 ObjCPropertyDecl *Property,
2724 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002725 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002726 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2727 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2728 /*FIXME:*/PropertyLoc,
2729 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002730 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002731 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002732 NameInfo,
2733 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002735
John McCallb7bd14f2010-12-02 01:19:52 +00002736 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002737 ///
2738 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002739 /// Subclasses may override this routine to provide different behavior.
2740 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2741 ObjCMethodDecl *Getter,
2742 ObjCMethodDecl *Setter,
2743 SourceLocation PropertyLoc) {
2744 // Since these expressions can only be value-dependent, we do not
2745 // need to perform semantic analysis again.
2746 return Owned(
2747 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2748 VK_LValue, OK_ObjCProperty,
2749 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002750 }
2751
Douglas Gregord51d90d2010-04-26 20:11:03 +00002752 /// \brief Build a new Objective-C "isa" expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002756 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002757 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002758 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002759 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2760 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002761 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002762 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002763 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002764 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002765 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002767
Douglas Gregora16548e2009-08-11 05:31:07 +00002768 /// \brief Build a new shuffle vector expression.
2769 ///
2770 /// By default, performs semantic analysis to build the new expression.
2771 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002772 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002773 MultiExprArg SubExprs,
2774 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002776 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2778 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2779 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002780 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002781
Douglas Gregora16548e2009-08-11 05:31:07 +00002782 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002783 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002784 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2785 SemaRef.Context.BuiltinFnTy,
2786 VK_RValue, BuiltinLoc);
2787 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2788 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002789 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002790
2791 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002792 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002793 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002794 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002795
Douglas Gregora16548e2009-08-11 05:31:07 +00002796 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002797 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002798 }
John McCall31f82722010-11-12 08:19:04 +00002799
Hal Finkelc4d7c822013-09-18 03:29:45 +00002800 /// \brief Build a new convert vector expression.
2801 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2802 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2803 SourceLocation RParenLoc) {
2804 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2805 BuiltinLoc, RParenLoc);
2806 }
2807
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002808 /// \brief Build a new template argument pack expansion.
2809 ///
2810 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002811 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002812 /// different behavior.
2813 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002814 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002815 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002816 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002817 case TemplateArgument::Expression: {
2818 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002819 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2820 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002821 if (Result.isInvalid())
2822 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002823
Douglas Gregor98318c22011-01-03 21:37:45 +00002824 return TemplateArgumentLoc(Result.get(), Result.get());
2825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002826
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002827 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002828 return TemplateArgumentLoc(TemplateArgument(
2829 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002830 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002831 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002832 Pattern.getTemplateNameLoc(),
2833 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002834
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002835 case TemplateArgument::Null:
2836 case TemplateArgument::Integral:
2837 case TemplateArgument::Declaration:
2838 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002839 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002840 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002841 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002842
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002843 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002844 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002845 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002846 EllipsisLoc,
2847 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002848 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2849 Expansion);
2850 break;
2851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002853 return TemplateArgumentLoc();
2854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002855
Douglas Gregor968f23a2011-01-03 19:31:53 +00002856 /// \brief Build a new expression pack expansion.
2857 ///
2858 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002859 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002860 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002861 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002862 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002863 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002864 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002865
Richard Smith0f0af192014-11-08 05:07:16 +00002866 /// \brief Build a new C++1z fold-expression.
2867 ///
2868 /// By default, performs semantic analysis in order to build a new fold
2869 /// expression.
2870 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2871 BinaryOperatorKind Operator,
2872 SourceLocation EllipsisLoc, Expr *RHS,
2873 SourceLocation RParenLoc) {
2874 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2875 RHS, RParenLoc);
2876 }
2877
2878 /// \brief Build an empty C++1z fold-expression with the given operator.
2879 ///
2880 /// By default, produces the fallback value for the fold-expression, or
2881 /// produce an error if there is no fallback value.
2882 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2883 BinaryOperatorKind Operator) {
2884 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2885 }
2886
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002887 /// \brief Build a new atomic operation expression.
2888 ///
2889 /// By default, performs semantic analysis to build the new expression.
2890 /// Subclasses may override this routine to provide different behavior.
2891 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2892 MultiExprArg SubExprs,
2893 QualType RetTy,
2894 AtomicExpr::AtomicOp Op,
2895 SourceLocation RParenLoc) {
2896 // Just create the expression; there is not any interesting semantic
2897 // analysis here because we can't actually build an AtomicExpr until
2898 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002899 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002900 RParenLoc);
2901 }
2902
John McCall31f82722010-11-12 08:19:04 +00002903private:
Douglas Gregor14454802011-02-25 02:25:35 +00002904 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2905 QualType ObjectType,
2906 NamedDecl *FirstQualifierInScope,
2907 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002908
2909 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2910 QualType ObjectType,
2911 NamedDecl *FirstQualifierInScope,
2912 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002913
2914 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2915 NamedDecl *FirstQualifierInScope,
2916 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002917};
Douglas Gregora16548e2009-08-11 05:31:07 +00002918
Douglas Gregorebe10102009-08-20 07:17:43 +00002919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002920StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002921 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002922 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002923
Douglas Gregorebe10102009-08-20 07:17:43 +00002924 switch (S->getStmtClass()) {
2925 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregorebe10102009-08-20 07:17:43 +00002927 // Transform individual statement nodes
2928#define STMT(Node, Parent) \
2929 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002930#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002931#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002932#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002933
Douglas Gregorebe10102009-08-20 07:17:43 +00002934 // Transform expressions by calling TransformExpr.
2935#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002936#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002937#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002938#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002939 {
John McCalldadc5752010-08-24 06:29:42 +00002940 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002941 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002942 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002943
Richard Smith945f8d32013-01-14 22:39:08 +00002944 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002945 }
Mike Stump11289f42009-09-09 15:08:12 +00002946 }
2947
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002948 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002949}
Mike Stump11289f42009-09-09 15:08:12 +00002950
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002951template<typename Derived>
2952OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2953 if (!S)
2954 return S;
2955
2956 switch (S->getClauseKind()) {
2957 default: break;
2958 // Transform individual clause nodes
2959#define OPENMP_CLAUSE(Name, Class) \
2960 case OMPC_ ## Name : \
2961 return getDerived().Transform ## Class(cast<Class>(S));
2962#include "clang/Basic/OpenMPKinds.def"
2963 }
2964
2965 return S;
2966}
2967
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregore922c772009-08-04 22:27:00 +00002969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002970ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002971 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002972 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002973
2974 switch (E->getStmtClass()) {
2975 case Stmt::NoStmtClass: break;
2976#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002977#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002978#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002979 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002980#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002981 }
2982
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002983 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002984}
2985
2986template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002987ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002988 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002989 // Initializers are instantiated like expressions, except that various outer
2990 // layers are stripped.
2991 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002992 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002993
2994 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2995 Init = ExprTemp->getSubExpr();
2996
Richard Smithe6ca4752013-05-30 22:40:16 +00002997 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2998 Init = MTE->GetTemporaryExpr();
2999
Richard Smithd59b8322012-12-19 01:39:02 +00003000 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3001 Init = Binder->getSubExpr();
3002
3003 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3004 Init = ICE->getSubExprAsWritten();
3005
Richard Smithcc1b96d2013-06-12 22:31:48 +00003006 if (CXXStdInitializerListExpr *ILE =
3007 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003008 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003009
Richard Smithc6abd962014-07-25 01:12:44 +00003010 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003011 // InitListExprs. Other forms of copy-initialization will be a no-op if
3012 // the initializer is already the right type.
3013 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003014 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003015 return getDerived().TransformExpr(Init);
3016
3017 // Revert value-initialization back to empty parens.
3018 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3019 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003020 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003021 Parens.getEnd());
3022 }
3023
3024 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3025 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003026 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003027 SourceLocation());
3028
3029 // Revert initialization by constructor back to a parenthesized or braced list
3030 // of expressions. Any other form of initializer can just be reused directly.
3031 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003032 return getDerived().TransformExpr(Init);
3033
Richard Smithf8adcdc2014-07-17 05:12:35 +00003034 // If the initialization implicitly converted an initializer list to a
3035 // std::initializer_list object, unwrap the std::initializer_list too.
3036 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003037 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003038
Richard Smithd59b8322012-12-19 01:39:02 +00003039 SmallVector<Expr*, 8> NewArgs;
3040 bool ArgChanged = false;
3041 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003042 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003043 return ExprError();
3044
3045 // If this was list initialization, revert to list form.
3046 if (Construct->isListInitialization())
3047 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3048 Construct->getLocEnd(),
3049 Construct->getType());
3050
Richard Smithd59b8322012-12-19 01:39:02 +00003051 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003052 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003053 if (Parens.isInvalid()) {
3054 // This was a variable declaration's initialization for which no initializer
3055 // was specified.
3056 assert(NewArgs.empty() &&
3057 "no parens or braces but have direct init with arguments?");
3058 return ExprEmpty();
3059 }
Richard Smithd59b8322012-12-19 01:39:02 +00003060 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3061 Parens.getEnd());
3062}
3063
3064template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003065bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3066 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003067 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003068 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003069 bool *ArgChanged) {
3070 for (unsigned I = 0; I != NumInputs; ++I) {
3071 // If requested, drop call arguments that need to be dropped.
3072 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3073 if (ArgChanged)
3074 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003075
Douglas Gregora3efea12011-01-03 19:04:46 +00003076 break;
3077 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003078
Douglas Gregor968f23a2011-01-03 19:31:53 +00003079 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3080 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Chris Lattner01cf8db2011-07-20 06:58:45 +00003082 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003083 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3084 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003085
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 // Determine whether the set of unexpanded parameter packs can and should
3087 // be expanded.
3088 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003089 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003090 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3091 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003092 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3093 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003094 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003095 Expand, RetainExpansion,
3096 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003097 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003098
Douglas Gregor968f23a2011-01-03 19:31:53 +00003099 if (!Expand) {
3100 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003101 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003102 // expansion.
3103 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3104 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3105 if (OutPattern.isInvalid())
3106 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003107
3108 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003109 Expansion->getEllipsisLoc(),
3110 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003111 if (Out.isInvalid())
3112 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003113
Douglas Gregor968f23a2011-01-03 19:31:53 +00003114 if (ArgChanged)
3115 *ArgChanged = true;
3116 Outputs.push_back(Out.get());
3117 continue;
3118 }
John McCall542e7c62011-07-06 07:30:07 +00003119
3120 // Record right away that the argument was changed. This needs
3121 // to happen even if the array expands to nothing.
3122 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003123
Douglas Gregor968f23a2011-01-03 19:31:53 +00003124 // The transform has determined that we should perform an elementwise
3125 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003126 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3128 ExprResult Out = getDerived().TransformExpr(Pattern);
3129 if (Out.isInvalid())
3130 return true;
3131
Richard Smith9467be42014-06-06 17:33:35 +00003132 // FIXME: Can this happen? We should not try to expand the pack
3133 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003134 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003135 Out = getDerived().RebuildPackExpansion(
3136 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003137 if (Out.isInvalid())
3138 return true;
3139 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Douglas Gregor968f23a2011-01-03 19:31:53 +00003141 Outputs.push_back(Out.get());
3142 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Richard Smith9467be42014-06-06 17:33:35 +00003144 // If we're supposed to retain a pack expansion, do so by temporarily
3145 // forgetting the partially-substituted parameter pack.
3146 if (RetainExpansion) {
3147 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3148
3149 ExprResult Out = getDerived().TransformExpr(Pattern);
3150 if (Out.isInvalid())
3151 return true;
3152
3153 Out = getDerived().RebuildPackExpansion(
3154 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3155 if (Out.isInvalid())
3156 return true;
3157
3158 Outputs.push_back(Out.get());
3159 }
3160
Douglas Gregor968f23a2011-01-03 19:31:53 +00003161 continue;
3162 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003163
Richard Smithd59b8322012-12-19 01:39:02 +00003164 ExprResult Result =
3165 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3166 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003167 if (Result.isInvalid())
3168 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregora3efea12011-01-03 19:04:46 +00003170 if (Result.get() != Inputs[I] && ArgChanged)
3171 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
3173 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregora3efea12011-01-03 19:04:46 +00003176 return false;
3177}
3178
3179template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003180NestedNameSpecifierLoc
3181TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3182 NestedNameSpecifierLoc NNS,
3183 QualType ObjectType,
3184 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003185 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003186 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003187 Qualifier = Qualifier.getPrefix())
3188 Qualifiers.push_back(Qualifier);
3189
3190 CXXScopeSpec SS;
3191 while (!Qualifiers.empty()) {
3192 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3193 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003194
Douglas Gregor14454802011-02-25 02:25:35 +00003195 switch (QNNS->getKind()) {
3196 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003197 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003198 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003199 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003200 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003201 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003202 FirstQualifierInScope, false))
3203 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregor14454802011-02-25 02:25:35 +00003205 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
Douglas Gregor14454802011-02-25 02:25:35 +00003207 case NestedNameSpecifier::Namespace: {
3208 NamespaceDecl *NS
3209 = cast_or_null<NamespaceDecl>(
3210 getDerived().TransformDecl(
3211 Q.getLocalBeginLoc(),
3212 QNNS->getAsNamespace()));
3213 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3214 break;
3215 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003216
Douglas Gregor14454802011-02-25 02:25:35 +00003217 case NestedNameSpecifier::NamespaceAlias: {
3218 NamespaceAliasDecl *Alias
3219 = cast_or_null<NamespaceAliasDecl>(
3220 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3221 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003222 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003223 Q.getLocalEndLoc());
3224 break;
3225 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003226
Douglas Gregor14454802011-02-25 02:25:35 +00003227 case NestedNameSpecifier::Global:
3228 // There is no meaningful transformation that one could perform on the
3229 // global scope.
3230 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3231 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Nikola Smiljanic67860242014-09-26 00:28:20 +00003233 case NestedNameSpecifier::Super: {
3234 CXXRecordDecl *RD =
3235 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3236 SourceLocation(), QNNS->getAsRecordDecl()));
3237 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3238 break;
3239 }
3240
Douglas Gregor14454802011-02-25 02:25:35 +00003241 case NestedNameSpecifier::TypeSpecWithTemplate:
3242 case NestedNameSpecifier::TypeSpec: {
3243 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3244 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003245
Douglas Gregor14454802011-02-25 02:25:35 +00003246 if (!TL)
3247 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003248
Douglas Gregor14454802011-02-25 02:25:35 +00003249 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003250 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003251 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003252 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003253 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003254 if (TL.getType()->isEnumeralType())
3255 SemaRef.Diag(TL.getBeginLoc(),
3256 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003257 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3258 Q.getLocalEndLoc());
3259 break;
3260 }
Richard Trieude756fb2011-05-07 01:36:37 +00003261 // If the nested-name-specifier is an invalid type def, don't emit an
3262 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003263 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3264 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003265 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003266 << TL.getType() << SS.getRange();
3267 }
Douglas Gregor14454802011-02-25 02:25:35 +00003268 return NestedNameSpecifierLoc();
3269 }
Douglas Gregore16af532011-02-28 18:50:33 +00003270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregore16af532011-02-28 18:50:33 +00003272 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003273 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003274 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor14454802011-02-25 02:25:35 +00003277 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003278 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003279 !getDerived().AlwaysRebuild())
3280 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
3282 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003283 // nested-name-specifier, do so.
3284 if (SS.location_size() == NNS.getDataLength() &&
3285 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3286 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3287
3288 // Allocate new nested-name-specifier location information.
3289 return SS.getWithLocInContext(SemaRef.Context);
3290}
3291
3292template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003293DeclarationNameInfo
3294TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003295::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003296 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003297 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003298 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003299
3300 switch (Name.getNameKind()) {
3301 case DeclarationName::Identifier:
3302 case DeclarationName::ObjCZeroArgSelector:
3303 case DeclarationName::ObjCOneArgSelector:
3304 case DeclarationName::ObjCMultiArgSelector:
3305 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003306 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003307 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003308 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregorf816bd72009-09-03 22:13:48 +00003310 case DeclarationName::CXXConstructorName:
3311 case DeclarationName::CXXDestructorName:
3312 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003313 TypeSourceInfo *NewTInfo;
3314 CanQualType NewCanTy;
3315 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003316 NewTInfo = getDerived().TransformType(OldTInfo);
3317 if (!NewTInfo)
3318 return DeclarationNameInfo();
3319 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003320 }
3321 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003322 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003323 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003324 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003325 if (NewT.isNull())
3326 return DeclarationNameInfo();
3327 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3328 }
Mike Stump11289f42009-09-09 15:08:12 +00003329
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003330 DeclarationName NewName
3331 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3332 NewCanTy);
3333 DeclarationNameInfo NewNameInfo(NameInfo);
3334 NewNameInfo.setName(NewName);
3335 NewNameInfo.setNamedTypeInfo(NewTInfo);
3336 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003337 }
Mike Stump11289f42009-09-09 15:08:12 +00003338 }
3339
David Blaikie83d382b2011-09-23 05:06:16 +00003340 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003341}
3342
3343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003344TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003345TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3346 TemplateName Name,
3347 SourceLocation NameLoc,
3348 QualType ObjectType,
3349 NamedDecl *FirstQualifierInScope) {
3350 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3351 TemplateDecl *Template = QTN->getTemplateDecl();
3352 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregor9db53502011-03-02 18:07:45 +00003354 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003355 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003356 Template));
3357 if (!TransTemplate)
3358 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003359
Douglas Gregor9db53502011-03-02 18:07:45 +00003360 if (!getDerived().AlwaysRebuild() &&
3361 SS.getScopeRep() == QTN->getQualifier() &&
3362 TransTemplate == Template)
3363 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregor9db53502011-03-02 18:07:45 +00003365 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3366 TransTemplate);
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor9db53502011-03-02 18:07:45 +00003369 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3370 if (SS.getScopeRep()) {
3371 // These apply to the scope specifier, not the template.
3372 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003373 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003374 }
3375
Douglas Gregor9db53502011-03-02 18:07:45 +00003376 if (!getDerived().AlwaysRebuild() &&
3377 SS.getScopeRep() == DTN->getQualifier() &&
3378 ObjectType.isNull())
3379 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003380
Douglas Gregor9db53502011-03-02 18:07:45 +00003381 if (DTN->isIdentifier()) {
3382 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003383 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003384 NameLoc,
3385 ObjectType,
3386 FirstQualifierInScope);
3387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor9db53502011-03-02 18:07:45 +00003389 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3390 ObjectType);
3391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregor9db53502011-03-02 18:07:45 +00003393 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3394 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003395 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003396 Template));
3397 if (!TransTemplate)
3398 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregor9db53502011-03-02 18:07:45 +00003400 if (!getDerived().AlwaysRebuild() &&
3401 TransTemplate == Template)
3402 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor9db53502011-03-02 18:07:45 +00003404 return TemplateName(TransTemplate);
3405 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9db53502011-03-02 18:07:45 +00003407 if (SubstTemplateTemplateParmPackStorage *SubstPack
3408 = Name.getAsSubstTemplateTemplateParmPack()) {
3409 TemplateTemplateParmDecl *TransParam
3410 = cast_or_null<TemplateTemplateParmDecl>(
3411 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3412 if (!TransParam)
3413 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor9db53502011-03-02 18:07:45 +00003415 if (!getDerived().AlwaysRebuild() &&
3416 TransParam == SubstPack->getParameterPack())
3417 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
3419 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003420 SubstPack->getArgumentPack());
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor9db53502011-03-02 18:07:45 +00003423 // These should be getting filtered out before they reach the AST.
3424 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003425}
3426
3427template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003428void TreeTransform<Derived>::InventTemplateArgumentLoc(
3429 const TemplateArgument &Arg,
3430 TemplateArgumentLoc &Output) {
3431 SourceLocation Loc = getDerived().getBaseLocation();
3432 switch (Arg.getKind()) {
3433 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003434 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003435 break;
3436
3437 case TemplateArgument::Type:
3438 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003439 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
John McCall0ad16662009-10-29 08:12:44 +00003441 break;
3442
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003443 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003444 case TemplateArgument::TemplateExpansion: {
3445 NestedNameSpecifierLocBuilder Builder;
3446 TemplateName Template = Arg.getAsTemplate();
3447 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3448 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3449 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3450 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
Douglas Gregor9d802122011-03-02 17:09:35 +00003452 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003453 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003454 Builder.getWithLocInContext(SemaRef.Context),
3455 Loc);
3456 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003457 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003458 Builder.getWithLocInContext(SemaRef.Context),
3459 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003461 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003462 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003463
John McCall0ad16662009-10-29 08:12:44 +00003464 case TemplateArgument::Expression:
3465 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3466 break;
3467
3468 case TemplateArgument::Declaration:
3469 case TemplateArgument::Integral:
3470 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003471 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003472 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003473 break;
3474 }
3475}
3476
3477template<typename Derived>
3478bool TreeTransform<Derived>::TransformTemplateArgument(
3479 const TemplateArgumentLoc &Input,
3480 TemplateArgumentLoc &Output) {
3481 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003482 switch (Arg.getKind()) {
3483 case TemplateArgument::Null:
3484 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003485 case TemplateArgument::Pack:
3486 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003487 case TemplateArgument::NullPtr:
3488 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregore922c772009-08-04 22:27:00 +00003490 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003491 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003492 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003493 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003494
3495 DI = getDerived().TransformType(DI);
3496 if (!DI) return true;
3497
3498 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3499 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003502 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003503 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3504 if (QualifierLoc) {
3505 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3506 if (!QualifierLoc)
3507 return true;
3508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003509
Douglas Gregordf846d12011-03-02 18:46:51 +00003510 CXXScopeSpec SS;
3511 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003512 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003513 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3514 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003515 if (Template.isNull())
3516 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Douglas Gregor9d802122011-03-02 17:09:35 +00003518 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003519 Input.getTemplateNameLoc());
3520 return false;
3521 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003522
3523 case TemplateArgument::TemplateExpansion:
3524 llvm_unreachable("Caller should expand pack expansions");
3525
Douglas Gregore922c772009-08-04 22:27:00 +00003526 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003527 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003528 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003529 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003530
John McCall0ad16662009-10-29 08:12:44 +00003531 Expr *InputExpr = Input.getSourceExpression();
3532 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3533
Chris Lattnercdb591a2011-04-25 20:37:58 +00003534 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003535 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003536 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003537 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003538 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003539 }
Douglas Gregore922c772009-08-04 22:27:00 +00003540 }
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregore922c772009-08-04 22:27:00 +00003542 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003543 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003544}
3545
Douglas Gregorfe921a72010-12-20 23:36:19 +00003546/// \brief Iterator adaptor that invents template argument location information
3547/// for each of the template arguments in its underlying iterator.
3548template<typename Derived, typename InputIterator>
3549class TemplateArgumentLocInventIterator {
3550 TreeTransform<Derived> &Self;
3551 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregorfe921a72010-12-20 23:36:19 +00003553public:
3554 typedef TemplateArgumentLoc value_type;
3555 typedef TemplateArgumentLoc reference;
3556 typedef typename std::iterator_traits<InputIterator>::difference_type
3557 difference_type;
3558 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregorfe921a72010-12-20 23:36:19 +00003560 class pointer {
3561 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 public:
3564 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregorfe921a72010-12-20 23:36:19 +00003566 const TemplateArgumentLoc *operator->() const { return &Arg; }
3567 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003568
Douglas Gregorfe921a72010-12-20 23:36:19 +00003569 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003570
Douglas Gregorfe921a72010-12-20 23:36:19 +00003571 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3572 InputIterator Iter)
3573 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Douglas Gregorfe921a72010-12-20 23:36:19 +00003575 TemplateArgumentLocInventIterator &operator++() {
3576 ++Iter;
3577 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003578 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003579
Douglas Gregorfe921a72010-12-20 23:36:19 +00003580 TemplateArgumentLocInventIterator operator++(int) {
3581 TemplateArgumentLocInventIterator Old(*this);
3582 ++(*this);
3583 return Old;
3584 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregorfe921a72010-12-20 23:36:19 +00003586 reference operator*() const {
3587 TemplateArgumentLoc Result;
3588 Self.InventTemplateArgumentLoc(*Iter, Result);
3589 return Result;
3590 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregorfe921a72010-12-20 23:36:19 +00003592 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregorfe921a72010-12-20 23:36:19 +00003594 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3595 const TemplateArgumentLocInventIterator &Y) {
3596 return X.Iter == Y.Iter;
3597 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003598
Douglas Gregorfe921a72010-12-20 23:36:19 +00003599 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3600 const TemplateArgumentLocInventIterator &Y) {
3601 return X.Iter != Y.Iter;
3602 }
3603};
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor42cafa82010-12-20 17:42:22 +00003605template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003606template<typename InputIterator>
3607bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3608 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003609 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003610 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003611 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003612 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003614 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3615 // Unpack argument packs, which we translate them into separate
3616 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003617 // FIXME: We could do much better if we could guarantee that the
3618 // TemplateArgumentLocInfo for the pack expansion would be usable for
3619 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003620 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003621 TemplateArgument::pack_iterator>
3622 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003623 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003624 In.getArgument().pack_begin()),
3625 PackLocIterator(*this,
3626 In.getArgument().pack_end()),
3627 Outputs))
3628 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003629
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003630 continue;
3631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003633 if (In.getArgument().isPackExpansion()) {
3634 // We have a pack expansion, for which we will be substituting into
3635 // the pattern.
3636 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003637 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003638 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003639 = getSema().getTemplateArgumentPackExpansionPattern(
3640 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Chris Lattner01cf8db2011-07-20 06:58:45 +00003642 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003643 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3644 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003645
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003646 // Determine whether the set of unexpanded parameter packs can and should
3647 // be expanded.
3648 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003649 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003650 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003651 if (getDerived().TryExpandParameterPacks(Ellipsis,
3652 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003653 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003654 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003655 RetainExpansion,
3656 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003657 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003659 if (!Expand) {
3660 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003661 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003662 // expansion.
3663 TemplateArgumentLoc OutPattern;
3664 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3665 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3666 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003668 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3669 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003670 if (Out.getArgument().isNull())
3671 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 Outputs.addArgument(Out);
3674 continue;
3675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003677 // The transform has determined that we should perform an elementwise
3678 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003679 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003680 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3681
3682 if (getDerived().TransformTemplateArgument(Pattern, Out))
3683 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003685 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003686 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3687 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003688 if (Out.getArgument().isNull())
3689 return true;
3690 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 Outputs.addArgument(Out);
3693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregor48d24112011-01-10 20:53:55 +00003695 // If we're supposed to retain a pack expansion, do so by temporarily
3696 // forgetting the partially-substituted parameter pack.
3697 if (RetainExpansion) {
3698 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003699
Douglas Gregor48d24112011-01-10 20:53:55 +00003700 if (getDerived().TransformTemplateArgument(Pattern, Out))
3701 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003703 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3704 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003705 if (Out.getArgument().isNull())
3706 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Douglas Gregor48d24112011-01-10 20:53:55 +00003708 Outputs.addArgument(Out);
3709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003711 continue;
3712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
3714 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003715 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor42cafa82010-12-20 17:42:22 +00003718 Outputs.addArgument(Out);
3719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor42cafa82010-12-20 17:42:22 +00003721 return false;
3722
3723}
3724
Douglas Gregord6ff3322009-08-04 16:50:30 +00003725//===----------------------------------------------------------------------===//
3726// Type transformation
3727//===----------------------------------------------------------------------===//
3728
3729template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003730QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003731 if (getDerived().AlreadyTransformed(T))
3732 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003733
John McCall550e0c22009-10-21 00:40:46 +00003734 // Temporary workaround. All of these transformations should
3735 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003736 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3737 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003738
John McCall31f82722010-11-12 08:19:04 +00003739 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003740
John McCall550e0c22009-10-21 00:40:46 +00003741 if (!NewDI)
3742 return QualType();
3743
3744 return NewDI->getType();
3745}
3746
3747template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003748TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003749 // Refine the base location to the type's location.
3750 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3751 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003752 if (getDerived().AlreadyTransformed(DI->getType()))
3753 return DI;
3754
3755 TypeLocBuilder TLB;
3756
3757 TypeLoc TL = DI->getTypeLoc();
3758 TLB.reserve(TL.getFullDataSize());
3759
John McCall31f82722010-11-12 08:19:04 +00003760 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003761 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003762 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003763
John McCallbcd03502009-12-07 02:54:59 +00003764 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003765}
3766
3767template<typename Derived>
3768QualType
John McCall31f82722010-11-12 08:19:04 +00003769TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003770 switch (T.getTypeLocClass()) {
3771#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003772#define TYPELOC(CLASS, PARENT) \
3773 case TypeLoc::CLASS: \
3774 return getDerived().Transform##CLASS##Type(TLB, \
3775 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003776#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003777 }
Mike Stump11289f42009-09-09 15:08:12 +00003778
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003779 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003780}
3781
3782/// FIXME: By default, this routine adds type qualifiers only to types
3783/// that can have qualifiers, and silently suppresses those qualifiers
3784/// that are not permitted (e.g., qualifiers on reference or function
3785/// types). This is the right thing for template instantiation, but
3786/// probably not for other clients.
3787template<typename Derived>
3788QualType
3789TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003790 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003791 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003792
John McCall31f82722010-11-12 08:19:04 +00003793 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003794 if (Result.isNull())
3795 return QualType();
3796
3797 // Silently suppress qualifiers if the result type can't be qualified.
3798 // FIXME: this is the right thing for template instantiation, but
3799 // probably not for other clients.
3800 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003802
John McCall31168b02011-06-15 23:02:42 +00003803 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003804 // resulting type.
3805 if (Quals.hasObjCLifetime()) {
3806 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3807 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003808 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003809 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003810 // A lifetime qualifier applied to a substituted template parameter
3811 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003812 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003813 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003814 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3815 QualType Replacement = SubstTypeParam->getReplacementType();
3816 Qualifiers Qs = Replacement.getQualifiers();
3817 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003818 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003819 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3820 Qs);
3821 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003822 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003823 Replacement);
3824 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003825 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3826 // 'auto' types behave the same way as template parameters.
3827 QualType Deduced = AutoTy->getDeducedType();
3828 Qualifiers Qs = Deduced.getQualifiers();
3829 Qs.removeObjCLifetime();
3830 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3831 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003832 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3833 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003834 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003835 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003836 // Otherwise, complain about the addition of a qualifier to an
3837 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003838 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003839 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003840 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Douglas Gregore46db902011-06-17 22:11:49 +00003842 Quals.removeObjCLifetime();
3843 }
3844 }
3845 }
John McCallcb0f89a2010-06-05 06:41:15 +00003846 if (!Quals.empty()) {
3847 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003848 // BuildQualifiedType might not add qualifiers if they are invalid.
3849 if (Result.hasLocalQualifiers())
3850 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003851 // No location information to preserve.
3852 }
John McCall550e0c22009-10-21 00:40:46 +00003853
3854 return Result;
3855}
3856
Douglas Gregor14454802011-02-25 02:25:35 +00003857template<typename Derived>
3858TypeLoc
3859TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3860 QualType ObjectType,
3861 NamedDecl *UnqualLookup,
3862 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003863 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003864 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003865
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003866 TypeSourceInfo *TSI =
3867 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3868 if (TSI)
3869 return TSI->getTypeLoc();
3870 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003871}
3872
Douglas Gregor579c15f2011-03-02 18:32:08 +00003873template<typename Derived>
3874TypeSourceInfo *
3875TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3876 QualType ObjectType,
3877 NamedDecl *UnqualLookup,
3878 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003879 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003880 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003882 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3883 UnqualLookup, SS);
3884}
3885
3886template <typename Derived>
3887TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3888 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3889 CXXScopeSpec &SS) {
3890 QualType T = TL.getType();
3891 assert(!getDerived().AlreadyTransformed(T));
3892
Douglas Gregor579c15f2011-03-02 18:32:08 +00003893 TypeLocBuilder TLB;
3894 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
Douglas Gregor579c15f2011-03-02 18:32:08 +00003896 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003897 TemplateSpecializationTypeLoc SpecTL =
3898 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Douglas Gregor579c15f2011-03-02 18:32:08 +00003900 TemplateName Template
3901 = getDerived().TransformTemplateName(SS,
3902 SpecTL.getTypePtr()->getTemplateName(),
3903 SpecTL.getTemplateNameLoc(),
3904 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003905 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003906 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003907
3908 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003909 Template);
3910 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003911 DependentTemplateSpecializationTypeLoc SpecTL =
3912 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003913
Douglas Gregor579c15f2011-03-02 18:32:08 +00003914 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003915 = getDerived().RebuildTemplateName(SS,
3916 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003917 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003918 ObjectType, UnqualLookup);
3919 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003920 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003921
3922 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003923 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003924 Template,
3925 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003926 } else {
3927 // Nothing special needs to be done for these.
3928 Result = getDerived().TransformType(TLB, TL);
3929 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
3931 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003932 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
Douglas Gregor579c15f2011-03-02 18:32:08 +00003934 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3935}
3936
John McCall550e0c22009-10-21 00:40:46 +00003937template <class TyLoc> static inline
3938QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3939 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3940 NewT.setNameLoc(T.getNameLoc());
3941 return T.getType();
3942}
3943
John McCall550e0c22009-10-21 00:40:46 +00003944template<typename Derived>
3945QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003946 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003947 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3948 NewT.setBuiltinLoc(T.getBuiltinLoc());
3949 if (T.needsExtraLocalData())
3950 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3951 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952}
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregord6ff3322009-08-04 16:50:30 +00003954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003955QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003956 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003957 // FIXME: recurse?
3958 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Reid Kleckner0503a872013-12-05 01:23:43 +00003961template <typename Derived>
3962QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3963 AdjustedTypeLoc TL) {
3964 // Adjustments applied during transformation are handled elsewhere.
3965 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3966}
3967
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003969QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3970 DecayedTypeLoc TL) {
3971 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3972 if (OriginalType.isNull())
3973 return QualType();
3974
3975 QualType Result = TL.getType();
3976 if (getDerived().AlwaysRebuild() ||
3977 OriginalType != TL.getOriginalLoc().getType())
3978 Result = SemaRef.Context.getDecayedType(OriginalType);
3979 TLB.push<DecayedTypeLoc>(Result);
3980 // Nothing to set for DecayedTypeLoc.
3981 return Result;
3982}
3983
3984template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003985QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003986 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003987 QualType PointeeType
3988 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003989 if (PointeeType.isNull())
3990 return QualType();
3991
3992 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003993 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003994 // A dependent pointer type 'T *' has is being transformed such
3995 // that an Objective-C class type is being replaced for 'T'. The
3996 // resulting pointer type is an ObjCObjectPointerType, not a
3997 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003998 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00003999
John McCall8b07ec22010-05-15 11:32:37 +00004000 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4001 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004002 return Result;
4003 }
John McCall31f82722010-11-12 08:19:04 +00004004
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004005 if (getDerived().AlwaysRebuild() ||
4006 PointeeType != TL.getPointeeLoc().getType()) {
4007 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4008 if (Result.isNull())
4009 return QualType();
4010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004011
John McCall31168b02011-06-15 23:02:42 +00004012 // Objective-C ARC can add lifetime qualifiers to the type that we're
4013 // pointing to.
4014 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004015
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004016 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4017 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004018 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019}
Mike Stump11289f42009-09-09 15:08:12 +00004020
4021template<typename Derived>
4022QualType
John McCall550e0c22009-10-21 00:40:46 +00004023TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004024 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004025 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004026 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4027 if (PointeeType.isNull())
4028 return QualType();
4029
4030 QualType Result = TL.getType();
4031 if (getDerived().AlwaysRebuild() ||
4032 PointeeType != TL.getPointeeLoc().getType()) {
4033 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004034 TL.getSigilLoc());
4035 if (Result.isNull())
4036 return QualType();
4037 }
4038
Douglas Gregor049211a2010-04-22 16:50:51 +00004039 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004040 NewT.setSigilLoc(TL.getSigilLoc());
4041 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004042}
4043
John McCall70dd5f62009-10-30 00:06:24 +00004044/// Transforms a reference type. Note that somewhat paradoxically we
4045/// don't care whether the type itself is an l-value type or an r-value
4046/// type; we only care if the type was *written* as an l-value type
4047/// or an r-value type.
4048template<typename Derived>
4049QualType
4050TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004051 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004052 const ReferenceType *T = TL.getTypePtr();
4053
4054 // Note that this works with the pointee-as-written.
4055 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4056 if (PointeeType.isNull())
4057 return QualType();
4058
4059 QualType Result = TL.getType();
4060 if (getDerived().AlwaysRebuild() ||
4061 PointeeType != T->getPointeeTypeAsWritten()) {
4062 Result = getDerived().RebuildReferenceType(PointeeType,
4063 T->isSpelledAsLValue(),
4064 TL.getSigilLoc());
4065 if (Result.isNull())
4066 return QualType();
4067 }
4068
John McCall31168b02011-06-15 23:02:42 +00004069 // Objective-C ARC can add lifetime qualifiers to the type that we're
4070 // referring to.
4071 TLB.TypeWasModifiedSafely(
4072 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4073
John McCall70dd5f62009-10-30 00:06:24 +00004074 // r-value references can be rebuilt as l-value references.
4075 ReferenceTypeLoc NewTL;
4076 if (isa<LValueReferenceType>(Result))
4077 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4078 else
4079 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4080 NewTL.setSigilLoc(TL.getSigilLoc());
4081
4082 return Result;
4083}
4084
Mike Stump11289f42009-09-09 15:08:12 +00004085template<typename Derived>
4086QualType
John McCall550e0c22009-10-21 00:40:46 +00004087TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004088 LValueReferenceTypeLoc TL) {
4089 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004090}
4091
Mike Stump11289f42009-09-09 15:08:12 +00004092template<typename Derived>
4093QualType
John McCall550e0c22009-10-21 00:40:46 +00004094TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004095 RValueReferenceTypeLoc TL) {
4096 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregord6ff3322009-08-04 16:50:30 +00004099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004100QualType
John McCall550e0c22009-10-21 00:40:46 +00004101TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004102 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004103 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004104 if (PointeeType.isNull())
4105 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004106
Abramo Bagnara509357842011-03-05 14:42:21 +00004107 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004108 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004109 if (OldClsTInfo) {
4110 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4111 if (!NewClsTInfo)
4112 return QualType();
4113 }
4114
4115 const MemberPointerType *T = TL.getTypePtr();
4116 QualType OldClsType = QualType(T->getClass(), 0);
4117 QualType NewClsType;
4118 if (NewClsTInfo)
4119 NewClsType = NewClsTInfo->getType();
4120 else {
4121 NewClsType = getDerived().TransformType(OldClsType);
4122 if (NewClsType.isNull())
4123 return QualType();
4124 }
Mike Stump11289f42009-09-09 15:08:12 +00004125
John McCall550e0c22009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004129 NewClsType != OldClsType) {
4130 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004131 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004132 if (Result.isNull())
4133 return QualType();
4134 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004135
Reid Kleckner0503a872013-12-05 01:23:43 +00004136 // If we had to adjust the pointee type when building a member pointer, make
4137 // sure to push TypeLoc info for it.
4138 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4139 if (MPT && PointeeType != MPT->getPointeeType()) {
4140 assert(isa<AdjustedType>(MPT->getPointeeType()));
4141 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4142 }
4143
John McCall550e0c22009-10-21 00:40:46 +00004144 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4145 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004146 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004147
4148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
4150
Mike Stump11289f42009-09-09 15:08:12 +00004151template<typename Derived>
4152QualType
John McCall550e0c22009-10-21 00:40:46 +00004153TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004155 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004156 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157 if (ElementType.isNull())
4158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
4162 ElementType != T->getElementType()) {
4163 Result = getDerived().RebuildConstantArrayType(ElementType,
4164 T->getSizeModifier(),
4165 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004166 T->getIndexTypeCVRQualifiers(),
4167 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004168 if (Result.isNull())
4169 return QualType();
4170 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004171
4172 // We might have either a ConstantArrayType or a VariableArrayType now:
4173 // a ConstantArrayType is allowed to have an element type which is a
4174 // VariableArrayType if the type is dependent. Fortunately, all array
4175 // types have the same location layout.
4176 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004177 NewTL.setLBracketLoc(TL.getLBracketLoc());
4178 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall550e0c22009-10-21 00:40:46 +00004180 Expr *Size = TL.getSizeExpr();
4181 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004182 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4183 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004184 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4185 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004186 }
4187 NewTL.setSizeExpr(Size);
4188
4189 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190}
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregord6ff3322009-08-04 16:50:30 +00004192template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004194 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004195 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004196 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004197 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198 if (ElementType.isNull())
4199 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCall550e0c22009-10-21 00:40:46 +00004201 QualType Result = TL.getType();
4202 if (getDerived().AlwaysRebuild() ||
4203 ElementType != T->getElementType()) {
4204 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004206 T->getIndexTypeCVRQualifiers(),
4207 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004208 if (Result.isNull())
4209 return QualType();
4210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
John McCall550e0c22009-10-21 00:40:46 +00004212 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4213 NewTL.setLBracketLoc(TL.getLBracketLoc());
4214 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004215 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004216
4217 return Result;
4218}
4219
4220template<typename Derived>
4221QualType
4222TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004223 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004224 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004225 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4226 if (ElementType.isNull())
4227 return QualType();
4228
John McCalldadc5752010-08-24 06:29:42 +00004229 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004230 = getDerived().TransformExpr(T->getSizeExpr());
4231 if (SizeResult.isInvalid())
4232 return QualType();
4233
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004234 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004235
4236 QualType Result = TL.getType();
4237 if (getDerived().AlwaysRebuild() ||
4238 ElementType != T->getElementType() ||
4239 Size != T->getSizeExpr()) {
4240 Result = getDerived().RebuildVariableArrayType(ElementType,
4241 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004242 Size,
John McCall550e0c22009-10-21 00:40:46 +00004243 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004244 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004245 if (Result.isNull())
4246 return QualType();
4247 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004248
Serge Pavlov774c6d02014-02-06 03:49:11 +00004249 // We might have constant size array now, but fortunately it has the same
4250 // location layout.
4251 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004252 NewTL.setLBracketLoc(TL.getLBracketLoc());
4253 NewTL.setRBracketLoc(TL.getRBracketLoc());
4254 NewTL.setSizeExpr(Size);
4255
4256 return Result;
4257}
4258
4259template<typename Derived>
4260QualType
4261TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004262 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004263 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004264 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4265 if (ElementType.isNull())
4266 return QualType();
4267
Richard Smith764d2fe2011-12-20 02:08:33 +00004268 // Array bounds are constant expressions.
4269 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4270 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004271
John McCall33ddac02011-01-19 10:06:00 +00004272 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4273 Expr *origSize = TL.getSizeExpr();
4274 if (!origSize) origSize = T->getSizeExpr();
4275
4276 ExprResult sizeResult
4277 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004278 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004279 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004280 return QualType();
4281
John McCall33ddac02011-01-19 10:06:00 +00004282 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004283
4284 QualType Result = TL.getType();
4285 if (getDerived().AlwaysRebuild() ||
4286 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004287 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004288 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4289 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004290 size,
John McCall550e0c22009-10-21 00:40:46 +00004291 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004292 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004293 if (Result.isNull())
4294 return QualType();
4295 }
John McCall550e0c22009-10-21 00:40:46 +00004296
4297 // We might have any sort of array type now, but fortunately they
4298 // all have the same location layout.
4299 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4300 NewTL.setLBracketLoc(TL.getLBracketLoc());
4301 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004302 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004303
4304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004305}
Mike Stump11289f42009-09-09 15:08:12 +00004306
4307template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004308QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004309 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004310 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004311 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004312
4313 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314 QualType ElementType = getDerived().TransformType(T->getElementType());
4315 if (ElementType.isNull())
4316 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004317
Richard Smith764d2fe2011-12-20 02:08:33 +00004318 // Vector sizes are constant expressions.
4319 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4320 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004321
John McCalldadc5752010-08-24 06:29:42 +00004322 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004323 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004324 if (Size.isInvalid())
4325 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004326
John McCall550e0c22009-10-21 00:40:46 +00004327 QualType Result = TL.getType();
4328 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004329 ElementType != T->getElementType() ||
4330 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004331 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004332 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004333 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004334 if (Result.isNull())
4335 return QualType();
4336 }
John McCall550e0c22009-10-21 00:40:46 +00004337
4338 // Result might be dependent or not.
4339 if (isa<DependentSizedExtVectorType>(Result)) {
4340 DependentSizedExtVectorTypeLoc NewTL
4341 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4342 NewTL.setNameLoc(TL.getNameLoc());
4343 } else {
4344 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4345 NewTL.setNameLoc(TL.getNameLoc());
4346 }
4347
4348 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004349}
Mike Stump11289f42009-09-09 15:08:12 +00004350
4351template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004352QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004353 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004354 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355 QualType ElementType = getDerived().TransformType(T->getElementType());
4356 if (ElementType.isNull())
4357 return QualType();
4358
John McCall550e0c22009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
4361 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004362 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004363 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004364 if (Result.isNull())
4365 return QualType();
4366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004367
John McCall550e0c22009-10-21 00:40:46 +00004368 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4369 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004370
John McCall550e0c22009-10-21 00:40:46 +00004371 return Result;
4372}
4373
4374template<typename Derived>
4375QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004376 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004377 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004378 QualType ElementType = getDerived().TransformType(T->getElementType());
4379 if (ElementType.isNull())
4380 return QualType();
4381
4382 QualType Result = TL.getType();
4383 if (getDerived().AlwaysRebuild() ||
4384 ElementType != T->getElementType()) {
4385 Result = getDerived().RebuildExtVectorType(ElementType,
4386 T->getNumElements(),
4387 /*FIXME*/ SourceLocation());
4388 if (Result.isNull())
4389 return QualType();
4390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004391
John McCall550e0c22009-10-21 00:40:46 +00004392 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4393 NewTL.setNameLoc(TL.getNameLoc());
4394
4395 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
David Blaikie05785d12013-02-20 22:23:23 +00004398template <typename Derived>
4399ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4400 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4401 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004402 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004403 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004404
Douglas Gregor715e4612011-01-14 22:40:04 +00004405 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004406 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004407 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004408 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004409 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004410
Douglas Gregor715e4612011-01-14 22:40:04 +00004411 TypeLocBuilder TLB;
4412 TypeLoc NewTL = OldDI->getTypeLoc();
4413 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004414
4415 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004416 OldExpansionTL.getPatternLoc());
4417 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004418 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004419
4420 Result = RebuildPackExpansionType(Result,
4421 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004422 OldExpansionTL.getEllipsisLoc(),
4423 NumExpansions);
4424 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004425 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
Douglas Gregor715e4612011-01-14 22:40:04 +00004427 PackExpansionTypeLoc NewExpansionTL
4428 = TLB.push<PackExpansionTypeLoc>(Result);
4429 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4430 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4431 } else
4432 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004433 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004434 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004435
John McCall8fb0d9d2011-05-01 22:35:37 +00004436 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004437 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004438
4439 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4440 OldParm->getDeclContext(),
4441 OldParm->getInnerLocStart(),
4442 OldParm->getLocation(),
4443 OldParm->getIdentifier(),
4444 NewDI->getType(),
4445 NewDI,
4446 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004447 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004448 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4449 OldParm->getFunctionScopeIndex() + indexAdjustment);
4450 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004451}
4452
4453template<typename Derived>
4454bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004455 TransformFunctionTypeParams(SourceLocation Loc,
4456 ParmVarDecl **Params, unsigned NumParams,
4457 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004458 SmallVectorImpl<QualType> &OutParamTypes,
4459 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004460 int indexAdjustment = 0;
4461
Douglas Gregordd472162011-01-07 00:20:55 +00004462 for (unsigned i = 0; i != NumParams; ++i) {
4463 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004464 assert(OldParm->getFunctionScopeIndex() == i);
4465
David Blaikie05785d12013-02-20 22:23:23 +00004466 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004467 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004468 if (OldParm->isParameterPack()) {
4469 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004470 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004471
Douglas Gregor5499af42011-01-05 23:12:31 +00004472 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004473 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004474 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004475 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4476 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004477 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4478
Douglas Gregor5499af42011-01-05 23:12:31 +00004479 // Determine whether we should expand the parameter packs.
4480 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004481 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004482 Optional<unsigned> OrigNumExpansions =
4483 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004484 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004485 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4486 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004487 Unexpanded,
4488 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004489 RetainExpansion,
4490 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004491 return true;
4492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004493
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 if (ShouldExpand) {
4495 // Expand the function parameter pack into multiple, separate
4496 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004497 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004498 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004499 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004500 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004501 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004502 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004503 OrigNumExpansions,
4504 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 if (!NewParm)
4506 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004507
Douglas Gregordd472162011-01-07 00:20:55 +00004508 OutParamTypes.push_back(NewParm->getType());
4509 if (PVars)
4510 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004511 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004512
4513 // If we're supposed to retain a pack expansion, do so by temporarily
4514 // forgetting the partially-substituted parameter pack.
4515 if (RetainExpansion) {
4516 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004517 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004518 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004519 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004520 OrigNumExpansions,
4521 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004522 if (!NewParm)
4523 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004524
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004525 OutParamTypes.push_back(NewParm->getType());
4526 if (PVars)
4527 PVars->push_back(NewParm);
4528 }
4529
John McCall8fb0d9d2011-05-01 22:35:37 +00004530 // The next parameter should have the same adjustment as the
4531 // last thing we pushed, but we post-incremented indexAdjustment
4532 // on every push. Also, if we push nothing, the adjustment should
4533 // go down by one.
4534 indexAdjustment--;
4535
Douglas Gregor5499af42011-01-05 23:12:31 +00004536 // We're done with the pack expansion.
4537 continue;
4538 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004539
4540 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004541 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4543 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004544 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004545 NumExpansions,
4546 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004547 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004548 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004549 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004550 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004551
John McCall58f10c32010-03-11 09:03:00 +00004552 if (!NewParm)
4553 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004554
Douglas Gregordd472162011-01-07 00:20:55 +00004555 OutParamTypes.push_back(NewParm->getType());
4556 if (PVars)
4557 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004558 continue;
4559 }
John McCall58f10c32010-03-11 09:03:00 +00004560
4561 // Deal with the possibility that we don't have a parameter
4562 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004563 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004564 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004565 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004566 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004567 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004568 = dyn_cast<PackExpansionType>(OldType)) {
4569 // We have a function parameter pack that may need to be expanded.
4570 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004571 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004572 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004573
Douglas Gregor5499af42011-01-05 23:12:31 +00004574 // Determine whether we should expand the parameter packs.
4575 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004576 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004577 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004578 Unexpanded,
4579 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004580 RetainExpansion,
4581 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004582 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004583 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004584
Douglas Gregor5499af42011-01-05 23:12:31 +00004585 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004586 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004587 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004588 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004589 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4590 QualType NewType = getDerived().TransformType(Pattern);
4591 if (NewType.isNull())
4592 return true;
John McCall58f10c32010-03-11 09:03:00 +00004593
Douglas Gregordd472162011-01-07 00:20:55 +00004594 OutParamTypes.push_back(NewType);
4595 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004596 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004598
Douglas Gregor5499af42011-01-05 23:12:31 +00004599 // We're done with the pack expansion.
4600 continue;
4601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004602
Douglas Gregor48d24112011-01-10 20:53:55 +00004603 // If we're supposed to retain a pack expansion, do so by temporarily
4604 // forgetting the partially-substituted parameter pack.
4605 if (RetainExpansion) {
4606 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4607 QualType NewType = getDerived().TransformType(Pattern);
4608 if (NewType.isNull())
4609 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004610
Douglas Gregor48d24112011-01-10 20:53:55 +00004611 OutParamTypes.push_back(NewType);
4612 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004613 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004614 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004615
Chad Rosier1dcde962012-08-08 18:46:20 +00004616 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004617 // expansion.
4618 OldType = Expansion->getPattern();
4619 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004620 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4621 NewType = getDerived().TransformType(OldType);
4622 } else {
4623 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004625
Douglas Gregor5499af42011-01-05 23:12:31 +00004626 if (NewType.isNull())
4627 return true;
4628
4629 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004630 NewType = getSema().Context.getPackExpansionType(NewType,
4631 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Douglas Gregordd472162011-01-07 00:20:55 +00004633 OutParamTypes.push_back(NewType);
4634 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004635 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004636 }
4637
John McCall8fb0d9d2011-05-01 22:35:37 +00004638#ifndef NDEBUG
4639 if (PVars) {
4640 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4641 if (ParmVarDecl *parm = (*PVars)[i])
4642 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004643 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004644#endif
4645
4646 return false;
4647}
John McCall58f10c32010-03-11 09:03:00 +00004648
4649template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004650QualType
John McCall550e0c22009-10-21 00:40:46 +00004651TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004652 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004653 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004654 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004655 return getDerived().TransformFunctionProtoType(
4656 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004657 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4658 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4659 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004660 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004661}
4662
Richard Smith2e321552014-11-12 02:00:47 +00004663template<typename Derived> template<typename Fn>
4664QualType TreeTransform<Derived>::TransformFunctionProtoType(
4665 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4666 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004667 // Transform the parameters and return type.
4668 //
Richard Smithf623c962012-04-17 00:58:00 +00004669 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004670 // When the function has a trailing return type, we instantiate the
4671 // parameters before the return type, since the return type can then refer
4672 // to the parameters themselves (via decltype, sizeof, etc.).
4673 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004674 SmallVector<QualType, 4> ParamTypes;
4675 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004676 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004677
Douglas Gregor7fb25412010-10-01 18:44:50 +00004678 QualType ResultType;
4679
Richard Smith1226c602012-08-14 22:51:13 +00004680 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004681 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004682 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004683 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004684 return QualType();
4685
Douglas Gregor3024f072012-04-16 07:05:22 +00004686 {
4687 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004688 // If a declaration declares a member function or member function
4689 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004690 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004691 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004692 // declarator.
4693 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004694
Alp Toker42a16a62014-01-25 23:51:36 +00004695 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004696 if (ResultType.isNull())
4697 return QualType();
4698 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004699 }
4700 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004701 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004702 if (ResultType.isNull())
4703 return QualType();
4704
Alp Toker9cacbab2014-01-20 20:26:09 +00004705 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004706 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004707 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004708 return QualType();
4709 }
4710
Richard Smith2e321552014-11-12 02:00:47 +00004711 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4712
4713 bool EPIChanged = false;
4714 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4715 return QualType();
4716
4717 // FIXME: Need to transform ConsumedParameters for variadic template
4718 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004719
John McCall550e0c22009-10-21 00:40:46 +00004720 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004721 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004722 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004723 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004724 if (Result.isNull())
4725 return QualType();
4726 }
Mike Stump11289f42009-09-09 15:08:12 +00004727
John McCall550e0c22009-10-21 00:40:46 +00004728 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004729 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004730 NewTL.setLParenLoc(TL.getLParenLoc());
4731 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004732 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004733 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4734 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004735
4736 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004737}
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004740bool TreeTransform<Derived>::TransformExceptionSpec(
4741 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4742 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4743 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4744
4745 // Instantiate a dynamic noexcept expression, if any.
4746 if (ESI.Type == EST_ComputedNoexcept) {
4747 EnterExpressionEvaluationContext Unevaluated(getSema(),
4748 Sema::ConstantEvaluated);
4749 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4750 if (NoexceptExpr.isInvalid())
4751 return true;
4752
4753 NoexceptExpr = getSema().CheckBooleanCondition(
4754 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4755 if (NoexceptExpr.isInvalid())
4756 return true;
4757
4758 if (!NoexceptExpr.get()->isValueDependent()) {
4759 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4760 NoexceptExpr.get(), nullptr,
4761 diag::err_noexcept_needs_constant_expression,
4762 /*AllowFold*/false);
4763 if (NoexceptExpr.isInvalid())
4764 return true;
4765 }
4766
4767 if (ESI.NoexceptExpr != NoexceptExpr.get())
4768 Changed = true;
4769 ESI.NoexceptExpr = NoexceptExpr.get();
4770 }
4771
4772 if (ESI.Type != EST_Dynamic)
4773 return false;
4774
4775 // Instantiate a dynamic exception specification's type.
4776 for (QualType T : ESI.Exceptions) {
4777 if (const PackExpansionType *PackExpansion =
4778 T->getAs<PackExpansionType>()) {
4779 Changed = true;
4780
4781 // We have a pack expansion. Instantiate it.
4782 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4783 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4784 Unexpanded);
4785 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4786
4787 // Determine whether the set of unexpanded parameter packs can and
4788 // should
4789 // be expanded.
4790 bool Expand = false;
4791 bool RetainExpansion = false;
4792 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4793 // FIXME: Track the location of the ellipsis (and track source location
4794 // information for the types in the exception specification in general).
4795 if (getDerived().TryExpandParameterPacks(
4796 Loc, SourceRange(), Unexpanded, Expand,
4797 RetainExpansion, NumExpansions))
4798 return true;
4799
4800 if (!Expand) {
4801 // We can't expand this pack expansion into separate arguments yet;
4802 // just substitute into the pattern and create a new pack expansion
4803 // type.
4804 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4805 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4806 if (U.isNull())
4807 return true;
4808
4809 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4810 Exceptions.push_back(U);
4811 continue;
4812 }
4813
4814 // Substitute into the pack expansion pattern for each slice of the
4815 // pack.
4816 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4817 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4818
4819 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4820 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4821 return true;
4822
4823 Exceptions.push_back(U);
4824 }
4825 } else {
4826 QualType U = getDerived().TransformType(T);
4827 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4828 return true;
4829 if (T != U)
4830 Changed = true;
4831
4832 Exceptions.push_back(U);
4833 }
4834 }
4835
4836 ESI.Exceptions = Exceptions;
4837 return false;
4838}
4839
4840template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004841QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004842 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004843 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004844 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004845 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004846 if (ResultType.isNull())
4847 return QualType();
4848
4849 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004850 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004851 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4852
4853 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004854 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004855 NewTL.setLParenLoc(TL.getLParenLoc());
4856 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004857 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004858
4859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
John McCallb96ec562009-12-04 22:46:56 +00004862template<typename Derived> QualType
4863TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004864 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004865 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004866 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004867 if (!D)
4868 return QualType();
4869
4870 QualType Result = TL.getType();
4871 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4872 Result = getDerived().RebuildUnresolvedUsingType(D);
4873 if (Result.isNull())
4874 return QualType();
4875 }
4876
4877 // We might get an arbitrary type spec type back. We should at
4878 // least always get a type spec type, though.
4879 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4880 NewTL.setNameLoc(TL.getNameLoc());
4881
4882 return Result;
4883}
4884
Douglas Gregord6ff3322009-08-04 16:50:30 +00004885template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004886QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004887 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004888 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004889 TypedefNameDecl *Typedef
4890 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4891 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004892 if (!Typedef)
4893 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCall550e0c22009-10-21 00:40:46 +00004895 QualType Result = TL.getType();
4896 if (getDerived().AlwaysRebuild() ||
4897 Typedef != T->getDecl()) {
4898 Result = getDerived().RebuildTypedefType(Typedef);
4899 if (Result.isNull())
4900 return QualType();
4901 }
Mike Stump11289f42009-09-09 15:08:12 +00004902
John McCall550e0c22009-10-21 00:40:46 +00004903 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4904 NewTL.setNameLoc(TL.getNameLoc());
4905
4906 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004907}
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregord6ff3322009-08-04 16:50:30 +00004909template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004910QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004911 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004912 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004913 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4914 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCalldadc5752010-08-24 06:29:42 +00004916 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004917 if (E.isInvalid())
4918 return QualType();
4919
Eli Friedmane4f22df2012-02-29 04:03:55 +00004920 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4921 if (E.isInvalid())
4922 return QualType();
4923
John McCall550e0c22009-10-21 00:40:46 +00004924 QualType Result = TL.getType();
4925 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004926 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004927 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004928 if (Result.isNull())
4929 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004930 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004931 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004932
John McCall550e0c22009-10-21 00:40:46 +00004933 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004934 NewTL.setTypeofLoc(TL.getTypeofLoc());
4935 NewTL.setLParenLoc(TL.getLParenLoc());
4936 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004937
4938 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004939}
Mike Stump11289f42009-09-09 15:08:12 +00004940
4941template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004942QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004943 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004944 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4945 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4946 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004947 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004948
John McCall550e0c22009-10-21 00:40:46 +00004949 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004950 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4951 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004952 if (Result.isNull())
4953 return QualType();
4954 }
Mike Stump11289f42009-09-09 15:08:12 +00004955
John McCall550e0c22009-10-21 00:40:46 +00004956 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004957 NewTL.setTypeofLoc(TL.getTypeofLoc());
4958 NewTL.setLParenLoc(TL.getLParenLoc());
4959 NewTL.setRParenLoc(TL.getRParenLoc());
4960 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004961
4962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004963}
Mike Stump11289f42009-09-09 15:08:12 +00004964
4965template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004966QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004967 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004968 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004969
Douglas Gregore922c772009-08-04 22:27:00 +00004970 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004971 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4972 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004973
John McCalldadc5752010-08-24 06:29:42 +00004974 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004975 if (E.isInvalid())
4976 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004977
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004978 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004979 if (E.isInvalid())
4980 return QualType();
4981
John McCall550e0c22009-10-21 00:40:46 +00004982 QualType Result = TL.getType();
4983 if (getDerived().AlwaysRebuild() ||
4984 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004985 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004986 if (Result.isNull())
4987 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004988 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004989 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004990
John McCall550e0c22009-10-21 00:40:46 +00004991 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4992 NewTL.setNameLoc(TL.getNameLoc());
4993
4994 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004995}
4996
4997template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004998QualType TreeTransform<Derived>::TransformUnaryTransformType(
4999 TypeLocBuilder &TLB,
5000 UnaryTransformTypeLoc TL) {
5001 QualType Result = TL.getType();
5002 if (Result->isDependentType()) {
5003 const UnaryTransformType *T = TL.getTypePtr();
5004 QualType NewBase =
5005 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5006 Result = getDerived().RebuildUnaryTransformType(NewBase,
5007 T->getUTTKind(),
5008 TL.getKWLoc());
5009 if (Result.isNull())
5010 return QualType();
5011 }
5012
5013 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5014 NewTL.setKWLoc(TL.getKWLoc());
5015 NewTL.setParensRange(TL.getParensRange());
5016 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5017 return Result;
5018}
5019
5020template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005021QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5022 AutoTypeLoc TL) {
5023 const AutoType *T = TL.getTypePtr();
5024 QualType OldDeduced = T->getDeducedType();
5025 QualType NewDeduced;
5026 if (!OldDeduced.isNull()) {
5027 NewDeduced = getDerived().TransformType(OldDeduced);
5028 if (NewDeduced.isNull())
5029 return QualType();
5030 }
5031
5032 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005033 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5034 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005035 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005036 if (Result.isNull())
5037 return QualType();
5038 }
5039
5040 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5041 NewTL.setNameLoc(TL.getNameLoc());
5042
5043 return Result;
5044}
5045
5046template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005047QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005048 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005049 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005050 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005051 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5052 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005053 if (!Record)
5054 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005055
John McCall550e0c22009-10-21 00:40:46 +00005056 QualType Result = TL.getType();
5057 if (getDerived().AlwaysRebuild() ||
5058 Record != T->getDecl()) {
5059 Result = getDerived().RebuildRecordType(Record);
5060 if (Result.isNull())
5061 return QualType();
5062 }
Mike Stump11289f42009-09-09 15:08:12 +00005063
John McCall550e0c22009-10-21 00:40:46 +00005064 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5065 NewTL.setNameLoc(TL.getNameLoc());
5066
5067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
5070template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005071QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005072 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005073 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005074 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005075 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5076 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005077 if (!Enum)
5078 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005079
John McCall550e0c22009-10-21 00:40:46 +00005080 QualType Result = TL.getType();
5081 if (getDerived().AlwaysRebuild() ||
5082 Enum != T->getDecl()) {
5083 Result = getDerived().RebuildEnumType(Enum);
5084 if (Result.isNull())
5085 return QualType();
5086 }
Mike Stump11289f42009-09-09 15:08:12 +00005087
John McCall550e0c22009-10-21 00:40:46 +00005088 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5089 NewTL.setNameLoc(TL.getNameLoc());
5090
5091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005092}
John McCallfcc33b02009-09-05 00:15:47 +00005093
John McCalle78aac42010-03-10 03:28:59 +00005094template<typename Derived>
5095QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5096 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005097 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005098 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5099 TL.getTypePtr()->getDecl());
5100 if (!D) return QualType();
5101
5102 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5103 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5104 return T;
5105}
5106
Douglas Gregord6ff3322009-08-04 16:50:30 +00005107template<typename Derived>
5108QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005109 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005110 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005111 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112}
5113
Mike Stump11289f42009-09-09 15:08:12 +00005114template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005115QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005116 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005117 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005118 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005119
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005120 // Substitute into the replacement type, which itself might involve something
5121 // that needs to be transformed. This only tends to occur with default
5122 // template arguments of template template parameters.
5123 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5124 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5125 if (Replacement.isNull())
5126 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005127
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005128 // Always canonicalize the replacement type.
5129 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5130 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005131 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005132 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005133
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005134 // Propagate type-source information.
5135 SubstTemplateTypeParmTypeLoc NewTL
5136 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5137 NewTL.setNameLoc(TL.getNameLoc());
5138 return Result;
5139
John McCallcebee162009-10-18 09:09:24 +00005140}
5141
5142template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005143QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5144 TypeLocBuilder &TLB,
5145 SubstTemplateTypeParmPackTypeLoc TL) {
5146 return TransformTypeSpecType(TLB, TL);
5147}
5148
5149template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005150QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005151 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005152 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005153 const TemplateSpecializationType *T = TL.getTypePtr();
5154
Douglas Gregordf846d12011-03-02 18:46:51 +00005155 // The nested-name-specifier never matters in a TemplateSpecializationType,
5156 // because we can't have a dependent nested-name-specifier anyway.
5157 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005158 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005159 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5160 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161 if (Template.isNull())
5162 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005163
John McCall31f82722010-11-12 08:19:04 +00005164 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5165}
5166
Eli Friedman0dfb8892011-10-06 23:00:33 +00005167template<typename Derived>
5168QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5169 AtomicTypeLoc TL) {
5170 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5171 if (ValueType.isNull())
5172 return QualType();
5173
5174 QualType Result = TL.getType();
5175 if (getDerived().AlwaysRebuild() ||
5176 ValueType != TL.getValueLoc().getType()) {
5177 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5178 if (Result.isNull())
5179 return QualType();
5180 }
5181
5182 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5183 NewTL.setKWLoc(TL.getKWLoc());
5184 NewTL.setLParenLoc(TL.getLParenLoc());
5185 NewTL.setRParenLoc(TL.getRParenLoc());
5186
5187 return Result;
5188}
5189
Chad Rosier1dcde962012-08-08 18:46:20 +00005190 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005191 /// container that provides a \c getArgLoc() member function.
5192 ///
5193 /// This iterator is intended to be used with the iterator form of
5194 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5195 template<typename ArgLocContainer>
5196 class TemplateArgumentLocContainerIterator {
5197 ArgLocContainer *Container;
5198 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005199
Douglas Gregorfe921a72010-12-20 23:36:19 +00005200 public:
5201 typedef TemplateArgumentLoc value_type;
5202 typedef TemplateArgumentLoc reference;
5203 typedef int difference_type;
5204 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005205
Douglas Gregorfe921a72010-12-20 23:36:19 +00005206 class pointer {
5207 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
Douglas Gregorfe921a72010-12-20 23:36:19 +00005209 public:
5210 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005211
Douglas Gregorfe921a72010-12-20 23:36:19 +00005212 const TemplateArgumentLoc *operator->() const {
5213 return &Arg;
5214 }
5215 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005216
5217
Douglas Gregorfe921a72010-12-20 23:36:19 +00005218 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
Douglas Gregorfe921a72010-12-20 23:36:19 +00005220 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5221 unsigned Index)
5222 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005223
Douglas Gregorfe921a72010-12-20 23:36:19 +00005224 TemplateArgumentLocContainerIterator &operator++() {
5225 ++Index;
5226 return *this;
5227 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005228
Douglas Gregorfe921a72010-12-20 23:36:19 +00005229 TemplateArgumentLocContainerIterator operator++(int) {
5230 TemplateArgumentLocContainerIterator Old(*this);
5231 ++(*this);
5232 return Old;
5233 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005234
Douglas Gregorfe921a72010-12-20 23:36:19 +00005235 TemplateArgumentLoc operator*() const {
5236 return Container->getArgLoc(Index);
5237 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005238
Douglas Gregorfe921a72010-12-20 23:36:19 +00005239 pointer operator->() const {
5240 return pointer(Container->getArgLoc(Index));
5241 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005242
Douglas Gregorfe921a72010-12-20 23:36:19 +00005243 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005244 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005245 return X.Container == Y.Container && X.Index == Y.Index;
5246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005247
Douglas Gregorfe921a72010-12-20 23:36:19 +00005248 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005249 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005250 return !(X == Y);
5251 }
5252 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005253
5254
John McCall31f82722010-11-12 08:19:04 +00005255template <typename Derived>
5256QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5257 TypeLocBuilder &TLB,
5258 TemplateSpecializationTypeLoc TL,
5259 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005260 TemplateArgumentListInfo NewTemplateArgs;
5261 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5262 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005263 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5264 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005265 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005266 ArgIterator(TL, TL.getNumArgs()),
5267 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005268 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005269
John McCall0ad16662009-10-29 08:12:44 +00005270 // FIXME: maybe don't rebuild if all the template arguments are the same.
5271
5272 QualType Result =
5273 getDerived().RebuildTemplateSpecializationType(Template,
5274 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005275 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005276
5277 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005278 // Specializations of template template parameters are represented as
5279 // TemplateSpecializationTypes, and substitution of type alias templates
5280 // within a dependent context can transform them into
5281 // DependentTemplateSpecializationTypes.
5282 if (isa<DependentTemplateSpecializationType>(Result)) {
5283 DependentTemplateSpecializationTypeLoc NewTL
5284 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005285 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005286 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005287 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005288 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005289 NewTL.setLAngleLoc(TL.getLAngleLoc());
5290 NewTL.setRAngleLoc(TL.getRAngleLoc());
5291 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5292 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5293 return Result;
5294 }
5295
John McCall0ad16662009-10-29 08:12:44 +00005296 TemplateSpecializationTypeLoc NewTL
5297 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005298 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005299 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5300 NewTL.setLAngleLoc(TL.getLAngleLoc());
5301 NewTL.setRAngleLoc(TL.getRAngleLoc());
5302 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5303 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304 }
Mike Stump11289f42009-09-09 15:08:12 +00005305
John McCall0ad16662009-10-29 08:12:44 +00005306 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005307}
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregor5a064722011-02-28 17:23:35 +00005309template <typename Derived>
5310QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5311 TypeLocBuilder &TLB,
5312 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005313 TemplateName Template,
5314 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005315 TemplateArgumentListInfo NewTemplateArgs;
5316 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5317 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5318 typedef TemplateArgumentLocContainerIterator<
5319 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005320 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005321 ArgIterator(TL, TL.getNumArgs()),
5322 NewTemplateArgs))
5323 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005324
Douglas Gregor5a064722011-02-28 17:23:35 +00005325 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005326
Douglas Gregor5a064722011-02-28 17:23:35 +00005327 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5328 QualType Result
5329 = getSema().Context.getDependentTemplateSpecializationType(
5330 TL.getTypePtr()->getKeyword(),
5331 DTN->getQualifier(),
5332 DTN->getIdentifier(),
5333 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005334
Douglas Gregor5a064722011-02-28 17:23:35 +00005335 DependentTemplateSpecializationTypeLoc NewTL
5336 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005337 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005338 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005339 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005340 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005341 NewTL.setLAngleLoc(TL.getLAngleLoc());
5342 NewTL.setRAngleLoc(TL.getRAngleLoc());
5343 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5344 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5345 return Result;
5346 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005347
5348 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005349 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005350 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005351 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005352
Douglas Gregor5a064722011-02-28 17:23:35 +00005353 if (!Result.isNull()) {
5354 /// FIXME: Wrap this in an elaborated-type-specifier?
5355 TemplateSpecializationTypeLoc NewTL
5356 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005357 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005358 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005359 NewTL.setLAngleLoc(TL.getLAngleLoc());
5360 NewTL.setRAngleLoc(TL.getRAngleLoc());
5361 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5362 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005364
Douglas Gregor5a064722011-02-28 17:23:35 +00005365 return Result;
5366}
5367
Mike Stump11289f42009-09-09 15:08:12 +00005368template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005369QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005370TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005371 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005372 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005373
Douglas Gregor844cb502011-03-01 18:12:44 +00005374 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005375 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005376 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005377 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005378 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5379 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005380 return QualType();
5381 }
Mike Stump11289f42009-09-09 15:08:12 +00005382
John McCall31f82722010-11-12 08:19:04 +00005383 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5384 if (NamedT.isNull())
5385 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005386
Richard Smith3f1b5d02011-05-05 21:57:07 +00005387 // C++0x [dcl.type.elab]p2:
5388 // If the identifier resolves to a typedef-name or the simple-template-id
5389 // resolves to an alias template specialization, the
5390 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005391 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5392 if (const TemplateSpecializationType *TST =
5393 NamedT->getAs<TemplateSpecializationType>()) {
5394 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005395 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5396 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005397 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5398 diag::err_tag_reference_non_tag) << 4;
5399 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5400 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005401 }
5402 }
5403
John McCall550e0c22009-10-21 00:40:46 +00005404 QualType Result = TL.getType();
5405 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005406 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005407 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005408 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005409 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005410 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005411 if (Result.isNull())
5412 return QualType();
5413 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005414
Abramo Bagnara6150c882010-05-11 21:36:43 +00005415 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005416 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005417 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005418 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419}
Mike Stump11289f42009-09-09 15:08:12 +00005420
5421template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005422QualType TreeTransform<Derived>::TransformAttributedType(
5423 TypeLocBuilder &TLB,
5424 AttributedTypeLoc TL) {
5425 const AttributedType *oldType = TL.getTypePtr();
5426 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5427 if (modifiedType.isNull())
5428 return QualType();
5429
5430 QualType result = TL.getType();
5431
5432 // FIXME: dependent operand expressions?
5433 if (getDerived().AlwaysRebuild() ||
5434 modifiedType != oldType->getModifiedType()) {
5435 // TODO: this is really lame; we should really be rebuilding the
5436 // equivalent type from first principles.
5437 QualType equivalentType
5438 = getDerived().TransformType(oldType->getEquivalentType());
5439 if (equivalentType.isNull())
5440 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005441
5442 // Check whether we can add nullability; it is only represented as
5443 // type sugar, and therefore cannot be diagnosed in any other way.
5444 if (auto nullability = oldType->getImmediateNullability()) {
5445 if (!modifiedType->canHaveNullability()) {
5446 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005447 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005448 return QualType();
5449 }
5450 }
5451
John McCall81904512011-01-06 01:58:22 +00005452 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5453 modifiedType,
5454 equivalentType);
5455 }
5456
5457 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5458 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5459 if (TL.hasAttrOperand())
5460 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5461 if (TL.hasAttrExprOperand())
5462 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5463 else if (TL.hasAttrEnumOperand())
5464 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5465
5466 return result;
5467}
5468
5469template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005470QualType
5471TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5472 ParenTypeLoc TL) {
5473 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5474 if (Inner.isNull())
5475 return QualType();
5476
5477 QualType Result = TL.getType();
5478 if (getDerived().AlwaysRebuild() ||
5479 Inner != TL.getInnerLoc().getType()) {
5480 Result = getDerived().RebuildParenType(Inner);
5481 if (Result.isNull())
5482 return QualType();
5483 }
5484
5485 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5486 NewTL.setLParenLoc(TL.getLParenLoc());
5487 NewTL.setRParenLoc(TL.getRParenLoc());
5488 return Result;
5489}
5490
5491template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005492QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005493 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005494 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005495
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005496 NestedNameSpecifierLoc QualifierLoc
5497 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5498 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005499 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005500
John McCallc392f372010-06-11 00:33:02 +00005501 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005502 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005503 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005504 QualifierLoc,
5505 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005506 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005507 if (Result.isNull())
5508 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005509
Abramo Bagnarad7548482010-05-19 21:37:53 +00005510 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5511 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005512 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5513
Abramo Bagnarad7548482010-05-19 21:37:53 +00005514 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005515 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005516 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005517 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005518 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005519 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005520 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005521 NewTL.setNameLoc(TL.getNameLoc());
5522 }
John McCall550e0c22009-10-21 00:40:46 +00005523 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005524}
Mike Stump11289f42009-09-09 15:08:12 +00005525
Douglas Gregord6ff3322009-08-04 16:50:30 +00005526template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005527QualType TreeTransform<Derived>::
5528 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005529 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005530 NestedNameSpecifierLoc QualifierLoc;
5531 if (TL.getQualifierLoc()) {
5532 QualifierLoc
5533 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5534 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005535 return QualType();
5536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005537
John McCall31f82722010-11-12 08:19:04 +00005538 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005539 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005540}
5541
5542template<typename Derived>
5543QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005544TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5545 DependentTemplateSpecializationTypeLoc TL,
5546 NestedNameSpecifierLoc QualifierLoc) {
5547 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005548
Douglas Gregora7a795b2011-03-01 20:11:18 +00005549 TemplateArgumentListInfo NewTemplateArgs;
5550 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5551 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregora7a795b2011-03-01 20:11:18 +00005553 typedef TemplateArgumentLocContainerIterator<
5554 DependentTemplateSpecializationTypeLoc> ArgIterator;
5555 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5556 ArgIterator(TL, TL.getNumArgs()),
5557 NewTemplateArgs))
5558 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005559
Douglas Gregora7a795b2011-03-01 20:11:18 +00005560 QualType Result
5561 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5562 QualifierLoc,
5563 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005564 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005565 NewTemplateArgs);
5566 if (Result.isNull())
5567 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005568
Douglas Gregora7a795b2011-03-01 20:11:18 +00005569 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5570 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005571
Douglas Gregora7a795b2011-03-01 20:11:18 +00005572 // Copy information relevant to the template specialization.
5573 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005574 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005575 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005576 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005577 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5578 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005579 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005580 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005581
Douglas Gregora7a795b2011-03-01 20:11:18 +00005582 // Copy information relevant to the elaborated type.
5583 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005584 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005585 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005586 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5587 DependentTemplateSpecializationTypeLoc SpecTL
5588 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005589 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005590 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005591 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005592 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005593 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5594 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005595 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005596 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005597 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005598 TemplateSpecializationTypeLoc SpecTL
5599 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005600 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005601 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005602 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5603 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005604 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005605 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005606 }
5607 return Result;
5608}
5609
5610template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005611QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5612 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005613 QualType Pattern
5614 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005615 if (Pattern.isNull())
5616 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005617
5618 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005619 if (getDerived().AlwaysRebuild() ||
5620 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005621 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005622 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005623 TL.getEllipsisLoc(),
5624 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005625 if (Result.isNull())
5626 return QualType();
5627 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005628
Douglas Gregor822d0302011-01-12 17:07:58 +00005629 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5630 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5631 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005632}
5633
5634template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005635QualType
5636TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005637 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005638 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005639 TLB.pushFullCopy(TL);
5640 return TL.getType();
5641}
5642
5643template<typename Derived>
5644QualType
5645TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005646 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005647 // Transform base type.
5648 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5649 if (BaseType.isNull())
5650 return QualType();
5651
5652 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5653
5654 // Transform type arguments.
5655 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5656 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5657 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5658 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5659 QualType TypeArg = TypeArgInfo->getType();
5660 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5661 AnyChanged = true;
5662
5663 // We have a pack expansion. Instantiate it.
5664 const auto *PackExpansion = PackExpansionLoc.getType()
5665 ->castAs<PackExpansionType>();
5666 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5667 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5668 Unexpanded);
5669 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5670
5671 // Determine whether the set of unexpanded parameter packs can
5672 // and should be expanded.
5673 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5674 bool Expand = false;
5675 bool RetainExpansion = false;
5676 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5677 if (getDerived().TryExpandParameterPacks(
5678 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5679 Unexpanded, Expand, RetainExpansion, NumExpansions))
5680 return QualType();
5681
5682 if (!Expand) {
5683 // We can't expand this pack expansion into separate arguments yet;
5684 // just substitute into the pattern and create a new pack expansion
5685 // type.
5686 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5687
5688 TypeLocBuilder TypeArgBuilder;
5689 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5690 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5691 PatternLoc);
5692 if (NewPatternType.isNull())
5693 return QualType();
5694
5695 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5696 NewPatternType, NumExpansions);
5697 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5698 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5699 NewTypeArgInfos.push_back(
5700 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5701 continue;
5702 }
5703
5704 // Substitute into the pack expansion pattern for each slice of the
5705 // pack.
5706 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5707 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5708
5709 TypeLocBuilder TypeArgBuilder;
5710 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5711
5712 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5713 PatternLoc);
5714 if (NewTypeArg.isNull())
5715 return QualType();
5716
5717 NewTypeArgInfos.push_back(
5718 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5719 }
5720
5721 continue;
5722 }
5723
5724 TypeLocBuilder TypeArgBuilder;
5725 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5726 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5727 if (NewTypeArg.isNull())
5728 return QualType();
5729
5730 // If nothing changed, just keep the old TypeSourceInfo.
5731 if (NewTypeArg == TypeArg) {
5732 NewTypeArgInfos.push_back(TypeArgInfo);
5733 continue;
5734 }
5735
5736 NewTypeArgInfos.push_back(
5737 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5738 AnyChanged = true;
5739 }
5740
5741 QualType Result = TL.getType();
5742 if (getDerived().AlwaysRebuild() || AnyChanged) {
5743 // Rebuild the type.
5744 Result = getDerived().RebuildObjCObjectType(
5745 BaseType,
5746 TL.getLocStart(),
5747 TL.getTypeArgsLAngleLoc(),
5748 NewTypeArgInfos,
5749 TL.getTypeArgsRAngleLoc(),
5750 TL.getProtocolLAngleLoc(),
5751 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5752 TL.getNumProtocols()),
5753 TL.getProtocolLocs(),
5754 TL.getProtocolRAngleLoc());
5755
5756 if (Result.isNull())
5757 return QualType();
5758 }
5759
5760 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5761 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5762 NewT.setHasBaseTypeAsWritten(true);
5763 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5764 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5765 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5766 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5767 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5768 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5769 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5770 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5771 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
5774template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005775QualType
5776TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005777 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005778 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5779 if (PointeeType.isNull())
5780 return QualType();
5781
5782 QualType Result = TL.getType();
5783 if (getDerived().AlwaysRebuild() ||
5784 PointeeType != TL.getPointeeLoc().getType()) {
5785 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5786 TL.getStarLoc());
5787 if (Result.isNull())
5788 return QualType();
5789 }
5790
5791 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5792 NewT.setStarLoc(TL.getStarLoc());
5793 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005794}
5795
Douglas Gregord6ff3322009-08-04 16:50:30 +00005796//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005797// Statement transformation
5798//===----------------------------------------------------------------------===//
5799template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005800StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005801TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005802 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005803}
5804
5805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005807TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5808 return getDerived().TransformCompoundStmt(S, false);
5809}
5810
5811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005813TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005814 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005815 Sema::CompoundScopeRAII CompoundScope(getSema());
5816
John McCall1ababa62010-08-27 19:56:05 +00005817 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005818 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005819 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005820 for (auto *B : S->body()) {
5821 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005822 if (Result.isInvalid()) {
5823 // Immediately fail if this was a DeclStmt, since it's very
5824 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005825 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005826 return StmtError();
5827
5828 // Otherwise, just keep processing substatements and fail later.
5829 SubStmtInvalid = true;
5830 continue;
5831 }
Mike Stump11289f42009-09-09 15:08:12 +00005832
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005833 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005834 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005835 }
Mike Stump11289f42009-09-09 15:08:12 +00005836
John McCall1ababa62010-08-27 19:56:05 +00005837 if (SubStmtInvalid)
5838 return StmtError();
5839
Douglas Gregorebe10102009-08-20 07:17:43 +00005840 if (!getDerived().AlwaysRebuild() &&
5841 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005842 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005843
5844 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005845 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005846 S->getRBracLoc(),
5847 IsStmtExpr);
5848}
Mike Stump11289f42009-09-09 15:08:12 +00005849
Douglas Gregorebe10102009-08-20 07:17:43 +00005850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005851StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005852TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005853 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005854 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005855 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5856 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005857
Eli Friedman06577382009-11-19 03:14:00 +00005858 // Transform the left-hand case value.
5859 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005860 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005861 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005863
Eli Friedman06577382009-11-19 03:14:00 +00005864 // Transform the right-hand case value (for the GNU case-range extension).
5865 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005866 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005867 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005869 }
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregorebe10102009-08-20 07:17:43 +00005871 // Build the case statement.
5872 // Case statements are always rebuilt so that they will attached to their
5873 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005874 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005875 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005876 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005877 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005878 S->getColonLoc());
5879 if (Case.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 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005883 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005884 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregorebe10102009-08-20 07:17:43 +00005887 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005888 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005889}
5890
5891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005892StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005893TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005894 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005895 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005896 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005898
Douglas Gregorebe10102009-08-20 07:17:43 +00005899 // Default statements are always rebuilt
5900 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005901 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005902}
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregorebe10102009-08-20 07:17:43 +00005904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005906TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005907 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005908 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005909 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005910
Chris Lattnercab02a62011-02-17 20:34:02 +00005911 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5912 S->getDecl());
5913 if (!LD)
5914 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005915
5916
Douglas Gregorebe10102009-08-20 07:17:43 +00005917 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005918 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005919 cast<LabelDecl>(LD), SourceLocation(),
5920 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005923template <typename Derived>
5924const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5925 if (!R)
5926 return R;
5927
5928 switch (R->getKind()) {
5929// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5930#define ATTR(X)
5931#define PRAGMA_SPELLING_ATTR(X) \
5932 case attr::X: \
5933 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5934#include "clang/Basic/AttrList.inc"
5935 default:
5936 return R;
5937 }
5938}
5939
5940template <typename Derived>
5941StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5942 bool AttrsChanged = false;
5943 SmallVector<const Attr *, 1> Attrs;
5944
5945 // Visit attributes and keep track if any are transformed.
5946 for (const auto *I : S->getAttrs()) {
5947 const Attr *R = getDerived().TransformAttr(I);
5948 AttrsChanged |= (I != R);
5949 Attrs.push_back(R);
5950 }
5951
Richard Smithc202b282012-04-14 00:33:13 +00005952 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5953 if (SubStmt.isInvalid())
5954 return StmtError();
5955
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005956 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005957 return S;
5958
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005959 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005960 SubStmt.get());
5961}
5962
5963template<typename Derived>
5964StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005965TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005966 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005967 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005968 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005969 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005970 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005971 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005972 getDerived().TransformDefinition(
5973 S->getConditionVariable()->getLocation(),
5974 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005975 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005976 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005977 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005978 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005980 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005981 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005983 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005984 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005985 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005986 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005987 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005988 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
John McCallb268a282010-08-23 23:25:46 +00005990 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005991 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005993
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005994 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005995 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005997
Douglas Gregorebe10102009-08-20 07:17:43 +00005998 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005999 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregorebe10102009-08-20 07:17:43 +00006003 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006004 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006005 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006006 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006007
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006009 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006010 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006011 Then.get() == S->getThen() &&
6012 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006013 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006015 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006016 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006017 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006018}
6019
6020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006021StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006022TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006023 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006024 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006025 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006026 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006027 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006028 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006029 getDerived().TransformDefinition(
6030 S->getConditionVariable()->getLocation(),
6031 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006032 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006033 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006034 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006035 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006036
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006037 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006038 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006039 }
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006042 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006043 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006044 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregorebe10102009-08-20 07:17:43 +00006048 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006049 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006050 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregorebe10102009-08-20 07:17:43 +00006053 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006054 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6055 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregorebe10102009-08-20 07:17:43 +00006058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006059StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006060TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006061 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006062 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006063 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006064 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006065 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006066 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006067 getDerived().TransformDefinition(
6068 S->getConditionVariable()->getLocation(),
6069 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006070 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006072 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006073 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006074
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006075 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006076 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006077
6078 if (S->getCond()) {
6079 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006080 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6081 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006082 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006083 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006084 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006085 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006086 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006087 }
Mike Stump11289f42009-09-09 15:08:12 +00006088
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006089 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006090 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006091 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006092
Douglas Gregorebe10102009-08-20 07:17:43 +00006093 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006094 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006099 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006100 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006101 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006102 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006103
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006104 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006105 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006106}
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregorebe10102009-08-20 07:17:43 +00006108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006110TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006111 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006112 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006113 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006114 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006115
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006116 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006117 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006118 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006120
Douglas Gregorebe10102009-08-20 07:17:43 +00006121 if (!getDerived().AlwaysRebuild() &&
6122 Cond.get() == S->getCond() &&
6123 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006124 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCallb268a282010-08-23 23:25:46 +00006126 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6127 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006128 S->getRParenLoc());
6129}
Mike Stump11289f42009-09-09 15:08:12 +00006130
Douglas Gregorebe10102009-08-20 07:17:43 +00006131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006132StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006133TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006135 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006136 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006137 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006141 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006142 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006143 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006144 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006145 getDerived().TransformDefinition(
6146 S->getConditionVariable()->getLocation(),
6147 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006148 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006150 } else {
6151 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006152
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006153 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006155
6156 if (S->getCond()) {
6157 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006158 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6159 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006160 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006161 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006163
John McCallb268a282010-08-23 23:25:46 +00006164 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006165 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006166 }
Mike Stump11289f42009-09-09 15:08:12 +00006167
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006168 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006169 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006171
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006173 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
Richard Smith945f8d32013-01-14 22:39:08 +00006177 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006178 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006179 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006180
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006182 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006185
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 if (!getDerived().AlwaysRebuild() &&
6187 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006188 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 Inc.get() == S->getInc() &&
6190 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006191 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006192
Douglas Gregorebe10102009-08-20 07:17:43 +00006193 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006194 Init.get(), FullCond, ConditionVar,
6195 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006196}
6197
6198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006200TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006201 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6202 S->getLabel());
6203 if (!LD)
6204 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006205
Douglas Gregorebe10102009-08-20 07:17:43 +00006206 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006207 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006208 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006209}
6210
6211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006212StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006213TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006214 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006215 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006216 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006217 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregorebe10102009-08-20 07:17:43 +00006219 if (!getDerived().AlwaysRebuild() &&
6220 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006221 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006222
6223 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006224 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006225}
6226
6227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006228StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006229TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006230 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006231}
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregorebe10102009-08-20 07:17:43 +00006233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006234StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006235TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006236 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006237}
Mike Stump11289f42009-09-09 15:08:12 +00006238
Douglas Gregorebe10102009-08-20 07:17:43 +00006239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006240StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006241TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006242 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6243 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006244 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006246
Mike Stump11289f42009-09-09 15:08:12 +00006247 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006249 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006250}
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregorebe10102009-08-20 07:17:43 +00006252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006253StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006254TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006255 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006256 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006257 for (auto *D : S->decls()) {
6258 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006259 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006261
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006262 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006263 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 Decls.push_back(Transformed);
6266 }
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006269 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006270
Rafael Espindolaab417692013-07-09 12:05:01 +00006271 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006272}
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006275StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006276TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006277
Benjamin Kramerf0623432012-08-23 22:51:59 +00006278 SmallVector<Expr*, 8> Constraints;
6279 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006280 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006281
John McCalldadc5752010-08-24 06:29:42 +00006282 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006283 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006284
6285 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006286
Anders Carlssonaaeef072010-01-24 05:50:09 +00006287 // Go through the outputs.
6288 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006289 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006290
Anders Carlssonaaeef072010-01-24 05:50:09 +00006291 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006292 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006293
Anders Carlssonaaeef072010-01-24 05:50:09 +00006294 // Transform the output expr.
6295 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006296 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006297 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006298 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006299
Anders Carlssonaaeef072010-01-24 05:50:09 +00006300 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006301
John McCallb268a282010-08-23 23:25:46 +00006302 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006304
Anders Carlssonaaeef072010-01-24 05:50:09 +00006305 // Go through the inputs.
6306 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006307 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006308
Anders Carlssonaaeef072010-01-24 05:50:09 +00006309 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006310 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006311
Anders Carlssonaaeef072010-01-24 05:50:09 +00006312 // Transform the input expr.
6313 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006314 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006315 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006316 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006317
Anders Carlssonaaeef072010-01-24 05:50:09 +00006318 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
John McCallb268a282010-08-23 23:25:46 +00006320 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006321 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Anders Carlssonaaeef072010-01-24 05:50:09 +00006323 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006324 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006325
6326 // Go through the clobbers.
6327 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006328 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006329
6330 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006331 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006332 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6333 S->isVolatile(), S->getNumOutputs(),
6334 S->getNumInputs(), Names.data(),
6335 Constraints, Exprs, AsmString.get(),
6336 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006337}
6338
Chad Rosier32503022012-06-11 20:47:18 +00006339template<typename Derived>
6340StmtResult
6341TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006342 ArrayRef<Token> AsmToks =
6343 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006344
John McCallf413f5e2013-05-03 00:10:13 +00006345 bool HadError = false, HadChange = false;
6346
6347 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6348 SmallVector<Expr*, 8> TransformedExprs;
6349 TransformedExprs.reserve(SrcExprs.size());
6350 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6351 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6352 if (!Result.isUsable()) {
6353 HadError = true;
6354 } else {
6355 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006356 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006357 }
6358 }
6359
6360 if (HadError) return StmtError();
6361 if (!HadChange && !getDerived().AlwaysRebuild())
6362 return Owned(S);
6363
Chad Rosierb6f46c12012-08-15 16:53:30 +00006364 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006365 AsmToks, S->getAsmString(),
6366 S->getNumOutputs(), S->getNumInputs(),
6367 S->getAllConstraints(), S->getClobbers(),
6368 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006369}
Douglas Gregorebe10102009-08-20 07:17:43 +00006370
6371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006372StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006373TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006374 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006375 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006376 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006378
Douglas Gregor96c79492010-04-23 22:50:49 +00006379 // Transform the @catch statements (if present).
6380 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006381 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006382 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006383 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006384 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006386 if (Catch.get() != S->getCatchStmt(I))
6387 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006388 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006390
Douglas Gregor306de2f2010-04-22 23:59:56 +00006391 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006392 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006393 if (S->getFinallyStmt()) {
6394 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6395 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006396 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006397 }
6398
6399 // If nothing changed, just retain this statement.
6400 if (!getDerived().AlwaysRebuild() &&
6401 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006402 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006403 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006404 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006405
Douglas Gregor306de2f2010-04-22 23:59:56 +00006406 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006407 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006408 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006409}
Mike Stump11289f42009-09-09 15:08:12 +00006410
Douglas Gregorebe10102009-08-20 07:17:43 +00006411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006412StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006413TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006414 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006415 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006416 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006417 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006418 if (FromVar->getTypeSourceInfo()) {
6419 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6420 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006423
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006424 QualType T;
6425 if (TSInfo)
6426 T = TSInfo->getType();
6427 else {
6428 T = getDerived().TransformType(FromVar->getType());
6429 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006430 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006432
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006433 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6434 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006437
John McCalldadc5752010-08-24 06:29:42 +00006438 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006439 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006440 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006441
6442 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006443 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006444 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006445}
Mike Stump11289f42009-09-09 15:08:12 +00006446
Douglas Gregorebe10102009-08-20 07:17:43 +00006447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006448StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006449TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006450 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006451 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006452 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006453 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006454
Douglas Gregor306de2f2010-04-22 23:59:56 +00006455 // If nothing changed, just retain this statement.
6456 if (!getDerived().AlwaysRebuild() &&
6457 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006458 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006459
6460 // Build a new statement.
6461 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006462 Body.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
Mike Stump11289f42009-09-09 15:08:12 +00006467TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006468 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006469 if (S->getThrowExpr()) {
6470 Operand = getDerived().TransformExpr(S->getThrowExpr());
6471 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006472 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006474
Douglas Gregor2900c162010-04-22 21:44:01 +00006475 if (!getDerived().AlwaysRebuild() &&
6476 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006477 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006478
John McCallb268a282010-08-23 23:25:46 +00006479 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006480}
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregorebe10102009-08-20 07:17:43 +00006482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006483StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006484TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006485 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006486 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006487 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006488 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006489 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006490 Object =
6491 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6492 Object.get());
6493 if (Object.isInvalid())
6494 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006495
Douglas Gregor6148de72010-04-22 22:01:21 +00006496 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006497 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006498 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006499 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006500
Douglas Gregor6148de72010-04-22 22:01:21 +00006501 // If nothing change, just retain the current statement.
6502 if (!getDerived().AlwaysRebuild() &&
6503 Object.get() == S->getSynchExpr() &&
6504 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006505 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006506
6507 // Build a new statement.
6508 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006509 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006510}
6511
6512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006513StmtResult
John McCall31168b02011-06-15 23:02:42 +00006514TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6515 ObjCAutoreleasePoolStmt *S) {
6516 // Transform the body.
6517 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6518 if (Body.isInvalid())
6519 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006520
John McCall31168b02011-06-15 23:02:42 +00006521 // If nothing changed, just retain this statement.
6522 if (!getDerived().AlwaysRebuild() &&
6523 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006524 return S;
John McCall31168b02011-06-15 23:02:42 +00006525
6526 // Build a new statement.
6527 return getDerived().RebuildObjCAutoreleasePoolStmt(
6528 S->getAtLoc(), Body.get());
6529}
6530
6531template<typename Derived>
6532StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006533TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006534 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006535 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006536 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006537 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006538 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006539
Douglas Gregorf68a5082010-04-22 23:10:45 +00006540 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006541 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006542 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006543 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006544
Douglas Gregorf68a5082010-04-22 23:10:45 +00006545 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006546 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006547 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006549
Douglas Gregorf68a5082010-04-22 23:10:45 +00006550 // If nothing changed, just retain this statement.
6551 if (!getDerived().AlwaysRebuild() &&
6552 Element.get() == S->getElement() &&
6553 Collection.get() == S->getCollection() &&
6554 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006555 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006556
Douglas Gregorf68a5082010-04-22 23:10:45 +00006557 // Build a new statement.
6558 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006559 Element.get(),
6560 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006561 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006562 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006563}
6564
David Majnemer5f7efef2013-10-15 09:50:08 +00006565template <typename Derived>
6566StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006567 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006568 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006569 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6570 TypeSourceInfo *T =
6571 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006572 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006573 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006574
David Majnemer5f7efef2013-10-15 09:50:08 +00006575 Var = getDerived().RebuildExceptionDecl(
6576 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6577 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006578 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006579 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006580 }
Mike Stump11289f42009-09-09 15:08:12 +00006581
Douglas Gregorebe10102009-08-20 07:17:43 +00006582 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006583 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006584 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006585 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006586
David Majnemer5f7efef2013-10-15 09:50:08 +00006587 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006588 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006589 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006590
David Majnemer5f7efef2013-10-15 09:50:08 +00006591 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006592}
Mike Stump11289f42009-09-09 15:08:12 +00006593
David Majnemer5f7efef2013-10-15 09:50:08 +00006594template <typename Derived>
6595StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006596 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006597 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006598 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006600
Douglas Gregorebe10102009-08-20 07:17:43 +00006601 // Transform the handlers.
6602 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006603 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006604 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006605 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006606 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006608
Douglas Gregorebe10102009-08-20 07:17:43 +00006609 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006610 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006611 }
Mike Stump11289f42009-09-09 15:08:12 +00006612
David Majnemer5f7efef2013-10-15 09:50:08 +00006613 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006615 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006616
John McCallb268a282010-08-23 23:25:46 +00006617 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006618 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006619}
Mike Stump11289f42009-09-09 15:08:12 +00006620
Richard Smith02e85f32011-04-14 22:09:26 +00006621template<typename Derived>
6622StmtResult
6623TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6624 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6625 if (Range.isInvalid())
6626 return StmtError();
6627
6628 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6629 if (BeginEnd.isInvalid())
6630 return StmtError();
6631
6632 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6633 if (Cond.isInvalid())
6634 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006635 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006636 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006637 if (Cond.isInvalid())
6638 return StmtError();
6639 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006640 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006641
6642 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6643 if (Inc.isInvalid())
6644 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006645 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006646 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006647
6648 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6649 if (LoopVar.isInvalid())
6650 return StmtError();
6651
6652 StmtResult NewStmt = S;
6653 if (getDerived().AlwaysRebuild() ||
6654 Range.get() != S->getRangeStmt() ||
6655 BeginEnd.get() != S->getBeginEndStmt() ||
6656 Cond.get() != S->getCond() ||
6657 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006658 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006659 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6660 S->getColonLoc(), Range.get(),
6661 BeginEnd.get(), Cond.get(),
6662 Inc.get(), LoopVar.get(),
6663 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006664 if (NewStmt.isInvalid())
6665 return StmtError();
6666 }
Richard Smith02e85f32011-04-14 22:09:26 +00006667
6668 StmtResult Body = getDerived().TransformStmt(S->getBody());
6669 if (Body.isInvalid())
6670 return StmtError();
6671
6672 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6673 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006674 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006675 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6676 S->getColonLoc(), Range.get(),
6677 BeginEnd.get(), Cond.get(),
6678 Inc.get(), LoopVar.get(),
6679 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006680 if (NewStmt.isInvalid())
6681 return StmtError();
6682 }
Richard Smith02e85f32011-04-14 22:09:26 +00006683
6684 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006685 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006686
6687 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6688}
6689
John Wiegley1c0675e2011-04-28 01:08:34 +00006690template<typename Derived>
6691StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006692TreeTransform<Derived>::TransformMSDependentExistsStmt(
6693 MSDependentExistsStmt *S) {
6694 // Transform the nested-name-specifier, if any.
6695 NestedNameSpecifierLoc QualifierLoc;
6696 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006697 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006698 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6699 if (!QualifierLoc)
6700 return StmtError();
6701 }
6702
6703 // Transform the declaration name.
6704 DeclarationNameInfo NameInfo = S->getNameInfo();
6705 if (NameInfo.getName()) {
6706 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6707 if (!NameInfo.getName())
6708 return StmtError();
6709 }
6710
6711 // Check whether anything changed.
6712 if (!getDerived().AlwaysRebuild() &&
6713 QualifierLoc == S->getQualifierLoc() &&
6714 NameInfo.getName() == S->getNameInfo().getName())
6715 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006716
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006717 // Determine whether this name exists, if we can.
6718 CXXScopeSpec SS;
6719 SS.Adopt(QualifierLoc);
6720 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006721 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006722 case Sema::IER_Exists:
6723 if (S->isIfExists())
6724 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006725
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006726 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6727
6728 case Sema::IER_DoesNotExist:
6729 if (S->isIfNotExists())
6730 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006731
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006732 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006733
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006734 case Sema::IER_Dependent:
6735 Dependent = true;
6736 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006737
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006738 case Sema::IER_Error:
6739 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006741
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006742 // We need to continue with the instantiation, so do so now.
6743 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6744 if (SubStmt.isInvalid())
6745 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006746
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006747 // If we have resolved the name, just transform to the substatement.
6748 if (!Dependent)
6749 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006751 // The name is still dependent, so build a dependent expression again.
6752 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6753 S->isIfExists(),
6754 QualifierLoc,
6755 NameInfo,
6756 SubStmt.get());
6757}
6758
6759template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006760ExprResult
6761TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6762 NestedNameSpecifierLoc QualifierLoc;
6763 if (E->getQualifierLoc()) {
6764 QualifierLoc
6765 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6766 if (!QualifierLoc)
6767 return ExprError();
6768 }
6769
6770 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6771 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6772 if (!PD)
6773 return ExprError();
6774
6775 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6776 if (Base.isInvalid())
6777 return ExprError();
6778
6779 return new (SemaRef.getASTContext())
6780 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6781 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6782 QualifierLoc, E->getMemberLoc());
6783}
6784
David Majnemerfad8f482013-10-15 09:33:02 +00006785template <typename Derived>
6786StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006787 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006788 if (TryBlock.isInvalid())
6789 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006790
6791 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006792 if (Handler.isInvalid())
6793 return StmtError();
6794
David Majnemerfad8f482013-10-15 09:33:02 +00006795 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6796 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006797 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006798
Warren Huntf6be4cb2014-07-25 20:52:51 +00006799 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6800 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006801}
6802
David Majnemerfad8f482013-10-15 09:33:02 +00006803template <typename Derived>
6804StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006805 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006806 if (Block.isInvalid())
6807 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006808
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006809 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006810}
6811
David Majnemerfad8f482013-10-15 09:33:02 +00006812template <typename Derived>
6813StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006814 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006815 if (FilterExpr.isInvalid())
6816 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006817
David Majnemer7e755502013-10-15 09:30:14 +00006818 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006819 if (Block.isInvalid())
6820 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006821
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006822 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6823 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006824}
6825
David Majnemerfad8f482013-10-15 09:33:02 +00006826template <typename Derived>
6827StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6828 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006829 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6830 else
6831 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6832}
6833
Nico Weber9b982072014-07-07 00:12:30 +00006834template<typename Derived>
6835StmtResult
6836TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6837 return S;
6838}
6839
Alexander Musman64d33f12014-06-04 07:53:32 +00006840//===----------------------------------------------------------------------===//
6841// OpenMP directive transformation
6842//===----------------------------------------------------------------------===//
6843template <typename Derived>
6844StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6845 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006846
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006847 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006848 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006849 ArrayRef<OMPClause *> Clauses = D->clauses();
6850 TClauses.reserve(Clauses.size());
6851 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6852 I != E; ++I) {
6853 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006854 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006855 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006856 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006857 if (Clause)
6858 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006859 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006860 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006861 }
6862 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006863 StmtResult AssociatedStmt;
6864 if (D->hasAssociatedStmt()) {
6865 if (!D->getAssociatedStmt()) {
6866 return StmtError();
6867 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006868 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6869 /*CurScope=*/nullptr);
6870 StmtResult Body;
6871 {
6872 Sema::CompoundScopeRAII CompoundScope(getSema());
6873 Body = getDerived().TransformStmt(
6874 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6875 }
6876 AssociatedStmt =
6877 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006878 if (AssociatedStmt.isInvalid()) {
6879 return StmtError();
6880 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006881 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006882 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006883 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006884 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006885
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006886 // Transform directive name for 'omp critical' directive.
6887 DeclarationNameInfo DirName;
6888 if (D->getDirectiveKind() == OMPD_critical) {
6889 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6890 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6891 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006892 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6893 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6894 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006895 } else if (D->getDirectiveKind() == OMPD_cancel) {
6896 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006897 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006898
Alexander Musman64d33f12014-06-04 07:53:32 +00006899 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006900 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6901 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006902}
6903
Alexander Musman64d33f12014-06-04 07:53:32 +00006904template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006905StmtResult
6906TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6907 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006908 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6909 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006910 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6912 return Res;
6913}
6914
Alexander Musman64d33f12014-06-04 07:53:32 +00006915template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006916StmtResult
6917TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6918 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006919 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6920 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006921 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006923 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006924}
6925
Alexey Bataevf29276e2014-06-18 04:14:57 +00006926template <typename Derived>
6927StmtResult
6928TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6929 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006930 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6931 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006932 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6933 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6934 return Res;
6935}
6936
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006937template <typename Derived>
6938StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006939TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6940 DeclarationNameInfo DirName;
6941 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6942 D->getLocStart());
6943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6945 return Res;
6946}
6947
6948template <typename Derived>
6949StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006950TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6951 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006952 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6953 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006954 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6955 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6956 return Res;
6957}
6958
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006959template <typename Derived>
6960StmtResult
6961TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6962 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006963 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6964 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006965 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6966 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6967 return Res;
6968}
6969
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006970template <typename Derived>
6971StmtResult
6972TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6973 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006974 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6975 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006976 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6977 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6978 return Res;
6979}
6980
Alexey Bataev4acb8592014-07-07 13:01:15 +00006981template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006982StmtResult
6983TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6984 DeclarationNameInfo DirName;
6985 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6986 D->getLocStart());
6987 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6988 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6989 return Res;
6990}
6991
6992template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006993StmtResult
6994TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6995 getDerived().getSema().StartOpenMPDSABlock(
6996 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
6997 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6998 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6999 return Res;
7000}
7001
7002template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007003StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7004 OMPParallelForDirective *D) {
7005 DeclarationNameInfo DirName;
7006 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7007 nullptr, D->getLocStart());
7008 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7009 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7010 return Res;
7011}
7012
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007013template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007014StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7015 OMPParallelForSimdDirective *D) {
7016 DeclarationNameInfo DirName;
7017 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7018 nullptr, D->getLocStart());
7019 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7020 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7021 return Res;
7022}
7023
7024template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007025StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7026 OMPParallelSectionsDirective *D) {
7027 DeclarationNameInfo DirName;
7028 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7029 nullptr, D->getLocStart());
7030 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7031 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7032 return Res;
7033}
7034
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007035template <typename Derived>
7036StmtResult
7037TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7038 DeclarationNameInfo DirName;
7039 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7040 D->getLocStart());
7041 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7042 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7043 return Res;
7044}
7045
Alexey Bataev68446b72014-07-18 07:47:19 +00007046template <typename Derived>
7047StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7048 OMPTaskyieldDirective *D) {
7049 DeclarationNameInfo DirName;
7050 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7051 D->getLocStart());
7052 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7053 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7054 return Res;
7055}
7056
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007057template <typename Derived>
7058StmtResult
7059TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7060 DeclarationNameInfo DirName;
7061 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7062 D->getLocStart());
7063 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7064 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7065 return Res;
7066}
7067
Alexey Bataev2df347a2014-07-18 10:17:07 +00007068template <typename Derived>
7069StmtResult
7070TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7071 DeclarationNameInfo DirName;
7072 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7073 D->getLocStart());
7074 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7075 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7076 return Res;
7077}
7078
Alexey Bataev6125da92014-07-21 11:26:11 +00007079template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007080StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7081 OMPTaskgroupDirective *D) {
7082 DeclarationNameInfo DirName;
7083 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7084 D->getLocStart());
7085 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7086 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7087 return Res;
7088}
7089
7090template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007091StmtResult
7092TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7093 DeclarationNameInfo DirName;
7094 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7095 D->getLocStart());
7096 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7097 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7098 return Res;
7099}
7100
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007101template <typename Derived>
7102StmtResult
7103TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7104 DeclarationNameInfo DirName;
7105 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7106 D->getLocStart());
7107 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7108 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7109 return Res;
7110}
7111
Alexey Bataev0162e452014-07-22 10:10:35 +00007112template <typename Derived>
7113StmtResult
7114TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7115 DeclarationNameInfo DirName;
7116 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7117 D->getLocStart());
7118 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7119 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7120 return Res;
7121}
7122
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007123template <typename Derived>
7124StmtResult
7125TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7126 DeclarationNameInfo DirName;
7127 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7128 D->getLocStart());
7129 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7130 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7131 return Res;
7132}
7133
Alexey Bataev13314bf2014-10-09 04:18:56 +00007134template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007135StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7136 OMPTargetDataDirective *D) {
7137 DeclarationNameInfo DirName;
7138 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7139 D->getLocStart());
7140 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7141 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7142 return Res;
7143}
7144
7145template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007146StmtResult
7147TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7148 DeclarationNameInfo DirName;
7149 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7150 D->getLocStart());
7151 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7152 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7153 return Res;
7154}
7155
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007156template <typename Derived>
7157StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7158 OMPCancellationPointDirective *D) {
7159 DeclarationNameInfo DirName;
7160 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7161 nullptr, D->getLocStart());
7162 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7163 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7164 return Res;
7165}
7166
Alexey Bataev80909872015-07-02 11:25:17 +00007167template <typename Derived>
7168StmtResult
7169TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7170 DeclarationNameInfo DirName;
7171 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7172 D->getLocStart());
7173 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7174 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7175 return Res;
7176}
7177
Alexander Musman64d33f12014-06-04 07:53:32 +00007178//===----------------------------------------------------------------------===//
7179// OpenMP clause transformation
7180//===----------------------------------------------------------------------===//
7181template <typename Derived>
7182OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007183 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7184 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007185 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007186 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007187 C->getLParenLoc(), C->getLocEnd());
7188}
7189
Alexander Musman64d33f12014-06-04 07:53:32 +00007190template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007191OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7192 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7193 if (Cond.isInvalid())
7194 return nullptr;
7195 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7196 C->getLParenLoc(), C->getLocEnd());
7197}
7198
7199template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007200OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007201TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7202 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7203 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007204 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007205 return getDerived().RebuildOMPNumThreadsClause(
7206 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007207}
7208
Alexey Bataev62c87d22014-03-21 04:51:18 +00007209template <typename Derived>
7210OMPClause *
7211TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7212 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7213 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007214 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007215 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007216 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007217}
7218
Alexander Musman8bd31e62014-05-27 15:12:19 +00007219template <typename Derived>
7220OMPClause *
7221TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7222 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7223 if (E.isInvalid())
7224 return 0;
7225 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007226 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007227}
7228
Alexander Musman64d33f12014-06-04 07:53:32 +00007229template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007230OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007231TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007232 return getDerived().RebuildOMPDefaultClause(
7233 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7234 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007235}
7236
Alexander Musman64d33f12014-06-04 07:53:32 +00007237template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007238OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007239TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007240 return getDerived().RebuildOMPProcBindClause(
7241 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7242 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007243}
7244
Alexander Musman64d33f12014-06-04 07:53:32 +00007245template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007246OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007247TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7248 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7249 if (E.isInvalid())
7250 return nullptr;
7251 return getDerived().RebuildOMPScheduleClause(
7252 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7253 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7254}
7255
7256template <typename Derived>
7257OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007258TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007259 ExprResult E;
7260 if (auto *Num = C->getNumForLoops()) {
7261 E = getDerived().TransformExpr(Num);
7262 if (E.isInvalid())
7263 return nullptr;
7264 }
7265 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7266 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007267}
7268
7269template <typename Derived>
7270OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007271TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7272 // No need to rebuild this clause, no template-dependent parameters.
7273 return C;
7274}
7275
7276template <typename Derived>
7277OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007278TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7279 // No need to rebuild this clause, no template-dependent parameters.
7280 return C;
7281}
7282
7283template <typename Derived>
7284OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007285TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7286 // No need to rebuild this clause, no template-dependent parameters.
7287 return C;
7288}
7289
7290template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007291OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7292 // No need to rebuild this clause, no template-dependent parameters.
7293 return C;
7294}
7295
7296template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007297OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7298 // No need to rebuild this clause, no template-dependent parameters.
7299 return C;
7300}
7301
7302template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007303OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007304TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7305 // No need to rebuild this clause, no template-dependent parameters.
7306 return C;
7307}
7308
7309template <typename Derived>
7310OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007311TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7312 // No need to rebuild this clause, no template-dependent parameters.
7313 return C;
7314}
7315
7316template <typename Derived>
7317OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007318TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7319 // No need to rebuild this clause, no template-dependent parameters.
7320 return C;
7321}
7322
7323template <typename Derived>
7324OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007325TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007326 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007327 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007328 for (auto *VE : C->varlists()) {
7329 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007330 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007331 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007332 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007333 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007334 return getDerived().RebuildOMPPrivateClause(
7335 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007336}
7337
Alexander Musman64d33f12014-06-04 07:53:32 +00007338template <typename Derived>
7339OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7340 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007341 llvm::SmallVector<Expr *, 16> Vars;
7342 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007343 for (auto *VE : C->varlists()) {
7344 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007345 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007346 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007347 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007348 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007349 return getDerived().RebuildOMPFirstprivateClause(
7350 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007351}
7352
Alexander Musman64d33f12014-06-04 07:53:32 +00007353template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007354OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007355TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7356 llvm::SmallVector<Expr *, 16> Vars;
7357 Vars.reserve(C->varlist_size());
7358 for (auto *VE : C->varlists()) {
7359 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7360 if (EVar.isInvalid())
7361 return nullptr;
7362 Vars.push_back(EVar.get());
7363 }
7364 return getDerived().RebuildOMPLastprivateClause(
7365 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7366}
7367
7368template <typename Derived>
7369OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007370TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7371 llvm::SmallVector<Expr *, 16> Vars;
7372 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007373 for (auto *VE : C->varlists()) {
7374 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007375 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007376 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007377 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007378 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007379 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7380 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007381}
7382
Alexander Musman64d33f12014-06-04 07:53:32 +00007383template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007384OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007385TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7386 llvm::SmallVector<Expr *, 16> Vars;
7387 Vars.reserve(C->varlist_size());
7388 for (auto *VE : C->varlists()) {
7389 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7390 if (EVar.isInvalid())
7391 return nullptr;
7392 Vars.push_back(EVar.get());
7393 }
7394 CXXScopeSpec ReductionIdScopeSpec;
7395 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7396
7397 DeclarationNameInfo NameInfo = C->getNameInfo();
7398 if (NameInfo.getName()) {
7399 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7400 if (!NameInfo.getName())
7401 return nullptr;
7402 }
7403 return getDerived().RebuildOMPReductionClause(
7404 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7405 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7406}
7407
7408template <typename Derived>
7409OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007410TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7411 llvm::SmallVector<Expr *, 16> Vars;
7412 Vars.reserve(C->varlist_size());
7413 for (auto *VE : C->varlists()) {
7414 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7415 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007416 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007417 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007418 }
7419 ExprResult Step = getDerived().TransformExpr(C->getStep());
7420 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007421 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007422 return getDerived().RebuildOMPLinearClause(Vars, Step.get(), C->getLocStart(),
7423 C->getLParenLoc(),
7424 C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007425}
7426
Alexander Musman64d33f12014-06-04 07:53:32 +00007427template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007428OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007429TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7430 llvm::SmallVector<Expr *, 16> Vars;
7431 Vars.reserve(C->varlist_size());
7432 for (auto *VE : C->varlists()) {
7433 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7434 if (EVar.isInvalid())
7435 return nullptr;
7436 Vars.push_back(EVar.get());
7437 }
7438 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7439 if (Alignment.isInvalid())
7440 return nullptr;
7441 return getDerived().RebuildOMPAlignedClause(
7442 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7443 C->getColonLoc(), C->getLocEnd());
7444}
7445
Alexander Musman64d33f12014-06-04 07:53:32 +00007446template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007447OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007448TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7449 llvm::SmallVector<Expr *, 16> Vars;
7450 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007451 for (auto *VE : C->varlists()) {
7452 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007453 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007454 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007455 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007456 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007457 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7458 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007459}
7460
Alexey Bataevbae9a792014-06-27 10:37:06 +00007461template <typename Derived>
7462OMPClause *
7463TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7464 llvm::SmallVector<Expr *, 16> Vars;
7465 Vars.reserve(C->varlist_size());
7466 for (auto *VE : C->varlists()) {
7467 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7468 if (EVar.isInvalid())
7469 return nullptr;
7470 Vars.push_back(EVar.get());
7471 }
7472 return getDerived().RebuildOMPCopyprivateClause(
7473 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7474}
7475
Alexey Bataev6125da92014-07-21 11:26:11 +00007476template <typename Derived>
7477OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7478 llvm::SmallVector<Expr *, 16> Vars;
7479 Vars.reserve(C->varlist_size());
7480 for (auto *VE : C->varlists()) {
7481 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7482 if (EVar.isInvalid())
7483 return nullptr;
7484 Vars.push_back(EVar.get());
7485 }
7486 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7487 C->getLParenLoc(), C->getLocEnd());
7488}
7489
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007490template <typename Derived>
7491OMPClause *
7492TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7493 llvm::SmallVector<Expr *, 16> Vars;
7494 Vars.reserve(C->varlist_size());
7495 for (auto *VE : C->varlists()) {
7496 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7497 if (EVar.isInvalid())
7498 return nullptr;
7499 Vars.push_back(EVar.get());
7500 }
7501 return getDerived().RebuildOMPDependClause(
7502 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7503 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7504}
7505
Michael Wonge710d542015-08-07 16:16:36 +00007506template <typename Derived>
7507OMPClause *
7508TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7509 ExprResult E = getDerived().TransformExpr(C->getDevice());
7510 if (E.isInvalid())
7511 return nullptr;
7512 return getDerived().RebuildOMPDeviceClause(
7513 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7514}
7515
Douglas Gregorebe10102009-08-20 07:17:43 +00007516//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007517// Expression transformation
7518//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007520ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007521TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007522 if (!E->isTypeDependent())
7523 return E;
7524
7525 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7526 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007527}
Mike Stump11289f42009-09-09 15:08:12 +00007528
7529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007531TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007532 NestedNameSpecifierLoc QualifierLoc;
7533 if (E->getQualifierLoc()) {
7534 QualifierLoc
7535 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7536 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007537 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007538 }
John McCallce546572009-12-08 09:08:17 +00007539
7540 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007541 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7542 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007543 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007545
John McCall815039a2010-08-17 21:27:17 +00007546 DeclarationNameInfo NameInfo = E->getNameInfo();
7547 if (NameInfo.getName()) {
7548 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7549 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007550 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007551 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007552
7553 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007554 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007555 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007556 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007557 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007558
7559 // Mark it referenced in the new context regardless.
7560 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007561 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007562
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007563 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007564 }
John McCallce546572009-12-08 09:08:17 +00007565
Craig Topperc3ec1492014-05-26 06:22:03 +00007566 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007567 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007568 TemplateArgs = &TransArgs;
7569 TransArgs.setLAngleLoc(E->getLAngleLoc());
7570 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007571 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7572 E->getNumTemplateArgs(),
7573 TransArgs))
7574 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007575 }
7576
Chad Rosier1dcde962012-08-08 18:46:20 +00007577 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007578 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007579}
Mike Stump11289f42009-09-09 15:08:12 +00007580
Douglas Gregora16548e2009-08-11 05:31:07 +00007581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007583TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007584 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007585}
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregora16548e2009-08-11 05:31:07 +00007587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007589TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007590 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007591}
Mike Stump11289f42009-09-09 15:08:12 +00007592
Douglas Gregora16548e2009-08-11 05:31:07 +00007593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007595TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007596 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007597}
Mike Stump11289f42009-09-09 15:08:12 +00007598
Douglas Gregora16548e2009-08-11 05:31:07 +00007599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007600ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007601TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007602 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007603}
Mike Stump11289f42009-09-09 15:08:12 +00007604
Douglas Gregora16548e2009-08-11 05:31:07 +00007605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007606ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007607TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007608 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007609}
7610
7611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007612ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007613TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007614 if (FunctionDecl *FD = E->getDirectCallee())
7615 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007616 return SemaRef.MaybeBindToTemporary(E);
7617}
7618
7619template<typename Derived>
7620ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007621TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7622 ExprResult ControllingExpr =
7623 getDerived().TransformExpr(E->getControllingExpr());
7624 if (ControllingExpr.isInvalid())
7625 return ExprError();
7626
Chris Lattner01cf8db2011-07-20 06:58:45 +00007627 SmallVector<Expr *, 4> AssocExprs;
7628 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007629 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7630 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7631 if (TS) {
7632 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7633 if (!AssocType)
7634 return ExprError();
7635 AssocTypes.push_back(AssocType);
7636 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007637 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007638 }
7639
7640 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7641 if (AssocExpr.isInvalid())
7642 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007643 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007644 }
7645
7646 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7647 E->getDefaultLoc(),
7648 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007649 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007650 AssocTypes,
7651 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007652}
7653
7654template<typename Derived>
7655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007656TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007657 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007659 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007662 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007663
John McCallb268a282010-08-23 23:25:46 +00007664 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007665 E->getRParen());
7666}
7667
Richard Smithdb2630f2012-10-21 03:28:35 +00007668/// \brief The operand of a unary address-of operator has special rules: it's
7669/// allowed to refer to a non-static member of a class even if there's no 'this'
7670/// object available.
7671template<typename Derived>
7672ExprResult
7673TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7674 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007675 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007676 else
7677 return getDerived().TransformExpr(E);
7678}
7679
Mike Stump11289f42009-09-09 15:08:12 +00007680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007682TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007683 ExprResult SubExpr;
7684 if (E->getOpcode() == UO_AddrOf)
7685 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7686 else
7687 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007688 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007690
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007692 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7695 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007696 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007697}
Mike Stump11289f42009-09-09 15:08:12 +00007698
Douglas Gregora16548e2009-08-11 05:31:07 +00007699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007700ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007701TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7702 // Transform the type.
7703 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7704 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007705 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007706
Douglas Gregor882211c2010-04-28 22:16:22 +00007707 // Transform all of the components into components similar to what the
7708 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007709 // FIXME: It would be slightly more efficient in the non-dependent case to
7710 // just map FieldDecls, rather than requiring the rebuilder to look for
7711 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007712 // template code that we don't care.
7713 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007714 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007715 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007716 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007717 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7718 const Node &ON = E->getComponent(I);
7719 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007720 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007721 Comp.LocStart = ON.getSourceRange().getBegin();
7722 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007723 switch (ON.getKind()) {
7724 case Node::Array: {
7725 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007726 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007727 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007728 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007729
Douglas Gregor882211c2010-04-28 22:16:22 +00007730 ExprChanged = ExprChanged || Index.get() != FromIndex;
7731 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007732 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007733 break;
7734 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007735
Douglas Gregor882211c2010-04-28 22:16:22 +00007736 case Node::Field:
7737 case Node::Identifier:
7738 Comp.isBrackets = false;
7739 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007740 if (!Comp.U.IdentInfo)
7741 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007742
Douglas Gregor882211c2010-04-28 22:16:22 +00007743 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007744
Douglas Gregord1702062010-04-29 00:18:15 +00007745 case Node::Base:
7746 // Will be recomputed during the rebuild.
7747 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007749
Douglas Gregor882211c2010-04-28 22:16:22 +00007750 Components.push_back(Comp);
7751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007752
Douglas Gregor882211c2010-04-28 22:16:22 +00007753 // If nothing changed, retain the existing expression.
7754 if (!getDerived().AlwaysRebuild() &&
7755 Type == E->getTypeSourceInfo() &&
7756 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007757 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007758
Douglas Gregor882211c2010-04-28 22:16:22 +00007759 // Build a new offsetof expression.
7760 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7761 Components.data(), Components.size(),
7762 E->getRParenLoc());
7763}
7764
7765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007766ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007767TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7768 assert(getDerived().AlreadyTransformed(E->getType()) &&
7769 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007770 return E;
John McCall8d69a212010-11-15 23:31:06 +00007771}
7772
7773template<typename Derived>
7774ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007775TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7776 return E;
7777}
7778
7779template<typename Derived>
7780ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007781TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007782 // Rebuild the syntactic form. The original syntactic form has
7783 // opaque-value expressions in it, so strip those away and rebuild
7784 // the result. This is a really awful way of doing this, but the
7785 // better solution (rebuilding the semantic expressions and
7786 // rebinding OVEs as necessary) doesn't work; we'd need
7787 // TreeTransform to not strip away implicit conversions.
7788 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7789 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007790 if (result.isInvalid()) return ExprError();
7791
7792 // If that gives us a pseudo-object result back, the pseudo-object
7793 // expression must have been an lvalue-to-rvalue conversion which we
7794 // should reapply.
7795 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007796 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007797
7798 return result;
7799}
7800
7801template<typename Derived>
7802ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007803TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7804 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007805 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007806 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007807
John McCallbcd03502009-12-07 02:54:59 +00007808 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007809 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007811
John McCall4c98fd82009-11-04 07:28:41 +00007812 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007813 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007814
Peter Collingbournee190dee2011-03-11 19:24:49 +00007815 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7816 E->getKind(),
7817 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007818 }
Mike Stump11289f42009-09-09 15:08:12 +00007819
Eli Friedmane4f22df2012-02-29 04:03:55 +00007820 // C++0x [expr.sizeof]p1:
7821 // The operand is either an expression, which is an unevaluated operand
7822 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007823 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7824 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007825
Reid Kleckner32506ed2014-06-12 23:03:48 +00007826 // Try to recover if we have something like sizeof(T::X) where X is a type.
7827 // Notably, there must be *exactly* one set of parens if X is a type.
7828 TypeSourceInfo *RecoveryTSI = nullptr;
7829 ExprResult SubExpr;
7830 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7831 if (auto *DRE =
7832 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7833 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7834 PE, DRE, false, &RecoveryTSI);
7835 else
7836 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7837
7838 if (RecoveryTSI) {
7839 return getDerived().RebuildUnaryExprOrTypeTrait(
7840 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7841 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007843
Eli Friedmane4f22df2012-02-29 04:03:55 +00007844 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007845 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007846
Peter Collingbournee190dee2011-03-11 19:24:49 +00007847 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7848 E->getOperatorLoc(),
7849 E->getKind(),
7850 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007851}
Mike Stump11289f42009-09-09 15:08:12 +00007852
Douglas Gregora16548e2009-08-11 05:31:07 +00007853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007855TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007856 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007857 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007858 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007859
John McCalldadc5752010-08-24 06:29:42 +00007860 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007861 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007863
7864
Douglas Gregora16548e2009-08-11 05:31:07 +00007865 if (!getDerived().AlwaysRebuild() &&
7866 LHS.get() == E->getLHS() &&
7867 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007868 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007869
John McCallb268a282010-08-23 23:25:46 +00007870 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007871 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007872 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 E->getRBracketLoc());
7874}
Mike Stump11289f42009-09-09 15:08:12 +00007875
7876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007878TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007879 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007880 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007882 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007883
7884 // Transform arguments.
7885 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007886 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007887 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007888 &ArgChanged))
7889 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007890
Douglas Gregora16548e2009-08-11 05:31:07 +00007891 if (!getDerived().AlwaysRebuild() &&
7892 Callee.get() == E->getCallee() &&
7893 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007894 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007895
Douglas Gregora16548e2009-08-11 05:31:07 +00007896 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007897 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007899 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007900 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 E->getRParenLoc());
7902}
Mike Stump11289f42009-09-09 15:08:12 +00007903
7904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007906TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007907 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007908 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregorea972d32011-02-28 21:54:11 +00007911 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007912 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007913 QualifierLoc
7914 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007915
Douglas Gregorea972d32011-02-28 21:54:11 +00007916 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007917 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007918 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007919 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007920
Eli Friedman2cfcef62009-12-04 06:40:45 +00007921 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007922 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7923 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007926
John McCall16df1e52010-03-30 21:47:33 +00007927 NamedDecl *FoundDecl = E->getFoundDecl();
7928 if (FoundDecl == E->getMemberDecl()) {
7929 FoundDecl = Member;
7930 } else {
7931 FoundDecl = cast_or_null<NamedDecl>(
7932 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7933 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007934 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007935 }
7936
Douglas Gregora16548e2009-08-11 05:31:07 +00007937 if (!getDerived().AlwaysRebuild() &&
7938 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007939 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007940 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007941 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007942 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007943
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007944 // Mark it referenced in the new context regardless.
7945 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007946 SemaRef.MarkMemberReferenced(E);
7947
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007948 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007949 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007950
John McCall6b51f282009-11-23 01:53:49 +00007951 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007952 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007953 TransArgs.setLAngleLoc(E->getLAngleLoc());
7954 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007955 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7956 E->getNumTemplateArgs(),
7957 TransArgs))
7958 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007960
Douglas Gregora16548e2009-08-11 05:31:07 +00007961 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007962 SourceLocation FakeOperatorLoc =
7963 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007964
John McCall38836f02010-01-15 08:34:02 +00007965 // FIXME: to do this check properly, we will need to preserve the
7966 // first-qualifier-in-scope here, just in case we had a dependent
7967 // base (and therefore couldn't do the check) and a
7968 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007969 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007970
John McCallb268a282010-08-23 23:25:46 +00007971 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007972 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007973 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007974 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007975 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007976 Member,
John McCall16df1e52010-03-30 21:47:33 +00007977 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007978 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007979 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007980 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007981}
Mike Stump11289f42009-09-09 15:08:12 +00007982
Douglas Gregora16548e2009-08-11 05:31:07 +00007983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007984ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007985TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007986 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007987 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007988 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007989
John McCalldadc5752010-08-24 06:29:42 +00007990 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007991 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007993
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 if (!getDerived().AlwaysRebuild() &&
7995 LHS.get() == E->getLHS() &&
7996 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007997 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007998
Lang Hames5de91cc2012-10-02 04:45:10 +00007999 Sema::FPContractStateRAII FPContractState(getSema());
8000 getSema().FPFeatures.fp_contract = E->isFPContractable();
8001
Douglas Gregora16548e2009-08-11 05:31:07 +00008002 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008003 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008004}
8005
Mike Stump11289f42009-09-09 15:08:12 +00008006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008007ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008008TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008009 CompoundAssignOperator *E) {
8010 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008011}
Mike Stump11289f42009-09-09 15:08:12 +00008012
Douglas Gregora16548e2009-08-11 05:31:07 +00008013template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008014ExprResult TreeTransform<Derived>::
8015TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8016 // Just rebuild the common and RHS expressions and see whether we
8017 // get any changes.
8018
8019 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8020 if (commonExpr.isInvalid())
8021 return ExprError();
8022
8023 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8024 if (rhs.isInvalid())
8025 return ExprError();
8026
8027 if (!getDerived().AlwaysRebuild() &&
8028 commonExpr.get() == e->getCommon() &&
8029 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008030 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008031
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008032 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008033 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008034 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008035 e->getColonLoc(),
8036 rhs.get());
8037}
8038
8039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008040ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008041TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008042 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008043 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008044 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008045
John McCalldadc5752010-08-24 06:29:42 +00008046 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008047 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008048 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008049
John McCalldadc5752010-08-24 06:29:42 +00008050 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008051 if (RHS.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() &&
8055 Cond.get() == E->getCond() &&
8056 LHS.get() == E->getLHS() &&
8057 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008058 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008059
John McCallb268a282010-08-23 23:25:46 +00008060 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008061 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008062 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008063 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008064 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008065}
Mike Stump11289f42009-09-09 15:08:12 +00008066
8067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008069TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008070 // Implicit casts are eliminated during transformation, since they
8071 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008072 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008073}
Mike Stump11289f42009-09-09 15:08:12 +00008074
Douglas Gregora16548e2009-08-11 05:31:07 +00008075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008077TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008078 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8079 if (!Type)
8080 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008081
John McCalldadc5752010-08-24 06:29:42 +00008082 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008083 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008084 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008086
Douglas Gregora16548e2009-08-11 05:31:07 +00008087 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008088 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008089 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008090 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008091
John McCall97513962010-01-15 18:39:57 +00008092 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008093 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008094 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008095 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008096}
Mike Stump11289f42009-09-09 15:08:12 +00008097
Douglas Gregora16548e2009-08-11 05:31:07 +00008098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008100TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008101 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8102 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8103 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008105
John McCalldadc5752010-08-24 06:29:42 +00008106 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008107 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008109
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008111 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008112 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008113 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008114
John McCall5d7aa7f2010-01-19 22:33:45 +00008115 // Note: the expression type doesn't necessarily match the
8116 // type-as-written, but that's okay, because it should always be
8117 // derivable from the initializer.
8118
John McCalle15bbff2010-01-18 19:35:47 +00008119 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008120 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008121 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008122}
Mike Stump11289f42009-09-09 15:08:12 +00008123
Douglas Gregora16548e2009-08-11 05:31:07 +00008124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008126TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008127 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008128 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008130
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 if (!getDerived().AlwaysRebuild() &&
8132 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008133 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008134
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008136 SourceLocation FakeOperatorLoc =
8137 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008138 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 E->getAccessorLoc(),
8140 E->getAccessor());
8141}
Mike Stump11289f42009-09-09 15:08:12 +00008142
Douglas Gregora16548e2009-08-11 05:31:07 +00008143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008144ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008145TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008146 if (InitListExpr *Syntactic = E->getSyntacticForm())
8147 E = Syntactic;
8148
Douglas Gregora16548e2009-08-11 05:31:07 +00008149 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008150
Benjamin Kramerf0623432012-08-23 22:51:59 +00008151 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008152 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008153 Inits, &InitChanged))
8154 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008155
Richard Smith520449d2015-02-05 06:15:50 +00008156 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8157 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8158 // in some cases. We can't reuse it in general, because the syntactic and
8159 // semantic forms are linked, and we can't know that semantic form will
8160 // match even if the syntactic form does.
8161 }
Mike Stump11289f42009-09-09 15:08:12 +00008162
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008163 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008164 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008165}
Mike Stump11289f42009-09-09 15:08:12 +00008166
Douglas Gregora16548e2009-08-11 05:31:07 +00008167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008168ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008169TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008171
Douglas Gregorebe10102009-08-20 07:17:43 +00008172 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008173 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008174 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008176
Douglas Gregorebe10102009-08-20 07:17:43 +00008177 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008178 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008179 bool ExprChanged = false;
8180 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8181 DEnd = E->designators_end();
8182 D != DEnd; ++D) {
8183 if (D->isFieldDesignator()) {
8184 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8185 D->getDotLoc(),
8186 D->getFieldLoc()));
8187 continue;
8188 }
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregora16548e2009-08-11 05:31:07 +00008190 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008191 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008192 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008194
8195 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008196 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008197
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008199 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 continue;
8201 }
Mike Stump11289f42009-09-09 15:08:12 +00008202
Douglas Gregora16548e2009-08-11 05:31:07 +00008203 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008204 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8206 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008208
John McCalldadc5752010-08-24 06:29:42 +00008209 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008210 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008211 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008212
8213 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008214 End.get(),
8215 D->getLBracketLoc(),
8216 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008217
Douglas Gregora16548e2009-08-11 05:31:07 +00008218 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8219 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008220
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008221 ArrayExprs.push_back(Start.get());
8222 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 }
Mike Stump11289f42009-09-09 15:08:12 +00008224
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 if (!getDerived().AlwaysRebuild() &&
8226 Init.get() == E->getInit() &&
8227 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008228 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008229
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008230 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008231 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008232 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008233}
Mike Stump11289f42009-09-09 15:08:12 +00008234
Yunzhong Gaocb779302015-06-10 00:27:52 +00008235// Seems that if TransformInitListExpr() only works on the syntactic form of an
8236// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8237template<typename Derived>
8238ExprResult
8239TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8240 DesignatedInitUpdateExpr *E) {
8241 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8242 "initializer");
8243 return ExprError();
8244}
8245
8246template<typename Derived>
8247ExprResult
8248TreeTransform<Derived>::TransformNoInitExpr(
8249 NoInitExpr *E) {
8250 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8251 return ExprError();
8252}
8253
Douglas Gregora16548e2009-08-11 05:31:07 +00008254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008255ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008256TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008257 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008258 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008259
Douglas Gregor3da3c062009-10-28 00:29:27 +00008260 // FIXME: Will we ever have proper type location here? Will we actually
8261 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 QualType T = getDerived().TransformType(E->getType());
8263 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008264 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008265
Douglas Gregora16548e2009-08-11 05:31:07 +00008266 if (!getDerived().AlwaysRebuild() &&
8267 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008268 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008269
Douglas Gregora16548e2009-08-11 05:31:07 +00008270 return getDerived().RebuildImplicitValueInitExpr(T);
8271}
Mike Stump11289f42009-09-09 15:08:12 +00008272
Douglas Gregora16548e2009-08-11 05:31:07 +00008273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008275TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008276 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8277 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008278 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008279
John McCalldadc5752010-08-24 06:29:42 +00008280 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008281 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008283
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008285 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008287 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008288
John McCallb268a282010-08-23 23:25:46 +00008289 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008290 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008291}
8292
8293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008295TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008297 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008298 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8299 &ArgumentChanged))
8300 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008301
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008303 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 E->getRParenLoc());
8305}
Mike Stump11289f42009-09-09 15:08:12 +00008306
Douglas Gregora16548e2009-08-11 05:31:07 +00008307/// \brief Transform an address-of-label expression.
8308///
8309/// By default, the transformation of an address-of-label expression always
8310/// rebuilds the expression, so that the label identifier can be resolved to
8311/// the corresponding label statement by semantic analysis.
8312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008314TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008315 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8316 E->getLabel());
8317 if (!LD)
8318 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008319
Douglas Gregora16548e2009-08-11 05:31:07 +00008320 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008321 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008322}
Mike Stump11289f42009-09-09 15:08:12 +00008323
8324template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008326TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008327 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008328 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008329 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008330 if (SubStmt.isInvalid()) {
8331 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008332 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008333 }
Mike Stump11289f42009-09-09 15:08:12 +00008334
Douglas Gregora16548e2009-08-11 05:31:07 +00008335 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008336 SubStmt.get() == E->getSubStmt()) {
8337 // Calling this an 'error' is unintuitive, but it does the right thing.
8338 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008339 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008340 }
Mike Stump11289f42009-09-09 15:08:12 +00008341
8342 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008343 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008344 E->getRParenLoc());
8345}
Mike Stump11289f42009-09-09 15:08:12 +00008346
Douglas Gregora16548e2009-08-11 05:31:07 +00008347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008349TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008350 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008351 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
John McCalldadc5752010-08-24 06:29:42 +00008354 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008355 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008356 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008357
John McCalldadc5752010-08-24 06:29:42 +00008358 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008359 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008360 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008361
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 if (!getDerived().AlwaysRebuild() &&
8363 Cond.get() == E->getCond() &&
8364 LHS.get() == E->getLHS() &&
8365 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008366 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008367
Douglas Gregora16548e2009-08-11 05:31:07 +00008368 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008369 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 E->getRParenLoc());
8371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008375TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008376 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008377}
8378
8379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008381TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008382 switch (E->getOperator()) {
8383 case OO_New:
8384 case OO_Delete:
8385 case OO_Array_New:
8386 case OO_Array_Delete:
8387 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008388
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008389 case OO_Call: {
8390 // This is a call to an object's operator().
8391 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8392
8393 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008394 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008395 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008396 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008397
8398 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008399 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8400 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008401
8402 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008403 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008404 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008405 Args))
8406 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008407
John McCallb268a282010-08-23 23:25:46 +00008408 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008409 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008410 E->getLocEnd());
8411 }
8412
8413#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8414 case OO_##Name:
8415#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8416#include "clang/Basic/OperatorKinds.def"
8417 case OO_Subscript:
8418 // Handled below.
8419 break;
8420
8421 case OO_Conditional:
8422 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008423
8424 case OO_None:
8425 case NUM_OVERLOADED_OPERATORS:
8426 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008427 }
8428
John McCalldadc5752010-08-24 06:29:42 +00008429 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008431 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008432
Richard Smithdb2630f2012-10-21 03:28:35 +00008433 ExprResult First;
8434 if (E->getOperator() == OO_Amp)
8435 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8436 else
8437 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008438 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008439 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008440
John McCalldadc5752010-08-24 06:29:42 +00008441 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008442 if (E->getNumArgs() == 2) {
8443 Second = getDerived().TransformExpr(E->getArg(1));
8444 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008445 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008446 }
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 if (!getDerived().AlwaysRebuild() &&
8449 Callee.get() == E->getCallee() &&
8450 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008451 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008452 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008453
Lang Hames5de91cc2012-10-02 04:45:10 +00008454 Sema::FPContractStateRAII FPContractState(getSema());
8455 getSema().FPFeatures.fp_contract = E->isFPContractable();
8456
Douglas Gregora16548e2009-08-11 05:31:07 +00008457 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8458 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008459 Callee.get(),
8460 First.get(),
8461 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008462}
Mike Stump11289f42009-09-09 15:08:12 +00008463
Douglas Gregora16548e2009-08-11 05:31:07 +00008464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008466TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8467 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008468}
Mike Stump11289f42009-09-09 15:08:12 +00008469
Douglas Gregora16548e2009-08-11 05:31:07 +00008470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008471ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008472TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8473 // Transform the callee.
8474 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8475 if (Callee.isInvalid())
8476 return ExprError();
8477
8478 // Transform exec config.
8479 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8480 if (EC.isInvalid())
8481 return ExprError();
8482
8483 // Transform arguments.
8484 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008485 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008486 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008487 &ArgChanged))
8488 return ExprError();
8489
8490 if (!getDerived().AlwaysRebuild() &&
8491 Callee.get() == E->getCallee() &&
8492 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008493 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008494
8495 // FIXME: Wrong source location information for the '('.
8496 SourceLocation FakeLParenLoc
8497 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8498 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008499 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008500 E->getRParenLoc(), EC.get());
8501}
8502
8503template<typename Derived>
8504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008505TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008506 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8507 if (!Type)
8508 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
John McCalldadc5752010-08-24 06:29:42 +00008510 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008511 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008512 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008514
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008516 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008517 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008518 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008519 return getDerived().RebuildCXXNamedCastExpr(
8520 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8521 Type, E->getAngleBrackets().getEnd(),
8522 // FIXME. this should be '(' location
8523 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008524}
Mike Stump11289f42009-09-09 15:08:12 +00008525
Douglas Gregora16548e2009-08-11 05:31:07 +00008526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008527ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008528TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8529 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008530}
Mike Stump11289f42009-09-09 15:08:12 +00008531
8532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008534TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8535 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008536}
8537
Douglas Gregora16548e2009-08-11 05:31:07 +00008538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008539ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008540TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008541 CXXReinterpretCastExpr *E) {
8542 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008543}
Mike Stump11289f42009-09-09 15:08:12 +00008544
Douglas Gregora16548e2009-08-11 05:31:07 +00008545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008547TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8548 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008549}
Mike Stump11289f42009-09-09 15:08:12 +00008550
Douglas Gregora16548e2009-08-11 05:31:07 +00008551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008552ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008553TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008554 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008555 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8556 if (!Type)
8557 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008558
John McCalldadc5752010-08-24 06:29:42 +00008559 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008560 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008561 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008563
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008565 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008566 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008567 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008568
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008569 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008570 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008571 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008572 E->getRParenLoc());
8573}
Mike Stump11289f42009-09-09 15:08:12 +00008574
Douglas Gregora16548e2009-08-11 05:31:07 +00008575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008577TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008579 TypeSourceInfo *TInfo
8580 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8581 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008583
Douglas Gregora16548e2009-08-11 05:31:07 +00008584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008585 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008586 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008587
Douglas Gregor9da64192010-04-26 22:37:10 +00008588 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8589 E->getLocStart(),
8590 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008591 E->getLocEnd());
8592 }
Mike Stump11289f42009-09-09 15:08:12 +00008593
Eli Friedman456f0182012-01-20 01:26:23 +00008594 // We don't know whether the subexpression is potentially evaluated until
8595 // after we perform semantic analysis. We speculatively assume it is
8596 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008597 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8599 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008600
John McCalldadc5752010-08-24 06:29:42 +00008601 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008602 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008604
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 if (!getDerived().AlwaysRebuild() &&
8606 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008607 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008608
Douglas Gregor9da64192010-04-26 22:37:10 +00008609 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8610 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008611 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008612 E->getLocEnd());
8613}
8614
8615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008616ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008617TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8618 if (E->isTypeOperand()) {
8619 TypeSourceInfo *TInfo
8620 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8621 if (!TInfo)
8622 return ExprError();
8623
8624 if (!getDerived().AlwaysRebuild() &&
8625 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008626 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008627
Douglas Gregor69735112011-03-06 17:40:41 +00008628 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008629 E->getLocStart(),
8630 TInfo,
8631 E->getLocEnd());
8632 }
8633
Francois Pichet9f4f2072010-09-08 12:20:18 +00008634 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8635
8636 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8637 if (SubExpr.isInvalid())
8638 return ExprError();
8639
8640 if (!getDerived().AlwaysRebuild() &&
8641 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008642 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008643
8644 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8645 E->getLocStart(),
8646 SubExpr.get(),
8647 E->getLocEnd());
8648}
8649
8650template<typename Derived>
8651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008652TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008653 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008654}
Mike Stump11289f42009-09-09 15:08:12 +00008655
Douglas Gregora16548e2009-08-11 05:31:07 +00008656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008657ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008658TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008659 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008660 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008661}
Mike Stump11289f42009-09-09 15:08:12 +00008662
Douglas Gregora16548e2009-08-11 05:31:07 +00008663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008666 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008667
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008668 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8669 // Make sure that we capture 'this'.
8670 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008671 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008673
Douglas Gregorb15af892010-01-07 23:12:05 +00008674 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008675}
Mike Stump11289f42009-09-09 15:08:12 +00008676
Douglas Gregora16548e2009-08-11 05:31:07 +00008677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008679TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008680 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008681 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008682 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008683
Douglas Gregora16548e2009-08-11 05:31:07 +00008684 if (!getDerived().AlwaysRebuild() &&
8685 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008686 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008687
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008688 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8689 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008690}
Mike Stump11289f42009-09-09 15:08:12 +00008691
Douglas Gregora16548e2009-08-11 05:31:07 +00008692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008693ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008694TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008695 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008696 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8697 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008698 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008700
Chandler Carruth794da4c2010-02-08 06:42:49 +00008701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008702 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008703 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008704
Douglas Gregor033f6752009-12-23 23:03:06 +00008705 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008706}
Mike Stump11289f42009-09-09 15:08:12 +00008707
Douglas Gregora16548e2009-08-11 05:31:07 +00008708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008709ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008710TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8711 FieldDecl *Field
8712 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8713 E->getField()));
8714 if (!Field)
8715 return ExprError();
8716
8717 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008718 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008719
8720 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8721}
8722
8723template<typename Derived>
8724ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008725TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8726 CXXScalarValueInitExpr *E) {
8727 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8728 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008729 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008730
Douglas Gregora16548e2009-08-11 05:31:07 +00008731 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008732 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008733 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008734
Chad Rosier1dcde962012-08-08 18:46:20 +00008735 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008736 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008737 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008738}
Mike Stump11289f42009-09-09 15:08:12 +00008739
Douglas Gregora16548e2009-08-11 05:31:07 +00008740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008742TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008743 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008744 TypeSourceInfo *AllocTypeInfo
8745 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8746 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008748
Douglas Gregora16548e2009-08-11 05:31:07 +00008749 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008750 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008751 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008753
Douglas Gregora16548e2009-08-11 05:31:07 +00008754 // Transform the placement arguments (if any).
8755 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008756 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008757 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008758 E->getNumPlacementArgs(), true,
8759 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008761
Sebastian Redl6047f072012-02-16 12:22:20 +00008762 // Transform the initializer (if any).
8763 Expr *OldInit = E->getInitializer();
8764 ExprResult NewInit;
8765 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008766 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008767 if (NewInit.isInvalid())
8768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008769
Sebastian Redl6047f072012-02-16 12:22:20 +00008770 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008771 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008772 if (E->getOperatorNew()) {
8773 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008774 getDerived().TransformDecl(E->getLocStart(),
8775 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008776 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008777 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008778 }
8779
Craig Topperc3ec1492014-05-26 06:22:03 +00008780 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008781 if (E->getOperatorDelete()) {
8782 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008783 getDerived().TransformDecl(E->getLocStart(),
8784 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008785 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008786 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008788
Douglas Gregora16548e2009-08-11 05:31:07 +00008789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008790 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008791 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008792 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008793 OperatorNew == E->getOperatorNew() &&
8794 OperatorDelete == E->getOperatorDelete() &&
8795 !ArgumentChanged) {
8796 // Mark any declarations we need as referenced.
8797 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008798 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008799 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008800 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008801 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008802
Sebastian Redl6047f072012-02-16 12:22:20 +00008803 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008804 QualType ElementType
8805 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8806 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8807 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8808 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008809 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008810 }
8811 }
8812 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008813
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008814 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008815 }
Mike Stump11289f42009-09-09 15:08:12 +00008816
Douglas Gregor0744ef62010-09-07 21:49:58 +00008817 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008818 if (!ArraySize.get()) {
8819 // If no array size was specified, but the new expression was
8820 // instantiated with an array type (e.g., "new T" where T is
8821 // instantiated with "int[4]"), extract the outer bound from the
8822 // array type as our array size. We do this with constant and
8823 // dependently-sized array types.
8824 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8825 if (!ArrayT) {
8826 // Do nothing
8827 } else if (const ConstantArrayType *ConsArrayT
8828 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008829 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8830 SemaRef.Context.getSizeType(),
8831 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008832 AllocType = ConsArrayT->getElementType();
8833 } else if (const DependentSizedArrayType *DepArrayT
8834 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8835 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008836 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008837 AllocType = DepArrayT->getElementType();
8838 }
8839 }
8840 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8843 E->isGlobalNew(),
8844 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008845 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008846 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008847 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008849 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008850 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008851 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008852 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008853}
Mike Stump11289f42009-09-09 15:08:12 +00008854
Douglas Gregora16548e2009-08-11 05:31:07 +00008855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008856ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008857TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008858 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008859 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008861
Douglas Gregord2d9da02010-02-26 00:38:10 +00008862 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008863 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 if (E->getOperatorDelete()) {
8865 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008866 getDerived().TransformDecl(E->getLocStart(),
8867 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008868 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008869 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008871
Douglas Gregora16548e2009-08-11 05:31:07 +00008872 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008873 Operand.get() == E->getArgument() &&
8874 OperatorDelete == E->getOperatorDelete()) {
8875 // Mark any declarations we need as referenced.
8876 // FIXME: instantiation-specific.
8877 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008878 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008879
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008880 if (!E->getArgument()->isTypeDependent()) {
8881 QualType Destroyed = SemaRef.Context.getBaseElementType(
8882 E->getDestroyedType());
8883 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8884 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008885 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008886 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008887 }
8888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008889
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008890 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008891 }
Mike Stump11289f42009-09-09 15:08:12 +00008892
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8894 E->isGlobalDelete(),
8895 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008896 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008897}
Mike Stump11289f42009-09-09 15:08:12 +00008898
Douglas Gregora16548e2009-08-11 05:31:07 +00008899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008900ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008901TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008902 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008903 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008904 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008906
John McCallba7bf592010-08-24 05:47:05 +00008907 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008908 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008909 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008910 E->getOperatorLoc(),
8911 E->isArrow()? tok::arrow : tok::period,
8912 ObjectTypePtr,
8913 MayBePseudoDestructor);
8914 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008915 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008916
John McCallba7bf592010-08-24 05:47:05 +00008917 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008918 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8919 if (QualifierLoc) {
8920 QualifierLoc
8921 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8922 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008923 return ExprError();
8924 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008925 CXXScopeSpec SS;
8926 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008927
Douglas Gregor678f90d2010-02-25 01:56:36 +00008928 PseudoDestructorTypeStorage Destroyed;
8929 if (E->getDestroyedTypeInfo()) {
8930 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008931 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008932 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008933 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008934 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008935 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008936 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008937 // We aren't likely to be able to resolve the identifier down to a type
8938 // now anyway, so just retain the identifier.
8939 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8940 E->getDestroyedTypeLoc());
8941 } else {
8942 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008943 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008944 *E->getDestroyedTypeIdentifier(),
8945 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008946 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008947 SS, ObjectTypePtr,
8948 false);
8949 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008951
Douglas Gregor678f90d2010-02-25 01:56:36 +00008952 Destroyed
8953 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8954 E->getDestroyedTypeLoc());
8955 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008956
Craig Topperc3ec1492014-05-26 06:22:03 +00008957 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008958 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008959 CXXScopeSpec EmptySS;
8960 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008961 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008962 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008963 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008965
John McCallb268a282010-08-23 23:25:46 +00008966 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008967 E->getOperatorLoc(),
8968 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008969 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008970 ScopeTypeInfo,
8971 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008972 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008973 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008974}
Mike Stump11289f42009-09-09 15:08:12 +00008975
Douglas Gregorad8a3362009-09-04 17:36:40 +00008976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008977ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008978TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008979 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008980 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8981 Sema::LookupOrdinaryName);
8982
8983 // Transform all the decls.
8984 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8985 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008986 NamedDecl *InstD = static_cast<NamedDecl*>(
8987 getDerived().TransformDecl(Old->getNameLoc(),
8988 *I));
John McCall84d87672009-12-10 09:41:52 +00008989 if (!InstD) {
8990 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8991 // This can happen because of dependent hiding.
8992 if (isa<UsingShadowDecl>(*I))
8993 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008994 else {
8995 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008996 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00008997 }
John McCall84d87672009-12-10 09:41:52 +00008998 }
John McCalle66edc12009-11-24 19:00:30 +00008999
9000 // Expand using declarations.
9001 if (isa<UsingDecl>(InstD)) {
9002 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009003 for (auto *I : UD->shadows())
9004 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009005 continue;
9006 }
9007
9008 R.addDecl(InstD);
9009 }
9010
9011 // Resolve a kind, but don't do any further analysis. If it's
9012 // ambiguous, the callee needs to deal with it.
9013 R.resolveKind();
9014
9015 // Rebuild the nested-name qualifier, if present.
9016 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009017 if (Old->getQualifierLoc()) {
9018 NestedNameSpecifierLoc QualifierLoc
9019 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9020 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009021 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009022
Douglas Gregor0da1d432011-02-28 20:01:57 +00009023 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009024 }
9025
Douglas Gregor9262f472010-04-27 18:19:34 +00009026 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009027 CXXRecordDecl *NamingClass
9028 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9029 Old->getNameLoc(),
9030 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009031 if (!NamingClass) {
9032 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009033 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009035
Douglas Gregorda7be082010-04-27 16:10:10 +00009036 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009037 }
9038
Abramo Bagnara7945c982012-01-27 09:46:47 +00009039 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9040
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009041 // If we have neither explicit template arguments, nor the template keyword,
9042 // it's a normal declaration name.
9043 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009044 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9045
9046 // If we have template arguments, rebuild them, then rebuild the
9047 // templateid expression.
9048 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009049 if (Old->hasExplicitTemplateArgs() &&
9050 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009051 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009052 TransArgs)) {
9053 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009054 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009055 }
John McCalle66edc12009-11-24 19:00:30 +00009056
Abramo Bagnara7945c982012-01-27 09:46:47 +00009057 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009058 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009059}
Mike Stump11289f42009-09-09 15:08:12 +00009060
Douglas Gregora16548e2009-08-11 05:31:07 +00009061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009062ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009063TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9064 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009065 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009066 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9067 TypeSourceInfo *From = E->getArg(I);
9068 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009069 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009070 TypeLocBuilder TLB;
9071 TLB.reserve(FromTL.getFullDataSize());
9072 QualType To = getDerived().TransformType(TLB, FromTL);
9073 if (To.isNull())
9074 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009075
Douglas Gregor29c42f22012-02-24 07:38:34 +00009076 if (To == From->getType())
9077 Args.push_back(From);
9078 else {
9079 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9080 ArgChanged = true;
9081 }
9082 continue;
9083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009084
Douglas Gregor29c42f22012-02-24 07:38:34 +00009085 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009086
Douglas Gregor29c42f22012-02-24 07:38:34 +00009087 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009088 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009089 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9090 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9091 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009092
Douglas Gregor29c42f22012-02-24 07:38:34 +00009093 // Determine whether the set of unexpanded parameter packs can and should
9094 // be expanded.
9095 bool Expand = true;
9096 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009097 Optional<unsigned> OrigNumExpansions =
9098 ExpansionTL.getTypePtr()->getNumExpansions();
9099 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009100 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9101 PatternTL.getSourceRange(),
9102 Unexpanded,
9103 Expand, RetainExpansion,
9104 NumExpansions))
9105 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009106
Douglas Gregor29c42f22012-02-24 07:38:34 +00009107 if (!Expand) {
9108 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009109 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009110 // expansion.
9111 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregor29c42f22012-02-24 07:38:34 +00009113 TypeLocBuilder TLB;
9114 TLB.reserve(From->getTypeLoc().getFullDataSize());
9115
9116 QualType To = getDerived().TransformType(TLB, PatternTL);
9117 if (To.isNull())
9118 return ExprError();
9119
Chad Rosier1dcde962012-08-08 18:46:20 +00009120 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009121 PatternTL.getSourceRange(),
9122 ExpansionTL.getEllipsisLoc(),
9123 NumExpansions);
9124 if (To.isNull())
9125 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009126
Douglas Gregor29c42f22012-02-24 07:38:34 +00009127 PackExpansionTypeLoc ToExpansionTL
9128 = TLB.push<PackExpansionTypeLoc>(To);
9129 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9130 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9131 continue;
9132 }
9133
9134 // Expand the pack expansion by substituting for each argument in the
9135 // pack(s).
9136 for (unsigned I = 0; I != *NumExpansions; ++I) {
9137 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9138 TypeLocBuilder TLB;
9139 TLB.reserve(PatternTL.getFullDataSize());
9140 QualType To = getDerived().TransformType(TLB, PatternTL);
9141 if (To.isNull())
9142 return ExprError();
9143
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009144 if (To->containsUnexpandedParameterPack()) {
9145 To = getDerived().RebuildPackExpansionType(To,
9146 PatternTL.getSourceRange(),
9147 ExpansionTL.getEllipsisLoc(),
9148 NumExpansions);
9149 if (To.isNull())
9150 return ExprError();
9151
9152 PackExpansionTypeLoc ToExpansionTL
9153 = TLB.push<PackExpansionTypeLoc>(To);
9154 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9155 }
9156
Douglas Gregor29c42f22012-02-24 07:38:34 +00009157 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009159
Douglas Gregor29c42f22012-02-24 07:38:34 +00009160 if (!RetainExpansion)
9161 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009162
Douglas Gregor29c42f22012-02-24 07:38:34 +00009163 // If we're supposed to retain a pack expansion, do so by temporarily
9164 // forgetting the partially-substituted parameter pack.
9165 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9166
9167 TypeLocBuilder TLB;
9168 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009169
Douglas Gregor29c42f22012-02-24 07:38:34 +00009170 QualType To = getDerived().TransformType(TLB, PatternTL);
9171 if (To.isNull())
9172 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009173
9174 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009175 PatternTL.getSourceRange(),
9176 ExpansionTL.getEllipsisLoc(),
9177 NumExpansions);
9178 if (To.isNull())
9179 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009180
Douglas Gregor29c42f22012-02-24 07:38:34 +00009181 PackExpansionTypeLoc ToExpansionTL
9182 = TLB.push<PackExpansionTypeLoc>(To);
9183 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9184 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009186
Douglas Gregor29c42f22012-02-24 07:38:34 +00009187 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009188 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009189
9190 return getDerived().RebuildTypeTrait(E->getTrait(),
9191 E->getLocStart(),
9192 Args,
9193 E->getLocEnd());
9194}
9195
9196template<typename Derived>
9197ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009198TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9199 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9200 if (!T)
9201 return ExprError();
9202
9203 if (!getDerived().AlwaysRebuild() &&
9204 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009205 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009206
9207 ExprResult SubExpr;
9208 {
9209 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9210 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9211 if (SubExpr.isInvalid())
9212 return ExprError();
9213
9214 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009215 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009216 }
9217
9218 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9219 E->getLocStart(),
9220 T,
9221 SubExpr.get(),
9222 E->getLocEnd());
9223}
9224
9225template<typename Derived>
9226ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009227TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9228 ExprResult SubExpr;
9229 {
9230 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9231 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9232 if (SubExpr.isInvalid())
9233 return ExprError();
9234
9235 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009236 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009237 }
9238
9239 return getDerived().RebuildExpressionTrait(
9240 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9241}
9242
Reid Kleckner32506ed2014-06-12 23:03:48 +00009243template <typename Derived>
9244ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9245 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9246 TypeSourceInfo **RecoveryTSI) {
9247 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9248 DRE, AddrTaken, RecoveryTSI);
9249
9250 // Propagate both errors and recovered types, which return ExprEmpty.
9251 if (!NewDRE.isUsable())
9252 return NewDRE;
9253
9254 // We got an expr, wrap it up in parens.
9255 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9256 return PE;
9257 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9258 PE->getRParen());
9259}
9260
9261template <typename Derived>
9262ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9263 DependentScopeDeclRefExpr *E) {
9264 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9265 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009266}
9267
9268template<typename Derived>
9269ExprResult
9270TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9271 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009272 bool IsAddressOfOperand,
9273 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009274 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009275 NestedNameSpecifierLoc QualifierLoc
9276 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9277 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009278 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009279 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009280
John McCall31f82722010-11-12 08:19:04 +00009281 // TODO: If this is a conversion-function-id, verify that the
9282 // destination type name (if present) resolves the same way after
9283 // instantiation as it did in the local scope.
9284
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009285 DeclarationNameInfo NameInfo
9286 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9287 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009289
John McCalle66edc12009-11-24 19:00:30 +00009290 if (!E->hasExplicitTemplateArgs()) {
9291 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009292 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009293 // Note: it is sufficient to compare the Name component of NameInfo:
9294 // if name has not changed, DNLoc has not changed either.
9295 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009296 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009297
Reid Kleckner32506ed2014-06-12 23:03:48 +00009298 return getDerived().RebuildDependentScopeDeclRefExpr(
9299 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9300 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009301 }
John McCall6b51f282009-11-23 01:53:49 +00009302
9303 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009304 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9305 E->getNumTemplateArgs(),
9306 TransArgs))
9307 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009308
Reid Kleckner32506ed2014-06-12 23:03:48 +00009309 return getDerived().RebuildDependentScopeDeclRefExpr(
9310 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9311 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009312}
9313
9314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009316TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009317 // CXXConstructExprs other than for list-initialization and
9318 // CXXTemporaryObjectExpr are always implicit, so when we have
9319 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009320 if ((E->getNumArgs() == 1 ||
9321 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009322 (!getDerived().DropCallArgument(E->getArg(0))) &&
9323 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009324 return getDerived().TransformExpr(E->getArg(0));
9325
Douglas Gregora16548e2009-08-11 05:31:07 +00009326 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9327
9328 QualType T = getDerived().TransformType(E->getType());
9329 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009330 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009331
9332 CXXConstructorDecl *Constructor
9333 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009334 getDerived().TransformDecl(E->getLocStart(),
9335 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009336 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009337 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009338
Douglas Gregora16548e2009-08-11 05:31:07 +00009339 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009340 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009341 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009342 &ArgumentChanged))
9343 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009344
Douglas Gregora16548e2009-08-11 05:31:07 +00009345 if (!getDerived().AlwaysRebuild() &&
9346 T == E->getType() &&
9347 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009348 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009349 // Mark the constructor as referenced.
9350 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009351 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009352 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009353 }
Mike Stump11289f42009-09-09 15:08:12 +00009354
Douglas Gregordb121ba2009-12-14 16:27:04 +00009355 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9356 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009357 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009358 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009359 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009360 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009361 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009362 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009363 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009364}
Mike Stump11289f42009-09-09 15:08:12 +00009365
Douglas Gregora16548e2009-08-11 05:31:07 +00009366/// \brief Transform a C++ temporary-binding expression.
9367///
Douglas Gregor363b1512009-12-24 18:51:59 +00009368/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9369/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009372TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009373 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009374}
Mike Stump11289f42009-09-09 15:08:12 +00009375
John McCall5d413782010-12-06 08:20:24 +00009376/// \brief Transform a C++ expression that contains cleanups that should
9377/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009378///
John McCall5d413782010-12-06 08:20:24 +00009379/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009380/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009382ExprResult
John McCall5d413782010-12-06 08:20:24 +00009383TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009384 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009385}
Mike Stump11289f42009-09-09 15:08:12 +00009386
Douglas Gregora16548e2009-08-11 05:31:07 +00009387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009388ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009389TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009390 CXXTemporaryObjectExpr *E) {
9391 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9392 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 CXXConstructorDecl *Constructor
9396 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009397 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009398 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009399 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009401
Douglas Gregora16548e2009-08-11 05:31:07 +00009402 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009403 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009404 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009405 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009406 &ArgumentChanged))
9407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregora16548e2009-08-11 05:31:07 +00009409 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009410 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009412 !ArgumentChanged) {
9413 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009414 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009415 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009417
Richard Smithd59b8322012-12-19 01:39:02 +00009418 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009419 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9420 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009421 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009422 E->getLocEnd());
9423}
Mike Stump11289f42009-09-09 15:08:12 +00009424
Douglas Gregora16548e2009-08-11 05:31:07 +00009425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009426ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009427TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009428 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009429 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009430 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009431 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9432 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009433 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009434 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009435 CEnd = E->capture_end();
9436 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009437 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009438 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009439 EnterExpressionEvaluationContext EEEC(getSema(),
9440 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009441 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9442 C->getCapturedVar()->getInit(),
9443 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009444
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009445 if (NewExprInitResult.isInvalid())
9446 return ExprError();
9447 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009448
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009449 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009450 QualType NewInitCaptureType =
9451 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9452 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009453 NewExprInit);
9454 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009455 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9456 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009457 }
9458
Faisal Vali2cba1332013-10-23 06:44:28 +00009459 // Transform the template parameters, and add them to the current
9460 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009461 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009462 E->getTemplateParameterList());
9463
Richard Smith01014ce2014-11-20 23:53:14 +00009464 // Transform the type of the original lambda's call operator.
9465 // The transformation MUST be done in the CurrentInstantiationScope since
9466 // it introduces a mapping of the original to the newly created
9467 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009468 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009469 {
9470 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9471 FunctionProtoTypeLoc OldCallOpFPTL =
9472 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009473
9474 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009475 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009476 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009477 QualType NewCallOpType = TransformFunctionProtoType(
9478 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009479 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9480 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9481 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009482 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009483 if (NewCallOpType.isNull())
9484 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009485 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9486 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009487 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009488
Richard Smithc38498f2015-04-27 21:27:54 +00009489 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9490 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9491 LSI->GLTemplateParameterList = TPL;
9492
Eli Friedmand564afb2012-09-19 01:18:11 +00009493 // Create the local class that will describe the lambda.
9494 CXXRecordDecl *Class
9495 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009496 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009497 /*KnownDependent=*/false,
9498 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009499 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9500
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009501 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009502 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9503 Class, E->getIntroducerRange(), NewCallOpTSI,
9504 E->getCallOperator()->getLocEnd(),
9505 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009506 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009507
Faisal Vali2cba1332013-10-23 06:44:28 +00009508 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009509 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009510
Douglas Gregorb4328232012-02-14 00:00:48 +00009511 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009512 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009513 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009514
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009515 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009516 getSema().buildLambdaScope(LSI, NewCallOperator,
9517 E->getIntroducerRange(),
9518 E->getCaptureDefault(),
9519 E->getCaptureDefaultLoc(),
9520 E->hasExplicitParameters(),
9521 E->hasExplicitResultType(),
9522 E->isMutable());
9523
9524 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009525
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009526 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009527 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009528 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009529 CEnd = E->capture_end();
9530 C != CEnd; ++C) {
9531 // When we hit the first implicit capture, tell Sema that we've finished
9532 // the list of explicit captures.
9533 if (!FinishedExplicitCaptures && C->isImplicit()) {
9534 getSema().finishLambdaExplicitCaptures(LSI);
9535 FinishedExplicitCaptures = true;
9536 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009537
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009538 // Capturing 'this' is trivial.
9539 if (C->capturesThis()) {
9540 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9541 continue;
9542 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009543 // Captured expression will be recaptured during captured variables
9544 // rebuilding.
9545 if (C->capturesVLAType())
9546 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009547
Richard Smithba71c082013-05-16 06:20:58 +00009548 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009549 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009550 InitCaptureInfoTy InitExprTypePair =
9551 InitCaptureExprsAndTypes[C - E->capture_begin()];
9552 ExprResult Init = InitExprTypePair.first;
9553 QualType InitQualType = InitExprTypePair.second;
9554 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009555 Invalid = true;
9556 continue;
9557 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009558 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009559 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9560 OldVD->getLocation(), InitExprTypePair.second,
9561 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009562 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009563 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009564 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009565 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009566 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009567 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009568 continue;
9569 }
9570
9571 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9572
Douglas Gregor3e308b12012-02-14 19:27:52 +00009573 // Determine the capture kind for Sema.
9574 Sema::TryCaptureKind Kind
9575 = C->isImplicit()? Sema::TryCapture_Implicit
9576 : C->getCaptureKind() == LCK_ByCopy
9577 ? Sema::TryCapture_ExplicitByVal
9578 : Sema::TryCapture_ExplicitByRef;
9579 SourceLocation EllipsisLoc;
9580 if (C->isPackExpansion()) {
9581 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9582 bool ShouldExpand = false;
9583 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009584 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009585 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9586 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009587 Unexpanded,
9588 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009589 NumExpansions)) {
9590 Invalid = true;
9591 continue;
9592 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009593
Douglas Gregor3e308b12012-02-14 19:27:52 +00009594 if (ShouldExpand) {
9595 // The transform has determined that we should perform an expansion;
9596 // transform and capture each of the arguments.
9597 // expansion of the pattern. Do so.
9598 VarDecl *Pack = C->getCapturedVar();
9599 for (unsigned I = 0; I != *NumExpansions; ++I) {
9600 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9601 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009602 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009603 Pack));
9604 if (!CapturedVar) {
9605 Invalid = true;
9606 continue;
9607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009608
Douglas Gregor3e308b12012-02-14 19:27:52 +00009609 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009610 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9611 }
Richard Smith9467be42014-06-06 17:33:35 +00009612
9613 // FIXME: Retain a pack expansion if RetainExpansion is true.
9614
Douglas Gregor3e308b12012-02-14 19:27:52 +00009615 continue;
9616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009617
Douglas Gregor3e308b12012-02-14 19:27:52 +00009618 EllipsisLoc = C->getEllipsisLoc();
9619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009620
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009621 // Transform the captured variable.
9622 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009623 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009624 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009625 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009626 Invalid = true;
9627 continue;
9628 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009629
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009630 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009631 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9632 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009633 }
9634 if (!FinishedExplicitCaptures)
9635 getSema().finishLambdaExplicitCaptures(LSI);
9636
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009637 // Enter a new evaluation context to insulate the lambda from any
9638 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009639 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009640
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009641 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009642 StmtResult Body =
9643 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9644
9645 // ActOnLambda* will pop the function scope for us.
9646 FuncScopeCleanup.disable();
9647
Douglas Gregorb4328232012-02-14 00:00:48 +00009648 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009649 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009650 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009651 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009652 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009653 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009654
Richard Smithc38498f2015-04-27 21:27:54 +00009655 // Copy the LSI before ActOnFinishFunctionBody removes it.
9656 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9657 // the call operator.
9658 auto LSICopy = *LSI;
9659 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9660 /*IsInstantiation*/ true);
9661 SavedContext.pop();
9662
9663 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9664 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009665}
9666
9667template<typename Derived>
9668ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009669TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009670 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009671 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9672 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009674
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009676 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009677 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009678 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009679 &ArgumentChanged))
9680 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009681
Douglas Gregora16548e2009-08-11 05:31:07 +00009682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009683 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009684 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009685 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009686
Douglas Gregora16548e2009-08-11 05:31:07 +00009687 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009688 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009689 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009690 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009691 E->getRParenLoc());
9692}
Mike Stump11289f42009-09-09 15:08:12 +00009693
Douglas Gregora16548e2009-08-11 05:31:07 +00009694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009695ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009696TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009697 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009698 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009699 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009700 Expr *OldBase;
9701 QualType BaseType;
9702 QualType ObjectType;
9703 if (!E->isImplicitAccess()) {
9704 OldBase = E->getBase();
9705 Base = getDerived().TransformExpr(OldBase);
9706 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009708
John McCall2d74de92009-12-01 22:10:20 +00009709 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009710 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009711 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009712 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009713 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009714 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009715 ObjectTy,
9716 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009717 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009718 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009719
John McCallba7bf592010-08-24 05:47:05 +00009720 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009721 BaseType = ((Expr*) Base.get())->getType();
9722 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009723 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009724 BaseType = getDerived().TransformType(E->getBaseType());
9725 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9726 }
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009728 // Transform the first part of the nested-name-specifier that qualifies
9729 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009730 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009731 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009732 E->getFirstQualifierFoundInScope(),
9733 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009734
Douglas Gregore16af532011-02-28 18:50:33 +00009735 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009736 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009737 QualifierLoc
9738 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9739 ObjectType,
9740 FirstQualifierInScope);
9741 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009742 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009743 }
Mike Stump11289f42009-09-09 15:08:12 +00009744
Abramo Bagnara7945c982012-01-27 09:46:47 +00009745 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9746
John McCall31f82722010-11-12 08:19:04 +00009747 // TODO: If this is a conversion-function-id, verify that the
9748 // destination type name (if present) resolves the same way after
9749 // instantiation as it did in the local scope.
9750
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009751 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009752 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009753 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009755
John McCall2d74de92009-12-01 22:10:20 +00009756 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009757 // This is a reference to a member without an explicitly-specified
9758 // template argument list. Optimize for this common case.
9759 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009760 Base.get() == OldBase &&
9761 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009762 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009763 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009764 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009765 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009766
John McCallb268a282010-08-23 23:25:46 +00009767 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009768 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009769 E->isArrow(),
9770 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009771 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009772 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009773 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009774 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009775 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009776 }
9777
John McCall6b51f282009-11-23 01:53:49 +00009778 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009779 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9780 E->getNumTemplateArgs(),
9781 TransArgs))
9782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009783
John McCallb268a282010-08-23 23:25:46 +00009784 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009785 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 E->isArrow(),
9787 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009788 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009789 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009790 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009791 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009792 &TransArgs);
9793}
9794
9795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009796ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009797TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009798 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009799 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009800 QualType BaseType;
9801 if (!Old->isImplicitAccess()) {
9802 Base = getDerived().TransformExpr(Old->getBase());
9803 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009804 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009805 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009806 Old->isArrow());
9807 if (Base.isInvalid())
9808 return ExprError();
9809 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009810 } else {
9811 BaseType = getDerived().TransformType(Old->getBaseType());
9812 }
John McCall10eae182009-11-30 22:42:35 +00009813
Douglas Gregor0da1d432011-02-28 20:01:57 +00009814 NestedNameSpecifierLoc QualifierLoc;
9815 if (Old->getQualifierLoc()) {
9816 QualifierLoc
9817 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9818 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009819 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009820 }
9821
Abramo Bagnara7945c982012-01-27 09:46:47 +00009822 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9823
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009824 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009825 Sema::LookupOrdinaryName);
9826
9827 // Transform all the decls.
9828 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9829 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009830 NamedDecl *InstD = static_cast<NamedDecl*>(
9831 getDerived().TransformDecl(Old->getMemberLoc(),
9832 *I));
John McCall84d87672009-12-10 09:41:52 +00009833 if (!InstD) {
9834 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9835 // This can happen because of dependent hiding.
9836 if (isa<UsingShadowDecl>(*I))
9837 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009838 else {
9839 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009840 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009841 }
John McCall84d87672009-12-10 09:41:52 +00009842 }
John McCall10eae182009-11-30 22:42:35 +00009843
9844 // Expand using declarations.
9845 if (isa<UsingDecl>(InstD)) {
9846 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009847 for (auto *I : UD->shadows())
9848 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009849 continue;
9850 }
9851
9852 R.addDecl(InstD);
9853 }
9854
9855 R.resolveKind();
9856
Douglas Gregor9262f472010-04-27 18:19:34 +00009857 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009858 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009859 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009860 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009861 Old->getMemberLoc(),
9862 Old->getNamingClass()));
9863 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009864 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009865
Douglas Gregorda7be082010-04-27 16:10:10 +00009866 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009867 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009868
John McCall10eae182009-11-30 22:42:35 +00009869 TemplateArgumentListInfo TransArgs;
9870 if (Old->hasExplicitTemplateArgs()) {
9871 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9872 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009873 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9874 Old->getNumTemplateArgs(),
9875 TransArgs))
9876 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009877 }
John McCall38836f02010-01-15 08:34:02 +00009878
9879 // FIXME: to do this check properly, we will need to preserve the
9880 // first-qualifier-in-scope here, just in case we had a dependent
9881 // base (and therefore couldn't do the check) and a
9882 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009883 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009884
John McCallb268a282010-08-23 23:25:46 +00009885 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009886 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009887 Old->getOperatorLoc(),
9888 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009889 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009890 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009891 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009892 R,
9893 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009894 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009895}
9896
9897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009898ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009899TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009900 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009901 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9902 if (SubExpr.isInvalid())
9903 return ExprError();
9904
9905 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009906 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009907
9908 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9909}
9910
9911template<typename Derived>
9912ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009913TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009914 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9915 if (Pattern.isInvalid())
9916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009917
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009918 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009919 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009920
Douglas Gregorb8840002011-01-14 21:20:45 +00009921 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9922 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009923}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009924
9925template<typename Derived>
9926ExprResult
9927TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9928 // If E is not value-dependent, then nothing will change when we transform it.
9929 // Note: This is an instantiation-centric view.
9930 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009931 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009932
9933 // Note: None of the implementations of TryExpandParameterPacks can ever
9934 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009935 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009936 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9937 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009938 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009939 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009940 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009941 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009942 ShouldExpand, RetainExpansion,
9943 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009944 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009945
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009946 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009947 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009948
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009949 NamedDecl *Pack = E->getPack();
9950 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009951 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009952 Pack));
9953 if (!Pack)
9954 return ExprError();
9955 }
9956
Chad Rosier1dcde962012-08-08 18:46:20 +00009957
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009958 // We now know the length of the parameter pack, so build a new expression
9959 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009960 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9961 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009962 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009963}
9964
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009965template<typename Derived>
9966ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009967TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9968 SubstNonTypeTemplateParmPackExpr *E) {
9969 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009970 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009971}
9972
9973template<typename Derived>
9974ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009975TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9976 SubstNonTypeTemplateParmExpr *E) {
9977 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009978 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009979}
9980
9981template<typename Derived>
9982ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009983TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9984 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009985 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009986}
9987
9988template<typename Derived>
9989ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009990TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9991 MaterializeTemporaryExpr *E) {
9992 return getDerived().TransformExpr(E->GetTemporaryExpr());
9993}
Chad Rosier1dcde962012-08-08 18:46:20 +00009994
Douglas Gregorfe314812011-06-21 17:03:29 +00009995template<typename Derived>
9996ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +00009997TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
9998 Expr *Pattern = E->getPattern();
9999
10000 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10001 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10002 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10003
10004 // Determine whether the set of unexpanded parameter packs can and should
10005 // be expanded.
10006 bool Expand = true;
10007 bool RetainExpansion = false;
10008 Optional<unsigned> NumExpansions;
10009 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10010 Pattern->getSourceRange(),
10011 Unexpanded,
10012 Expand, RetainExpansion,
10013 NumExpansions))
10014 return true;
10015
10016 if (!Expand) {
10017 // Do not expand any packs here, just transform and rebuild a fold
10018 // expression.
10019 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10020
10021 ExprResult LHS =
10022 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10023 if (LHS.isInvalid())
10024 return true;
10025
10026 ExprResult RHS =
10027 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10028 if (RHS.isInvalid())
10029 return true;
10030
10031 if (!getDerived().AlwaysRebuild() &&
10032 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10033 return E;
10034
10035 return getDerived().RebuildCXXFoldExpr(
10036 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10037 RHS.get(), E->getLocEnd());
10038 }
10039
10040 // The transform has determined that we should perform an elementwise
10041 // expansion of the pattern. Do so.
10042 ExprResult Result = getDerived().TransformExpr(E->getInit());
10043 if (Result.isInvalid())
10044 return true;
10045 bool LeftFold = E->isLeftFold();
10046
10047 // If we're retaining an expansion for a right fold, it is the innermost
10048 // component and takes the init (if any).
10049 if (!LeftFold && RetainExpansion) {
10050 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10051
10052 ExprResult Out = getDerived().TransformExpr(Pattern);
10053 if (Out.isInvalid())
10054 return true;
10055
10056 Result = getDerived().RebuildCXXFoldExpr(
10057 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10058 Result.get(), E->getLocEnd());
10059 if (Result.isInvalid())
10060 return true;
10061 }
10062
10063 for (unsigned I = 0; I != *NumExpansions; ++I) {
10064 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10065 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10066 ExprResult Out = getDerived().TransformExpr(Pattern);
10067 if (Out.isInvalid())
10068 return true;
10069
10070 if (Out.get()->containsUnexpandedParameterPack()) {
10071 // We still have a pack; retain a pack expansion for this slice.
10072 Result = getDerived().RebuildCXXFoldExpr(
10073 E->getLocStart(),
10074 LeftFold ? Result.get() : Out.get(),
10075 E->getOperator(), E->getEllipsisLoc(),
10076 LeftFold ? Out.get() : Result.get(),
10077 E->getLocEnd());
10078 } else if (Result.isUsable()) {
10079 // We've got down to a single element; build a binary operator.
10080 Result = getDerived().RebuildBinaryOperator(
10081 E->getEllipsisLoc(), E->getOperator(),
10082 LeftFold ? Result.get() : Out.get(),
10083 LeftFold ? Out.get() : Result.get());
10084 } else
10085 Result = Out;
10086
10087 if (Result.isInvalid())
10088 return true;
10089 }
10090
10091 // If we're retaining an expansion for a left fold, it is the outermost
10092 // component and takes the complete expansion so far as its init (if any).
10093 if (LeftFold && RetainExpansion) {
10094 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10095
10096 ExprResult Out = getDerived().TransformExpr(Pattern);
10097 if (Out.isInvalid())
10098 return true;
10099
10100 Result = getDerived().RebuildCXXFoldExpr(
10101 E->getLocStart(), Result.get(),
10102 E->getOperator(), E->getEllipsisLoc(),
10103 Out.get(), E->getLocEnd());
10104 if (Result.isInvalid())
10105 return true;
10106 }
10107
10108 // If we had no init and an empty pack, and we're not retaining an expansion,
10109 // then produce a fallback value or error.
10110 if (Result.isUnset())
10111 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10112 E->getOperator());
10113
10114 return Result;
10115}
10116
10117template<typename Derived>
10118ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010119TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10120 CXXStdInitializerListExpr *E) {
10121 return getDerived().TransformExpr(E->getSubExpr());
10122}
10123
10124template<typename Derived>
10125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010126TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010127 return SemaRef.MaybeBindToTemporary(E);
10128}
10129
10130template<typename Derived>
10131ExprResult
10132TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010133 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010134}
10135
10136template<typename Derived>
10137ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010138TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10139 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10140 if (SubExpr.isInvalid())
10141 return ExprError();
10142
10143 if (!getDerived().AlwaysRebuild() &&
10144 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010145 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010146
10147 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010148}
10149
10150template<typename Derived>
10151ExprResult
10152TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10153 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010154 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010155 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010156 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010157 /*IsCall=*/false, Elements, &ArgChanged))
10158 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010159
Ted Kremeneke65b0862012-03-06 20:05:56 +000010160 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10161 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010162
Ted Kremeneke65b0862012-03-06 20:05:56 +000010163 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10164 Elements.data(),
10165 Elements.size());
10166}
10167
10168template<typename Derived>
10169ExprResult
10170TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010171 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010172 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010173 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010174 bool ArgChanged = false;
10175 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10176 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010177
Ted Kremeneke65b0862012-03-06 20:05:56 +000010178 if (OrigElement.isPackExpansion()) {
10179 // This key/value element is a pack expansion.
10180 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10181 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10182 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10183 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10184
10185 // Determine whether the set of unexpanded parameter packs can
10186 // and should be expanded.
10187 bool Expand = true;
10188 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010189 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10190 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010191 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10192 OrigElement.Value->getLocEnd());
10193 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10194 PatternRange,
10195 Unexpanded,
10196 Expand, RetainExpansion,
10197 NumExpansions))
10198 return ExprError();
10199
10200 if (!Expand) {
10201 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010202 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010203 // expansion.
10204 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10205 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10206 if (Key.isInvalid())
10207 return ExprError();
10208
10209 if (Key.get() != OrigElement.Key)
10210 ArgChanged = true;
10211
10212 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10213 if (Value.isInvalid())
10214 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010215
Ted Kremeneke65b0862012-03-06 20:05:56 +000010216 if (Value.get() != OrigElement.Value)
10217 ArgChanged = true;
10218
Chad Rosier1dcde962012-08-08 18:46:20 +000010219 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010220 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10221 };
10222 Elements.push_back(Expansion);
10223 continue;
10224 }
10225
10226 // Record right away that the argument was changed. This needs
10227 // to happen even if the array expands to nothing.
10228 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010229
Ted Kremeneke65b0862012-03-06 20:05:56 +000010230 // The transform has determined that we should perform an elementwise
10231 // expansion of the pattern. Do so.
10232 for (unsigned I = 0; I != *NumExpansions; ++I) {
10233 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10234 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10235 if (Key.isInvalid())
10236 return ExprError();
10237
10238 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10239 if (Value.isInvalid())
10240 return ExprError();
10241
Chad Rosier1dcde962012-08-08 18:46:20 +000010242 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010243 Key.get(), Value.get(), SourceLocation(), NumExpansions
10244 };
10245
10246 // If any unexpanded parameter packs remain, we still have a
10247 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010248 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010249 if (Key.get()->containsUnexpandedParameterPack() ||
10250 Value.get()->containsUnexpandedParameterPack())
10251 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010252
Ted Kremeneke65b0862012-03-06 20:05:56 +000010253 Elements.push_back(Element);
10254 }
10255
Richard Smith9467be42014-06-06 17:33:35 +000010256 // FIXME: Retain a pack expansion if RetainExpansion is true.
10257
Ted Kremeneke65b0862012-03-06 20:05:56 +000010258 // We've finished with this pack expansion.
10259 continue;
10260 }
10261
10262 // Transform and check key.
10263 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10264 if (Key.isInvalid())
10265 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010266
Ted Kremeneke65b0862012-03-06 20:05:56 +000010267 if (Key.get() != OrigElement.Key)
10268 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010269
Ted Kremeneke65b0862012-03-06 20:05:56 +000010270 // Transform and check value.
10271 ExprResult Value
10272 = getDerived().TransformExpr(OrigElement.Value);
10273 if (Value.isInvalid())
10274 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010275
Ted Kremeneke65b0862012-03-06 20:05:56 +000010276 if (Value.get() != OrigElement.Value)
10277 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010278
10279 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010280 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010281 };
10282 Elements.push_back(Element);
10283 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010284
Ted Kremeneke65b0862012-03-06 20:05:56 +000010285 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10286 return SemaRef.MaybeBindToTemporary(E);
10287
10288 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10289 Elements.data(),
10290 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010291}
10292
Mike Stump11289f42009-09-09 15:08:12 +000010293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010294ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010295TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010296 TypeSourceInfo *EncodedTypeInfo
10297 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10298 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010300
Douglas Gregora16548e2009-08-11 05:31:07 +000010301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010302 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010303 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010304
10305 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010306 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010307 E->getRParenLoc());
10308}
Mike Stump11289f42009-09-09 15:08:12 +000010309
Douglas Gregora16548e2009-08-11 05:31:07 +000010310template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010311ExprResult TreeTransform<Derived>::
10312TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010313 // This is a kind of implicit conversion, and it needs to get dropped
10314 // and recomputed for the same general reasons that ImplicitCastExprs
10315 // do, as well a more specific one: this expression is only valid when
10316 // it appears *immediately* as an argument expression.
10317 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010318}
10319
10320template<typename Derived>
10321ExprResult TreeTransform<Derived>::
10322TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010323 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010324 = getDerived().TransformType(E->getTypeInfoAsWritten());
10325 if (!TSInfo)
10326 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010327
John McCall31168b02011-06-15 23:02:42 +000010328 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010329 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010330 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010331
John McCall31168b02011-06-15 23:02:42 +000010332 if (!getDerived().AlwaysRebuild() &&
10333 TSInfo == E->getTypeInfoAsWritten() &&
10334 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010335 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010336
John McCall31168b02011-06-15 23:02:42 +000010337 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010338 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010339 Result.get());
10340}
10341
10342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010344TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010345 // Transform arguments.
10346 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010347 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010348 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010349 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010350 &ArgChanged))
10351 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010352
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010353 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10354 // Class message: transform the receiver type.
10355 TypeSourceInfo *ReceiverTypeInfo
10356 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10357 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010358 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010359
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010360 // If nothing changed, just retain the existing message send.
10361 if (!getDerived().AlwaysRebuild() &&
10362 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010363 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010364
10365 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010366 SmallVector<SourceLocation, 16> SelLocs;
10367 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010368 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10369 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010370 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010371 E->getMethodDecl(),
10372 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010373 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010374 E->getRightLoc());
10375 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010376 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10377 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10378 // Build a new class message send to 'super'.
10379 SmallVector<SourceLocation, 16> SelLocs;
10380 E->getSelectorLocs(SelLocs);
10381 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10382 E->getSelector(),
10383 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010384 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010385 E->getMethodDecl(),
10386 E->getLeftLoc(),
10387 Args,
10388 E->getRightLoc());
10389 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010390
10391 // Instance message: transform the receiver
10392 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10393 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010394 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010395 = getDerived().TransformExpr(E->getInstanceReceiver());
10396 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010397 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010398
10399 // If nothing changed, just retain the existing message send.
10400 if (!getDerived().AlwaysRebuild() &&
10401 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010402 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010403
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010404 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010405 SmallVector<SourceLocation, 16> SelLocs;
10406 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010407 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010408 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010409 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010410 E->getMethodDecl(),
10411 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010412 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010413 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010414}
10415
Mike Stump11289f42009-09-09 15:08:12 +000010416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010417ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010418TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010419 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010420}
10421
Mike Stump11289f42009-09-09 15:08:12 +000010422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010424TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010425 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010426}
10427
Mike Stump11289f42009-09-09 15:08:12 +000010428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010430TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010431 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010432 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010433 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010434 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010435
10436 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010437
Douglas Gregord51d90d2010-04-26 20:11:03 +000010438 // If nothing changed, just retain the existing expression.
10439 if (!getDerived().AlwaysRebuild() &&
10440 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010441 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010442
John McCallb268a282010-08-23 23:25:46 +000010443 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010444 E->getLocation(),
10445 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010446}
10447
Mike Stump11289f42009-09-09 15:08:12 +000010448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010450TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010451 // 'super' and types never change. Property never changes. Just
10452 // retain the existing expression.
10453 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010454 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010455
Douglas Gregor9faee212010-04-26 20:47:02 +000010456 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010457 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010458 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010459 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010460
Douglas Gregor9faee212010-04-26 20:47:02 +000010461 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010462
Douglas Gregor9faee212010-04-26 20:47:02 +000010463 // If nothing changed, just retain the existing expression.
10464 if (!getDerived().AlwaysRebuild() &&
10465 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010466 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010467
John McCallb7bd14f2010-12-02 01:19:52 +000010468 if (E->isExplicitProperty())
10469 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10470 E->getExplicitProperty(),
10471 E->getLocation());
10472
10473 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010474 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010475 E->getImplicitPropertyGetter(),
10476 E->getImplicitPropertySetter(),
10477 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010478}
10479
Mike Stump11289f42009-09-09 15:08:12 +000010480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010481ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010482TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10483 // Transform the base expression.
10484 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10485 if (Base.isInvalid())
10486 return ExprError();
10487
10488 // Transform the key expression.
10489 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10490 if (Key.isInvalid())
10491 return ExprError();
10492
10493 // If nothing changed, just retain the existing expression.
10494 if (!getDerived().AlwaysRebuild() &&
10495 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010496 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010497
Chad Rosier1dcde962012-08-08 18:46:20 +000010498 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010499 Base.get(), Key.get(),
10500 E->getAtIndexMethodDecl(),
10501 E->setAtIndexMethodDecl());
10502}
10503
10504template<typename Derived>
10505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010506TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010507 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010508 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010509 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010510 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010511
Douglas Gregord51d90d2010-04-26 20:11:03 +000010512 // If nothing changed, just retain the existing expression.
10513 if (!getDerived().AlwaysRebuild() &&
10514 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010515 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010516
John McCallb268a282010-08-23 23:25:46 +000010517 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010518 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010519 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010520}
10521
Mike Stump11289f42009-09-09 15:08:12 +000010522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010523ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010524TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010525 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010526 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010527 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010528 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010529 SubExprs, &ArgumentChanged))
10530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010531
Douglas Gregora16548e2009-08-11 05:31:07 +000010532 if (!getDerived().AlwaysRebuild() &&
10533 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010534 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010535
Douglas Gregora16548e2009-08-11 05:31:07 +000010536 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010537 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010538 E->getRParenLoc());
10539}
10540
Mike Stump11289f42009-09-09 15:08:12 +000010541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010542ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010543TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10544 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10545 if (SrcExpr.isInvalid())
10546 return ExprError();
10547
10548 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10549 if (!Type)
10550 return ExprError();
10551
10552 if (!getDerived().AlwaysRebuild() &&
10553 Type == E->getTypeSourceInfo() &&
10554 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010555 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010556
10557 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10558 SrcExpr.get(), Type,
10559 E->getRParenLoc());
10560}
10561
10562template<typename Derived>
10563ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010564TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010565 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010566
Craig Topperc3ec1492014-05-26 06:22:03 +000010567 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010568 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10569
10570 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010571 blockScope->TheDecl->setBlockMissingReturnType(
10572 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010573
Chris Lattner01cf8db2011-07-20 06:58:45 +000010574 SmallVector<ParmVarDecl*, 4> params;
10575 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010576
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010577 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010578 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10579 oldBlock->param_begin(),
10580 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010581 nullptr, paramTypes, &params)) {
10582 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010583 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010584 }
John McCall490112f2011-02-04 18:33:18 +000010585
Jordan Rosea0a86be2013-03-08 22:25:36 +000010586 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010587 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010588 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010589
Jordan Rose5c382722013-03-08 21:51:21 +000010590 QualType functionType =
10591 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010592 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010593 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010594
10595 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010596 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010597 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010598
10599 if (!oldBlock->blockMissingReturnType()) {
10600 blockScope->HasImplicitReturnType = false;
10601 blockScope->ReturnType = exprResultType;
10602 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010603
John McCall3882ace2011-01-05 12:14:39 +000010604 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010605 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010606 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010607 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010608 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010609 }
John McCall3882ace2011-01-05 12:14:39 +000010610
John McCall490112f2011-02-04 18:33:18 +000010611#ifndef NDEBUG
10612 // In builds with assertions, make sure that we captured everything we
10613 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010614 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010615 for (const auto &I : oldBlock->captures()) {
10616 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010617
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010618 // Ignore parameter packs.
10619 if (isa<ParmVarDecl>(oldCapture) &&
10620 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10621 continue;
John McCall490112f2011-02-04 18:33:18 +000010622
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010623 VarDecl *newCapture =
10624 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10625 oldCapture));
10626 assert(blockScope->CaptureMap.count(newCapture));
10627 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010628 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010629 }
10630#endif
10631
10632 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010633 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010634}
10635
Mike Stump11289f42009-09-09 15:08:12 +000010636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010637ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010638TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010639 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010640}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010641
10642template<typename Derived>
10643ExprResult
10644TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010645 QualType RetTy = getDerived().TransformType(E->getType());
10646 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010647 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010648 SubExprs.reserve(E->getNumSubExprs());
10649 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10650 SubExprs, &ArgumentChanged))
10651 return ExprError();
10652
10653 if (!getDerived().AlwaysRebuild() &&
10654 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010655 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010656
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010657 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010658 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010659}
Chad Rosier1dcde962012-08-08 18:46:20 +000010660
Douglas Gregora16548e2009-08-11 05:31:07 +000010661//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010662// Type reconstruction
10663//===----------------------------------------------------------------------===//
10664
Mike Stump11289f42009-09-09 15:08:12 +000010665template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010666QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10667 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010668 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010669 getDerived().getBaseEntity());
10670}
10671
Mike Stump11289f42009-09-09 15:08:12 +000010672template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010673QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10674 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010675 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010676 getDerived().getBaseEntity());
10677}
10678
Mike Stump11289f42009-09-09 15:08:12 +000010679template<typename Derived>
10680QualType
John McCall70dd5f62009-10-30 00:06:24 +000010681TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10682 bool WrittenAsLValue,
10683 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010684 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010685 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010686}
10687
10688template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010689QualType
John McCall70dd5f62009-10-30 00:06:24 +000010690TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10691 QualType ClassType,
10692 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010693 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10694 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010695}
10696
10697template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010698QualType TreeTransform<Derived>::RebuildObjCObjectType(
10699 QualType BaseType,
10700 SourceLocation Loc,
10701 SourceLocation TypeArgsLAngleLoc,
10702 ArrayRef<TypeSourceInfo *> TypeArgs,
10703 SourceLocation TypeArgsRAngleLoc,
10704 SourceLocation ProtocolLAngleLoc,
10705 ArrayRef<ObjCProtocolDecl *> Protocols,
10706 ArrayRef<SourceLocation> ProtocolLocs,
10707 SourceLocation ProtocolRAngleLoc) {
10708 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10709 TypeArgs, TypeArgsRAngleLoc,
10710 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10711 ProtocolRAngleLoc,
10712 /*FailOnError=*/true);
10713}
10714
10715template<typename Derived>
10716QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10717 QualType PointeeType,
10718 SourceLocation Star) {
10719 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10720}
10721
10722template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010723QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010724TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10725 ArrayType::ArraySizeModifier SizeMod,
10726 const llvm::APInt *Size,
10727 Expr *SizeExpr,
10728 unsigned IndexTypeQuals,
10729 SourceRange BracketsRange) {
10730 if (SizeExpr || !Size)
10731 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10732 IndexTypeQuals, BracketsRange,
10733 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010734
10735 QualType Types[] = {
10736 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10737 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10738 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010739 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010740 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010741 QualType SizeType;
10742 for (unsigned I = 0; I != NumTypes; ++I)
10743 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10744 SizeType = Types[I];
10745 break;
10746 }
Mike Stump11289f42009-09-09 15:08:12 +000010747
Eli Friedman9562f392012-01-25 23:20:27 +000010748 // Note that we can return a VariableArrayType here in the case where
10749 // the element type was a dependent VariableArrayType.
10750 IntegerLiteral *ArraySize
10751 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10752 /*FIXME*/BracketsRange.getBegin());
10753 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010754 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010755 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010756}
Mike Stump11289f42009-09-09 15:08:12 +000010757
Douglas Gregord6ff3322009-08-04 16:50:30 +000010758template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010759QualType
10760TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010761 ArrayType::ArraySizeModifier SizeMod,
10762 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010763 unsigned IndexTypeQuals,
10764 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010765 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010766 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010767}
10768
10769template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010770QualType
Mike Stump11289f42009-09-09 15:08:12 +000010771TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010772 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010773 unsigned IndexTypeQuals,
10774 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010775 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010776 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010777}
Mike Stump11289f42009-09-09 15:08:12 +000010778
Douglas Gregord6ff3322009-08-04 16:50:30 +000010779template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010780QualType
10781TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010782 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010783 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010784 unsigned IndexTypeQuals,
10785 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010786 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010787 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010788 IndexTypeQuals, BracketsRange);
10789}
10790
10791template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010792QualType
10793TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010794 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010795 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010796 unsigned IndexTypeQuals,
10797 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010798 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010799 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010800 IndexTypeQuals, BracketsRange);
10801}
10802
10803template<typename Derived>
10804QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010805 unsigned NumElements,
10806 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010807 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010808 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010809}
Mike Stump11289f42009-09-09 15:08:12 +000010810
Douglas Gregord6ff3322009-08-04 16:50:30 +000010811template<typename Derived>
10812QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10813 unsigned NumElements,
10814 SourceLocation AttributeLoc) {
10815 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10816 NumElements, true);
10817 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010818 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10819 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010820 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010821}
Mike Stump11289f42009-09-09 15:08:12 +000010822
Douglas Gregord6ff3322009-08-04 16:50:30 +000010823template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010824QualType
10825TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010826 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010827 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010828 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010829}
Mike Stump11289f42009-09-09 15:08:12 +000010830
Douglas Gregord6ff3322009-08-04 16:50:30 +000010831template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010832QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10833 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010834 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010835 const FunctionProtoType::ExtProtoInfo &EPI) {
10836 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010837 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010838 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010839 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010840}
Mike Stump11289f42009-09-09 15:08:12 +000010841
Douglas Gregord6ff3322009-08-04 16:50:30 +000010842template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010843QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10844 return SemaRef.Context.getFunctionNoProtoType(T);
10845}
10846
10847template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010848QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10849 assert(D && "no decl found");
10850 if (D->isInvalidDecl()) return QualType();
10851
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010852 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010853 TypeDecl *Ty;
10854 if (isa<UsingDecl>(D)) {
10855 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010856 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010857 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10858
10859 // A valid resolved using typename decl points to exactly one type decl.
10860 assert(++Using->shadow_begin() == Using->shadow_end());
10861 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010862
John McCallb96ec562009-12-04 22:46:56 +000010863 } else {
10864 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10865 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10866 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10867 }
10868
10869 return SemaRef.Context.getTypeDeclType(Ty);
10870}
10871
10872template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010873QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10874 SourceLocation Loc) {
10875 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010876}
10877
10878template<typename Derived>
10879QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10880 return SemaRef.Context.getTypeOfType(Underlying);
10881}
10882
10883template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010884QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10885 SourceLocation Loc) {
10886 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010887}
10888
10889template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010890QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10891 UnaryTransformType::UTTKind UKind,
10892 SourceLocation Loc) {
10893 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10894}
10895
10896template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010897QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010898 TemplateName Template,
10899 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010900 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010901 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010902}
Mike Stump11289f42009-09-09 15:08:12 +000010903
Douglas Gregor1135c352009-08-06 05:28:30 +000010904template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010905QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10906 SourceLocation KWLoc) {
10907 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10908}
10909
10910template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010911TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010912TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010913 bool TemplateKW,
10914 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010915 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010916 Template);
10917}
10918
10919template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010920TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010921TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10922 const IdentifierInfo &Name,
10923 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010924 QualType ObjectType,
10925 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010926 UnqualifiedId TemplateName;
10927 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010928 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010929 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010930 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010931 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010932 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010933 /*EnteringContext=*/false,
10934 Template);
John McCall31f82722010-11-12 08:19:04 +000010935 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010936}
Mike Stump11289f42009-09-09 15:08:12 +000010937
Douglas Gregora16548e2009-08-11 05:31:07 +000010938template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010939TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010940TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010941 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010942 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010943 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010944 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010945 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010946 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010947 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010948 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010949 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010950 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010951 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010952 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010953 /*EnteringContext=*/false,
10954 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010955 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010956}
Chad Rosier1dcde962012-08-08 18:46:20 +000010957
Douglas Gregor71395fa2009-11-04 00:56:37 +000010958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010959ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010960TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10961 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010962 Expr *OrigCallee,
10963 Expr *First,
10964 Expr *Second) {
10965 Expr *Callee = OrigCallee->IgnoreParenCasts();
10966 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010967
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010968 if (First->getObjectKind() == OK_ObjCProperty) {
10969 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10970 if (BinaryOperator::isAssignmentOp(Opc))
10971 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10972 First, Second);
10973 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10974 if (Result.isInvalid())
10975 return ExprError();
10976 First = Result.get();
10977 }
10978
10979 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10980 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10981 if (Result.isInvalid())
10982 return ExprError();
10983 Second = Result.get();
10984 }
10985
Douglas Gregora16548e2009-08-11 05:31:07 +000010986 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010987 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010988 if (!First->getType()->isOverloadableType() &&
10989 !Second->getType()->isOverloadableType())
10990 return getSema().CreateBuiltinArraySubscriptExpr(First,
10991 Callee->getLocStart(),
10992 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010993 } else if (Op == OO_Arrow) {
10994 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010995 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10996 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000010997 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010998 // The argument is not of overloadable type, so try to create a
10999 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011000 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011001 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011002
John McCallb268a282010-08-23 23:25:46 +000011003 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011004 }
11005 } else {
John McCallb268a282010-08-23 23:25:46 +000011006 if (!First->getType()->isOverloadableType() &&
11007 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011008 // Neither of the arguments is an overloadable type, so try to
11009 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011010 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011011 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011012 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011013 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011015
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011016 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011017 }
11018 }
Mike Stump11289f42009-09-09 15:08:12 +000011019
11020 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011021 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011022 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011023
John McCallb268a282010-08-23 23:25:46 +000011024 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011025 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011026 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011027 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011028 // If we've resolved this to a particular non-member function, just call
11029 // that function. If we resolved it to a member function,
11030 // CreateOverloaded* will find that function for us.
11031 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11032 if (!isa<CXXMethodDecl>(ND))
11033 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011034 }
Mike Stump11289f42009-09-09 15:08:12 +000011035
Douglas Gregora16548e2009-08-11 05:31:07 +000011036 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011037 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011038 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011039
Douglas Gregora16548e2009-08-11 05:31:07 +000011040 // Create the overloaded operator invocation for unary operators.
11041 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011042 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011043 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011044 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011045 }
Mike Stump11289f42009-09-09 15:08:12 +000011046
Douglas Gregore9d62932011-07-15 16:25:15 +000011047 if (Op == OO_Subscript) {
11048 SourceLocation LBrace;
11049 SourceLocation RBrace;
11050
11051 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011052 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011053 LBrace = SourceLocation::getFromRawEncoding(
11054 NameLoc.CXXOperatorName.BeginOpNameLoc);
11055 RBrace = SourceLocation::getFromRawEncoding(
11056 NameLoc.CXXOperatorName.EndOpNameLoc);
11057 } else {
11058 LBrace = Callee->getLocStart();
11059 RBrace = OpLoc;
11060 }
11061
11062 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11063 First, Second);
11064 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011065
Douglas Gregora16548e2009-08-11 05:31:07 +000011066 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011067 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011068 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011069 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11070 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011071 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011072
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011073 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011074}
Mike Stump11289f42009-09-09 15:08:12 +000011075
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011076template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011077ExprResult
John McCallb268a282010-08-23 23:25:46 +000011078TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011079 SourceLocation OperatorLoc,
11080 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011081 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011082 TypeSourceInfo *ScopeType,
11083 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011084 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011085 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011086 QualType BaseType = Base->getType();
11087 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011088 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011089 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011090 !BaseType->getAs<PointerType>()->getPointeeType()
11091 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011092 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011093 return SemaRef.BuildPseudoDestructorExpr(
11094 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11095 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011096 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011097
Douglas Gregor678f90d2010-02-25 01:56:36 +000011098 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011099 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11100 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11101 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11102 NameInfo.setNamedTypeInfo(DestroyedType);
11103
Richard Smith8e4a3862012-05-15 06:15:11 +000011104 // The scope type is now known to be a valid nested name specifier
11105 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011106 if (ScopeType) {
11107 if (!ScopeType->getType()->getAs<TagType>()) {
11108 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11109 diag::err_expected_class_or_namespace)
11110 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11111 return ExprError();
11112 }
11113 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11114 CCLoc);
11115 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011116
Abramo Bagnara7945c982012-01-27 09:46:47 +000011117 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011118 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011119 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011120 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011121 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011122 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011123 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011124}
11125
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011126template<typename Derived>
11127StmtResult
11128TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011129 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011130 CapturedDecl *CD = S->getCapturedDecl();
11131 unsigned NumParams = CD->getNumParams();
11132 unsigned ContextParamPos = CD->getContextParamPosition();
11133 SmallVector<Sema::CapturedParamNameType, 4> Params;
11134 for (unsigned I = 0; I < NumParams; ++I) {
11135 if (I != ContextParamPos) {
11136 Params.push_back(
11137 std::make_pair(
11138 CD->getParam(I)->getName(),
11139 getDerived().TransformType(CD->getParam(I)->getType())));
11140 } else {
11141 Params.push_back(std::make_pair(StringRef(), QualType()));
11142 }
11143 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011144 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011145 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011146 StmtResult Body;
11147 {
11148 Sema::CompoundScopeRAII CompoundScope(getSema());
11149 Body = getDerived().TransformStmt(S->getCapturedStmt());
11150 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011151
11152 if (Body.isInvalid()) {
11153 getSema().ActOnCapturedRegionError();
11154 return StmtError();
11155 }
11156
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011157 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011158}
11159
Douglas Gregord6ff3322009-08-04 16:50:30 +000011160} // end namespace clang
11161
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011162#endif