blob: 7cc7b7797245f99fb2054e6c45e28444059df371 [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,
Alexey Bataev182227b2015-08-20 10:54:39 +00001531 OpenMPLinearClauseKind Modifier,
1532 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001533 SourceLocation ColonLoc,
1534 SourceLocation EndLoc) {
1535 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001536 Modifier, ModifierLoc, ColonLoc,
1537 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001538 }
1539
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001540 /// \brief Build a new OpenMP 'aligned' clause.
1541 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001542 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation ColonLoc,
1548 SourceLocation EndLoc) {
1549 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1550 LParenLoc, ColonLoc, EndLoc);
1551 }
1552
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001553 /// \brief Build a new OpenMP 'copyin' clause.
1554 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001555 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001556 /// Subclasses may override this routine to provide different behavior.
1557 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1558 SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1562 EndLoc);
1563 }
1564
Alexey Bataevbae9a792014-06-27 10:37:06 +00001565 /// \brief Build a new OpenMP 'copyprivate' clause.
1566 ///
1567 /// By default, performs semantic analysis to build the new OpenMP clause.
1568 /// Subclasses may override this routine to provide different behavior.
1569 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
1572 SourceLocation EndLoc) {
1573 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1574 EndLoc);
1575 }
1576
Alexey Bataev6125da92014-07-21 11:26:11 +00001577 /// \brief Build a new OpenMP 'flush' pseudo clause.
1578 ///
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1582 SourceLocation StartLoc,
1583 SourceLocation LParenLoc,
1584 SourceLocation EndLoc) {
1585 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1586 EndLoc);
1587 }
1588
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001589 /// \brief Build a new OpenMP 'depend' pseudo clause.
1590 ///
1591 /// By default, performs semantic analysis to build the new OpenMP clause.
1592 /// Subclasses may override this routine to provide different behavior.
1593 OMPClause *
1594 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1595 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1596 SourceLocation StartLoc, SourceLocation LParenLoc,
1597 SourceLocation EndLoc) {
1598 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1599 StartLoc, LParenLoc, EndLoc);
1600 }
1601
Michael Wonge710d542015-08-07 16:16:36 +00001602 /// \brief Build a new OpenMP 'device' clause.
1603 ///
1604 /// By default, performs semantic analysis to build the new statement.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1610 EndLoc);
1611 }
1612
James Dennett2a4d13c2012-06-15 07:13:21 +00001613 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001614 ///
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1618 Expr *object) {
1619 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1620 }
1621
James Dennett2a4d13c2012-06-15 07:13:21 +00001622 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001623 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001624 /// By default, performs semantic analysis to build the new statement.
1625 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001626 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001627 Expr *Object, Stmt *Body) {
1628 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001629 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001630
James Dennett2a4d13c2012-06-15 07:13:21 +00001631 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1635 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1636 Stmt *Body) {
1637 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1638 }
John McCall53848232011-07-27 01:07:15 +00001639
Douglas Gregorf68a5082010-04-22 23:10:45 +00001640 /// \brief Build a new Objective-C fast enumeration statement.
1641 ///
1642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001644 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001645 Stmt *Element,
1646 Expr *Collection,
1647 SourceLocation RParenLoc,
1648 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001649 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001650 Element,
John McCallb268a282010-08-23 23:25:46 +00001651 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001652 RParenLoc);
1653 if (ForEachStmt.isInvalid())
1654 return StmtError();
1655
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001656 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001658
Douglas Gregorebe10102009-08-20 07:17:43 +00001659 /// \brief Build a new C++ exception declaration.
1660 ///
1661 /// By default, performs semantic analysis to build the new decaration.
1662 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001663 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001664 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001665 SourceLocation StartLoc,
1666 SourceLocation IdLoc,
1667 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001668 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001669 StartLoc, IdLoc, Id);
1670 if (Var)
1671 getSema().CurContext->addDecl(Var);
1672 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 }
1674
1675 /// \brief Build a new C++ catch statement.
1676 ///
1677 /// By default, performs semantic analysis to build the new statement.
1678 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001679 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001680 VarDecl *ExceptionDecl,
1681 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001682 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1683 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001684 }
Mike Stump11289f42009-09-09 15:08:12 +00001685
Douglas Gregorebe10102009-08-20 07:17:43 +00001686 /// \brief Build a new C++ try statement.
1687 ///
1688 /// By default, performs semantic analysis to build the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001690 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1691 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001692 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001693 }
Mike Stump11289f42009-09-09 15:08:12 +00001694
Richard Smith02e85f32011-04-14 22:09:26 +00001695 /// \brief Build a new C++0x range-based for statement.
1696 ///
1697 /// By default, performs semantic analysis to build the new statement.
1698 /// Subclasses may override this routine to provide different behavior.
1699 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1700 SourceLocation ColonLoc,
1701 Stmt *Range, Stmt *BeginEnd,
1702 Expr *Cond, Expr *Inc,
1703 Stmt *LoopVar,
1704 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001705 // If we've just learned that the range is actually an Objective-C
1706 // collection, treat this as an Objective-C fast enumeration loop.
1707 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1708 if (RangeStmt->isSingleDecl()) {
1709 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001710 if (RangeVar->isInvalidDecl())
1711 return StmtError();
1712
Douglas Gregorf7106af2013-04-08 18:40:13 +00001713 Expr *RangeExpr = RangeVar->getInit();
1714 if (!RangeExpr->isTypeDependent() &&
1715 RangeExpr->getType()->isObjCObjectPointerType())
1716 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1717 RParenLoc);
1718 }
1719 }
1720 }
1721
Richard Smith02e85f32011-04-14 22:09:26 +00001722 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001723 Cond, Inc, LoopVar, RParenLoc,
1724 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001725 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001726
1727 /// \brief Build a new C++0x range-based for statement.
1728 ///
1729 /// By default, performs semantic analysis to build the new statement.
1730 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001731 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001732 bool IsIfExists,
1733 NestedNameSpecifierLoc QualifierLoc,
1734 DeclarationNameInfo NameInfo,
1735 Stmt *Nested) {
1736 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1737 QualifierLoc, NameInfo, Nested);
1738 }
1739
Richard Smith02e85f32011-04-14 22:09:26 +00001740 /// \brief Attach body to a C++0x range-based for statement.
1741 ///
1742 /// By default, performs semantic analysis to finish the new statement.
1743 /// Subclasses may override this routine to provide different behavior.
1744 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1745 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001747
David Majnemerfad8f482013-10-15 09:33:02 +00001748 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001749 Stmt *TryBlock, Stmt *Handler) {
1750 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001751 }
1752
David Majnemerfad8f482013-10-15 09:33:02 +00001753 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001754 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001755 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001756 }
1757
David Majnemerfad8f482013-10-15 09:33:02 +00001758 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001759 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001760 }
1761
Alexey Bataevec474782014-10-09 08:45:04 +00001762 /// \brief Build a new predefined expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
1766 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1767 PredefinedExpr::IdentType IT) {
1768 return getSema().BuildPredefinedExpr(Loc, IT);
1769 }
1770
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// \brief Build a new expression that references a declaration.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001776 LookupResult &R,
1777 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001778 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1779 }
1780
1781
1782 /// \brief Build a new expression that references a declaration.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001786 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001787 ValueDecl *VD,
1788 const DeclarationNameInfo &NameInfo,
1789 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001790 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001791 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001792
1793 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001794
1795 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 }
Mike Stump11289f42009-09-09 15:08:12 +00001797
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001799 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001802 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001804 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
1806
Douglas Gregorad8a3362009-09-04 17:36:40 +00001807 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001808 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001812 SourceLocation OperatorLoc,
1813 bool isArrow,
1814 CXXScopeSpec &SS,
1815 TypeSourceInfo *ScopeType,
1816 SourceLocation CCLoc,
1817 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001818 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001819
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001821 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001824 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001825 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001826 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001827 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregor882211c2010-04-28 22:16:22 +00001830 /// \brief Build a new builtin offsetof expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001835 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001836 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001837 unsigned NumComponents,
1838 SourceLocation RParenLoc) {
1839 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1840 NumComponents, RParenLoc);
1841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001842
1843 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001844 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001845 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001848 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1849 SourceLocation OpLoc,
1850 UnaryExprOrTypeTrait ExprKind,
1851 SourceRange R) {
1852 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 }
1854
Peter Collingbournee190dee2011-03-11 19:24:49 +00001855 /// \brief Build a new sizeof, alignof or vec step expression with an
1856 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001857 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001860 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1861 UnaryExprOrTypeTrait ExprKind,
1862 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001863 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001864 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001867
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001868 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001875 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001877 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001879 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001880 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 RBracketLoc);
1882 }
1883
1884 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001885 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001888 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001890 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001891 Expr *ExecConfig = nullptr) {
1892 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001893 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 }
1895
1896 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001897 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001901 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001902 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001903 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001904 const DeclarationNameInfo &MemberNameInfo,
1905 ValueDecl *Member,
1906 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001907 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001908 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001909 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1910 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001911 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001912 // We have a reference to an unnamed field. This is always the
1913 // base of an anonymous struct/union member access, i.e. the
1914 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001915 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001916 assert(Member->getType()->isRecordType() &&
1917 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001918
Richard Smithcab9a7d2011-10-26 19:06:56 +00001919 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001920 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001921 QualifierLoc.getNestedNameSpecifier(),
1922 FoundDecl, Member);
1923 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001924 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001925 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001926 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001927 MemberExpr *ME = new (getSema().Context)
1928 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1929 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001930 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001931 }
Mike Stump11289f42009-09-09 15:08:12 +00001932
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001933 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001934 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001935
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001936 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001937 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001938
John McCall16df1e52010-03-30 21:47:33 +00001939 // FIXME: this involves duplicating earlier analysis in a lot of
1940 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001941 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001942 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001943 R.resolveKind();
1944
John McCallb268a282010-08-23 23:25:46 +00001945 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001946 SS, TemplateKWLoc,
1947 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001948 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 }
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001952 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001955 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001956 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001957 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001958 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001962 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 /// By default, performs semantic analysis to build the new expression.
1964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001965 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001966 SourceLocation QuestionLoc,
1967 Expr *LHS,
1968 SourceLocation ColonLoc,
1969 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001970 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1971 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 }
1973
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001975 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001979 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001981 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001982 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001983 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 }
Mike Stump11289f42009-09-09 15:08:12 +00001985
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001987 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001988 /// By default, performs semantic analysis to build the new expression.
1989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001990 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001991 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001992 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001993 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001994 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001995 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001999 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// By default, performs semantic analysis to build the new expression.
2001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002002 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation OpLoc,
2004 SourceLocation AccessorLoc,
2005 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002006
John McCall10eae182009-11-30 22:42:35 +00002007 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002008 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002009 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002010 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002011 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002012 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002013 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002014 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002022 MultiExprArg Inits,
2023 SourceLocation RBraceLoc,
2024 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002026 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002027 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002028 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002029
Douglas Gregord3d93062009-11-09 17:16:50 +00002030 // Patch in the result type we were given, which may have been computed
2031 // when the initial InitListExpr was built.
2032 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2033 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002034 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 }
Mike Stump11289f42009-09-09 15:08:12 +00002036
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002039 /// By default, performs semantic analysis to build the new expression.
2040 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 MultiExprArg ArrayExprs,
2043 SourceLocation EqualOrColonLoc,
2044 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002045 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002048 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002050 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002051
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002052 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002053 }
Mike Stump11289f42009-09-09 15:08:12 +00002054
Douglas Gregora16548e2009-08-11 05:31:07 +00002055 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002056 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002057 /// By default, builds the implicit value initialization without performing
2058 /// any semantic analysis. Subclasses may override this routine to provide
2059 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002061 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Douglas Gregora16548e2009-08-11 05:31:07 +00002064 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002065 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002070 SourceLocation RParenLoc) {
2071 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002072 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002073 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 }
2075
2076 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002080 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002081 MultiExprArg SubExprs,
2082 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002083 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002087 ///
2088 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// rather than attempting to map the label statement itself.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002092 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002093 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002101 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002103 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 /// \brief Build a new __builtin_choose_expr expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002110 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002111 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 SourceLocation RParenLoc) {
2113 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002114 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 RParenLoc);
2116 }
Mike Stump11289f42009-09-09 15:08:12 +00002117
Peter Collingbourne91147592011-04-15 00:35:48 +00002118 /// \brief Build a new generic selection expression.
2119 ///
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
2122 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2123 SourceLocation DefaultLoc,
2124 SourceLocation RParenLoc,
2125 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002126 ArrayRef<TypeSourceInfo *> Types,
2127 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002128 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002129 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002130 }
2131
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 /// \brief Build a new overloaded operator call expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// The semantic analysis provides the behavior of template instantiation,
2136 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002137 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// argument-dependent lookup, etc. Subclasses may override this routine to
2139 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *Callee,
2143 Expr *First,
2144 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002145
2146 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 /// reinterpret_cast.
2148 ///
2149 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002150 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 Stmt::StmtClass Class,
2154 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002155 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 SourceLocation RAngleLoc,
2157 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002158 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 SourceLocation RParenLoc) {
2160 switch (Class) {
2161 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002162 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002163 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002164 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002165
2166 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002167 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002168 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002169 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002172 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002173 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002174 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002178 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002179 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002180 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002181
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002183 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 }
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 /// \brief Build a new C++ static_cast expression.
2188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002193 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RAngleLoc,
2195 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002196 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002198 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002199 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002200 SourceRange(LAngleLoc, RAngleLoc),
2201 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 }
2203
2204 /// \brief Build a new C++ dynamic_cast expression.
2205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002208 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002210 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 SourceLocation RAngleLoc,
2212 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002213 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002215 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002216 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002217 SourceRange(LAngleLoc, RAngleLoc),
2218 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 }
2220
2221 /// \brief Build a new C++ reinterpret_cast expression.
2222 ///
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002225 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002227 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 SourceLocation RAngleLoc,
2229 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002230 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002232 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002233 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002234 SourceRange(LAngleLoc, RAngleLoc),
2235 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 }
2237
2238 /// \brief Build a new C++ const_cast expression.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002242 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002244 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 SourceLocation RAngleLoc,
2246 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002247 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002249 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002250 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002251 SourceRange(LAngleLoc, RAngleLoc),
2252 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 }
Mike Stump11289f42009-09-09 15:08:12 +00002254
Douglas Gregora16548e2009-08-11 05:31:07 +00002255 /// \brief Build a new C++ functional-style cast expression.
2256 ///
2257 /// By default, performs semantic analysis to build the new expression.
2258 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002259 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2260 SourceLocation LParenLoc,
2261 Expr *Sub,
2262 SourceLocation RParenLoc) {
2263 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002264 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 RParenLoc);
2266 }
Mike Stump11289f42009-09-09 15:08:12 +00002267
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 /// \brief Build a new C++ typeid(type) expression.
2269 ///
2270 /// By default, performs semantic analysis to build the new expression.
2271 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002272 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002273 SourceLocation TypeidLoc,
2274 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002276 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002277 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 }
Mike Stump11289f42009-09-09 15:08:12 +00002279
Francois Pichet9f4f2072010-09-08 12:20:18 +00002280
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 /// \brief Build a new C++ typeid(expr) expression.
2282 ///
2283 /// By default, performs semantic analysis to build the new expression.
2284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002285 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002286 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002287 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002289 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002290 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002291 }
2292
Francois Pichet9f4f2072010-09-08 12:20:18 +00002293 /// \brief Build a new C++ __uuidof(type) expression.
2294 ///
2295 /// By default, performs semantic analysis to build the new expression.
2296 /// Subclasses may override this routine to provide different behavior.
2297 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2298 SourceLocation TypeidLoc,
2299 TypeSourceInfo *Operand,
2300 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002301 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002302 RParenLoc);
2303 }
2304
2305 /// \brief Build a new C++ __uuidof(expr) expression.
2306 ///
2307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
2309 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2310 SourceLocation TypeidLoc,
2311 Expr *Operand,
2312 SourceLocation RParenLoc) {
2313 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2314 RParenLoc);
2315 }
2316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new C++ "this" expression.
2318 ///
2319 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002320 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002322 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002323 QualType ThisType,
2324 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002325 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002326 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 }
2328
2329 /// \brief Build a new C++ throw expression.
2330 ///
2331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002333 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2334 bool IsThrownVariableInScope) {
2335 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 }
2337
2338 /// \brief Build a new C++ default-argument expression.
2339 ///
2340 /// By default, builds a new default-argument expression, which does not
2341 /// require any semantic analysis. Subclasses may override this routine to
2342 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002343 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002344 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002345 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 }
2347
Richard Smith852c9db2013-04-20 22:23:05 +00002348 /// \brief Build a new C++11 default-initialization expression.
2349 ///
2350 /// By default, builds a new default field initialization expression, which
2351 /// does not require any semantic analysis. Subclasses may override this
2352 /// routine to provide different behavior.
2353 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2354 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002355 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002356 }
2357
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 /// \brief Build a new C++ zero-initialization expression.
2359 ///
2360 /// By default, performs semantic analysis to build the new expression.
2361 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002362 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2363 SourceLocation LParenLoc,
2364 SourceLocation RParenLoc) {
2365 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002366 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 }
Mike Stump11289f42009-09-09 15:08:12 +00002368
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 /// \brief Build a new C++ "new" expression.
2370 ///
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002373 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002374 bool UseGlobal,
2375 SourceLocation PlacementLParen,
2376 MultiExprArg PlacementArgs,
2377 SourceLocation PlacementRParen,
2378 SourceRange TypeIdParens,
2379 QualType AllocatedType,
2380 TypeSourceInfo *AllocatedTypeInfo,
2381 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002382 SourceRange DirectInitRange,
2383 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002384 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002385 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002386 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002388 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002389 AllocatedType,
2390 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002391 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002392 DirectInitRange,
2393 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 }
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 /// \brief Build a new C++ "delete" expression.
2397 ///
2398 /// By default, performs semantic analysis to build the new expression.
2399 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002400 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 bool IsGlobalDelete,
2402 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002403 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002405 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 }
Mike Stump11289f42009-09-09 15:08:12 +00002407
Douglas Gregor29c42f22012-02-24 07:38:34 +00002408 /// \brief Build a new type trait expression.
2409 ///
2410 /// By default, performs semantic analysis to build the new expression.
2411 /// Subclasses may override this routine to provide different behavior.
2412 ExprResult RebuildTypeTrait(TypeTrait Trait,
2413 SourceLocation StartLoc,
2414 ArrayRef<TypeSourceInfo *> Args,
2415 SourceLocation RParenLoc) {
2416 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002418
John Wiegley6242b6a2011-04-28 00:16:57 +00002419 /// \brief Build a new array type trait expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
2423 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2424 SourceLocation StartLoc,
2425 TypeSourceInfo *TSInfo,
2426 Expr *DimExpr,
2427 SourceLocation RParenLoc) {
2428 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2429 }
2430
John Wiegleyf9f65842011-04-25 06:54:41 +00002431 /// \brief Build a new expression trait expression.
2432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
2435 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2436 SourceLocation StartLoc,
2437 Expr *Queried,
2438 SourceLocation RParenLoc) {
2439 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2440 }
2441
Mike Stump11289f42009-09-09 15:08:12 +00002442 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 /// expression.
2444 ///
2445 /// By default, performs semantic analysis to build the new expression.
2446 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002447 ExprResult RebuildDependentScopeDeclRefExpr(
2448 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002449 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002450 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002451 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002452 bool IsAddressOfOperand,
2453 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002455 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002456
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002457 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002458 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2459 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002460
Reid Kleckner32506ed2014-06-12 23:03:48 +00002461 return getSema().BuildQualifiedDeclarationNameExpr(
2462 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 }
2464
2465 /// \brief Build a new template-id expression.
2466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002469 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002470 SourceLocation TemplateKWLoc,
2471 LookupResult &R,
2472 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002473 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002474 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2475 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 }
2477
2478 /// \brief Build a new object-construction expression.
2479 ///
2480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002482 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002483 SourceLocation Loc,
2484 CXXConstructorDecl *Constructor,
2485 bool IsElidable,
2486 MultiExprArg Args,
2487 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002488 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002489 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002490 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002491 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002492 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002493 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002494 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002495 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002496 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002497
Douglas Gregordb121ba2009-12-14 16:27:04 +00002498 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002499 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002500 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002501 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002502 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002503 RequiresZeroInit, ConstructKind,
2504 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 }
2506
2507 /// \brief Build a new object-construction expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002511 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2512 SourceLocation LParenLoc,
2513 MultiExprArg Args,
2514 SourceLocation RParenLoc) {
2515 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002517 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002518 RParenLoc);
2519 }
2520
2521 /// \brief Build a new object-construction expression.
2522 ///
2523 /// By default, performs semantic analysis to build the new expression.
2524 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002525 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2526 SourceLocation LParenLoc,
2527 MultiExprArg Args,
2528 SourceLocation RParenLoc) {
2529 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002531 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 RParenLoc);
2533 }
Mike Stump11289f42009-09-09 15:08:12 +00002534
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 /// \brief Build a new member reference expression.
2536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002539 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002540 QualType BaseType,
2541 bool IsArrow,
2542 SourceLocation OperatorLoc,
2543 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002544 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002545 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002546 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002547 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002549 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002550
John McCallb268a282010-08-23 23:25:46 +00002551 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002552 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002553 SS, TemplateKWLoc,
2554 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002555 MemberNameInfo,
2556 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 }
2558
John McCall10eae182009-11-30 22:42:35 +00002559 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002560 ///
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002563 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2564 SourceLocation OperatorLoc,
2565 bool IsArrow,
2566 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002567 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002568 NamedDecl *FirstQualifierInScope,
2569 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002570 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002571 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002572 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002573
John McCallb268a282010-08-23 23:25:46 +00002574 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002575 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002576 SS, TemplateKWLoc,
2577 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002578 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002579 }
Mike Stump11289f42009-09-09 15:08:12 +00002580
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002581 /// \brief Build a new noexcept expression.
2582 ///
2583 /// By default, performs semantic analysis to build the new expression.
2584 /// Subclasses may override this routine to provide different behavior.
2585 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2586 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2587 }
2588
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002589 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002590 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2591 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002592 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002593 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002594 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002595 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2596 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002597 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002598
2599 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2600 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002601 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002602 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002603
Patrick Beard0caa3942012-04-19 00:25:12 +00002604 /// \brief Build a new Objective-C boxed expression.
2605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
2608 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2609 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002611
Ted Kremeneke65b0862012-03-06 20:05:56 +00002612 /// \brief Build a new Objective-C array literal.
2613 ///
2614 /// By default, performs semantic analysis to build the new expression.
2615 /// Subclasses may override this routine to provide different behavior.
2616 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2617 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002618 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002619 MultiExprArg(Elements, NumElements));
2620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002621
2622 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002623 Expr *Base, Expr *Key,
2624 ObjCMethodDecl *getterMethod,
2625 ObjCMethodDecl *setterMethod) {
2626 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2627 getterMethod, setterMethod);
2628 }
2629
2630 /// \brief Build a new Objective-C dictionary literal.
2631 ///
2632 /// By default, performs semantic analysis to build the new expression.
2633 /// Subclasses may override this routine to provide different behavior.
2634 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2635 ObjCDictionaryElement *Elements,
2636 unsigned NumElements) {
2637 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2638 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002639
James Dennett2a4d13c2012-06-15 07:13:21 +00002640 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002641 ///
2642 /// By default, performs semantic analysis to build the new expression.
2643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002644 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002645 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002646 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002647 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002648 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002649
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002650 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002651 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002652 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002653 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002654 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002655 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002656 MultiExprArg Args,
2657 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002658 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2659 ReceiverTypeInfo->getType(),
2660 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002661 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002662 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002663 }
2664
2665 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002666 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002667 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002668 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002669 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002670 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002671 MultiExprArg Args,
2672 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002673 return SemaRef.BuildInstanceMessage(Receiver,
2674 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002675 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002676 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002677 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002678 }
2679
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002680 /// \brief Build a new Objective-C instance/class message to 'super'.
2681 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2682 Selector Sel,
2683 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002684 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002685 ObjCMethodDecl *Method,
2686 SourceLocation LBracLoc,
2687 MultiExprArg Args,
2688 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002689 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002690 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002691 SuperLoc,
2692 Sel, Method, LBracLoc, SelectorLocs,
2693 RBracLoc, Args)
2694 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002695 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002696 SuperLoc,
2697 Sel, Method, LBracLoc, SelectorLocs,
2698 RBracLoc, Args);
2699
2700
2701 }
2702
Douglas Gregord51d90d2010-04-26 20:11:03 +00002703 /// \brief Build a new Objective-C ivar reference expression.
2704 ///
2705 /// By default, performs semantic analysis to build the new expression.
2706 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002707 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002708 SourceLocation IvarLoc,
2709 bool IsArrow, bool IsFreeIvar) {
2710 // FIXME: We lose track of the IsFreeIvar bit.
2711 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002712 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2713 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002714 /*FIXME:*/IvarLoc, IsArrow,
2715 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002716 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002717 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002718 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002719 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002720
2721 /// \brief Build a new Objective-C property reference expression.
2722 ///
2723 /// By default, performs semantic analysis to build the new expression.
2724 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002725 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002726 ObjCPropertyDecl *Property,
2727 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002728 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002729 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2730 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2731 /*FIXME:*/PropertyLoc,
2732 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002733 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002734 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002735 NameInfo,
2736 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002738
John McCallb7bd14f2010-12-02 01:19:52 +00002739 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002740 ///
2741 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002742 /// Subclasses may override this routine to provide different behavior.
2743 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2744 ObjCMethodDecl *Getter,
2745 ObjCMethodDecl *Setter,
2746 SourceLocation PropertyLoc) {
2747 // Since these expressions can only be value-dependent, we do not
2748 // need to perform semantic analysis again.
2749 return Owned(
2750 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2751 VK_LValue, OK_ObjCProperty,
2752 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002753 }
2754
Douglas Gregord51d90d2010-04-26 20:11:03 +00002755 /// \brief Build a new Objective-C "isa" expression.
2756 ///
2757 /// By default, performs semantic analysis to build the new expression.
2758 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002759 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002760 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002761 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002762 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2763 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002764 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002765 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002766 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002767 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002768 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002770
Douglas Gregora16548e2009-08-11 05:31:07 +00002771 /// \brief Build a new shuffle vector expression.
2772 ///
2773 /// By default, performs semantic analysis to build the new expression.
2774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002775 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002776 MultiExprArg SubExprs,
2777 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002778 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002779 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002780 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2781 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2782 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002783 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002784
Douglas Gregora16548e2009-08-11 05:31:07 +00002785 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002786 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002787 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2788 SemaRef.Context.BuiltinFnTy,
2789 VK_RValue, BuiltinLoc);
2790 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2791 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002792 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002793
2794 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002795 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002796 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002797 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002798
Douglas Gregora16548e2009-08-11 05:31:07 +00002799 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002800 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002801 }
John McCall31f82722010-11-12 08:19:04 +00002802
Hal Finkelc4d7c822013-09-18 03:29:45 +00002803 /// \brief Build a new convert vector expression.
2804 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2805 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2806 SourceLocation RParenLoc) {
2807 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2808 BuiltinLoc, RParenLoc);
2809 }
2810
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002811 /// \brief Build a new template argument pack expansion.
2812 ///
2813 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002814 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002815 /// different behavior.
2816 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002817 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002818 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002819 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002820 case TemplateArgument::Expression: {
2821 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002822 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2823 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002824 if (Result.isInvalid())
2825 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002826
Douglas Gregor98318c22011-01-03 21:37:45 +00002827 return TemplateArgumentLoc(Result.get(), Result.get());
2828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002829
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002830 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002831 return TemplateArgumentLoc(TemplateArgument(
2832 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002833 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002834 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002835 Pattern.getTemplateNameLoc(),
2836 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002837
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002838 case TemplateArgument::Null:
2839 case TemplateArgument::Integral:
2840 case TemplateArgument::Declaration:
2841 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002842 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002843 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002844 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002845
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002846 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002847 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002848 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002849 EllipsisLoc,
2850 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002851 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2852 Expansion);
2853 break;
2854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002855
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002856 return TemplateArgumentLoc();
2857 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
Douglas Gregor968f23a2011-01-03 19:31:53 +00002859 /// \brief Build a new expression pack expansion.
2860 ///
2861 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002862 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002863 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002864 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002865 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002866 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002867 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002868
Richard Smith0f0af192014-11-08 05:07:16 +00002869 /// \brief Build a new C++1z fold-expression.
2870 ///
2871 /// By default, performs semantic analysis in order to build a new fold
2872 /// expression.
2873 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2874 BinaryOperatorKind Operator,
2875 SourceLocation EllipsisLoc, Expr *RHS,
2876 SourceLocation RParenLoc) {
2877 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2878 RHS, RParenLoc);
2879 }
2880
2881 /// \brief Build an empty C++1z fold-expression with the given operator.
2882 ///
2883 /// By default, produces the fallback value for the fold-expression, or
2884 /// produce an error if there is no fallback value.
2885 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2886 BinaryOperatorKind Operator) {
2887 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2888 }
2889
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002890 /// \brief Build a new atomic operation expression.
2891 ///
2892 /// By default, performs semantic analysis to build the new expression.
2893 /// Subclasses may override this routine to provide different behavior.
2894 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2895 MultiExprArg SubExprs,
2896 QualType RetTy,
2897 AtomicExpr::AtomicOp Op,
2898 SourceLocation RParenLoc) {
2899 // Just create the expression; there is not any interesting semantic
2900 // analysis here because we can't actually build an AtomicExpr until
2901 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002902 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002903 RParenLoc);
2904 }
2905
John McCall31f82722010-11-12 08:19:04 +00002906private:
Douglas Gregor14454802011-02-25 02:25:35 +00002907 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2908 QualType ObjectType,
2909 NamedDecl *FirstQualifierInScope,
2910 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002911
2912 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2913 QualType ObjectType,
2914 NamedDecl *FirstQualifierInScope,
2915 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002916
2917 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2918 NamedDecl *FirstQualifierInScope,
2919 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920};
Douglas Gregora16548e2009-08-11 05:31:07 +00002921
Douglas Gregorebe10102009-08-20 07:17:43 +00002922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002923StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002924 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002925 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002926
Douglas Gregorebe10102009-08-20 07:17:43 +00002927 switch (S->getStmtClass()) {
2928 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002929
Douglas Gregorebe10102009-08-20 07:17:43 +00002930 // Transform individual statement nodes
2931#define STMT(Node, Parent) \
2932 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002933#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002934#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002935#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002936
Douglas Gregorebe10102009-08-20 07:17:43 +00002937 // Transform expressions by calling TransformExpr.
2938#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002939#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002940#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002941#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002942 {
John McCalldadc5752010-08-24 06:29:42 +00002943 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002944 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002945 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002946
Richard Smith945f8d32013-01-14 22:39:08 +00002947 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002948 }
Mike Stump11289f42009-09-09 15:08:12 +00002949 }
2950
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002951 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002952}
Mike Stump11289f42009-09-09 15:08:12 +00002953
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002954template<typename Derived>
2955OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2956 if (!S)
2957 return S;
2958
2959 switch (S->getClauseKind()) {
2960 default: break;
2961 // Transform individual clause nodes
2962#define OPENMP_CLAUSE(Name, Class) \
2963 case OMPC_ ## Name : \
2964 return getDerived().Transform ## Class(cast<Class>(S));
2965#include "clang/Basic/OpenMPKinds.def"
2966 }
2967
2968 return S;
2969}
2970
Mike Stump11289f42009-09-09 15:08:12 +00002971
Douglas Gregore922c772009-08-04 22:27:00 +00002972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002973ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002974 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002975 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002976
2977 switch (E->getStmtClass()) {
2978 case Stmt::NoStmtClass: break;
2979#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002980#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002981#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002982 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002983#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002984 }
2985
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002986 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002987}
2988
2989template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00002990ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00002991 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00002992 // Initializers are instantiated like expressions, except that various outer
2993 // layers are stripped.
2994 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002995 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00002996
2997 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2998 Init = ExprTemp->getSubExpr();
2999
Richard Smithe6ca4752013-05-30 22:40:16 +00003000 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3001 Init = MTE->GetTemporaryExpr();
3002
Richard Smithd59b8322012-12-19 01:39:02 +00003003 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3004 Init = Binder->getSubExpr();
3005
3006 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3007 Init = ICE->getSubExprAsWritten();
3008
Richard Smithcc1b96d2013-06-12 22:31:48 +00003009 if (CXXStdInitializerListExpr *ILE =
3010 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003011 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003012
Richard Smithc6abd962014-07-25 01:12:44 +00003013 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003014 // InitListExprs. Other forms of copy-initialization will be a no-op if
3015 // the initializer is already the right type.
3016 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003017 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003018 return getDerived().TransformExpr(Init);
3019
3020 // Revert value-initialization back to empty parens.
3021 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3022 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003023 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003024 Parens.getEnd());
3025 }
3026
3027 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3028 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003029 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003030 SourceLocation());
3031
3032 // Revert initialization by constructor back to a parenthesized or braced list
3033 // of expressions. Any other form of initializer can just be reused directly.
3034 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003035 return getDerived().TransformExpr(Init);
3036
Richard Smithf8adcdc2014-07-17 05:12:35 +00003037 // If the initialization implicitly converted an initializer list to a
3038 // std::initializer_list object, unwrap the std::initializer_list too.
3039 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003040 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003041
Richard Smithd59b8322012-12-19 01:39:02 +00003042 SmallVector<Expr*, 8> NewArgs;
3043 bool ArgChanged = false;
3044 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003045 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003046 return ExprError();
3047
3048 // If this was list initialization, revert to list form.
3049 if (Construct->isListInitialization())
3050 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3051 Construct->getLocEnd(),
3052 Construct->getType());
3053
Richard Smithd59b8322012-12-19 01:39:02 +00003054 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003055 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003056 if (Parens.isInvalid()) {
3057 // This was a variable declaration's initialization for which no initializer
3058 // was specified.
3059 assert(NewArgs.empty() &&
3060 "no parens or braces but have direct init with arguments?");
3061 return ExprEmpty();
3062 }
Richard Smithd59b8322012-12-19 01:39:02 +00003063 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3064 Parens.getEnd());
3065}
3066
3067template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003068bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3069 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003070 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003071 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003072 bool *ArgChanged) {
3073 for (unsigned I = 0; I != NumInputs; ++I) {
3074 // If requested, drop call arguments that need to be dropped.
3075 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3076 if (ArgChanged)
3077 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003078
Douglas Gregora3efea12011-01-03 19:04:46 +00003079 break;
3080 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003081
Douglas Gregor968f23a2011-01-03 19:31:53 +00003082 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3083 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003084
Chris Lattner01cf8db2011-07-20 06:58:45 +00003085 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003086 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3087 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003088
Douglas Gregor968f23a2011-01-03 19:31:53 +00003089 // Determine whether the set of unexpanded parameter packs can and should
3090 // be expanded.
3091 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003092 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003093 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3094 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003095 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3096 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003097 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003098 Expand, RetainExpansion,
3099 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003100 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregor968f23a2011-01-03 19:31:53 +00003102 if (!Expand) {
3103 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003104 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003105 // expansion.
3106 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3107 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3108 if (OutPattern.isInvalid())
3109 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
3111 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003112 Expansion->getEllipsisLoc(),
3113 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003114 if (Out.isInvalid())
3115 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Douglas Gregor968f23a2011-01-03 19:31:53 +00003117 if (ArgChanged)
3118 *ArgChanged = true;
3119 Outputs.push_back(Out.get());
3120 continue;
3121 }
John McCall542e7c62011-07-06 07:30:07 +00003122
3123 // Record right away that the argument was changed. This needs
3124 // to happen even if the array expands to nothing.
3125 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Douglas Gregor968f23a2011-01-03 19:31:53 +00003127 // The transform has determined that we should perform an elementwise
3128 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003129 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003130 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3131 ExprResult Out = getDerived().TransformExpr(Pattern);
3132 if (Out.isInvalid())
3133 return true;
3134
Richard Smith9467be42014-06-06 17:33:35 +00003135 // FIXME: Can this happen? We should not try to expand the pack
3136 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003137 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003138 Out = getDerived().RebuildPackExpansion(
3139 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003140 if (Out.isInvalid())
3141 return true;
3142 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Douglas Gregor968f23a2011-01-03 19:31:53 +00003144 Outputs.push_back(Out.get());
3145 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
Richard Smith9467be42014-06-06 17:33:35 +00003147 // If we're supposed to retain a pack expansion, do so by temporarily
3148 // forgetting the partially-substituted parameter pack.
3149 if (RetainExpansion) {
3150 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3151
3152 ExprResult Out = getDerived().TransformExpr(Pattern);
3153 if (Out.isInvalid())
3154 return true;
3155
3156 Out = getDerived().RebuildPackExpansion(
3157 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3158 if (Out.isInvalid())
3159 return true;
3160
3161 Outputs.push_back(Out.get());
3162 }
3163
Douglas Gregor968f23a2011-01-03 19:31:53 +00003164 continue;
3165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Richard Smithd59b8322012-12-19 01:39:02 +00003167 ExprResult Result =
3168 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3169 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003170 if (Result.isInvalid())
3171 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregora3efea12011-01-03 19:04:46 +00003173 if (Result.get() != Inputs[I] && ArgChanged)
3174 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
3176 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003177 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Douglas Gregora3efea12011-01-03 19:04:46 +00003179 return false;
3180}
3181
3182template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003183NestedNameSpecifierLoc
3184TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3185 NestedNameSpecifierLoc NNS,
3186 QualType ObjectType,
3187 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003188 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003189 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003190 Qualifier = Qualifier.getPrefix())
3191 Qualifiers.push_back(Qualifier);
3192
3193 CXXScopeSpec SS;
3194 while (!Qualifiers.empty()) {
3195 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3196 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Douglas Gregor14454802011-02-25 02:25:35 +00003198 switch (QNNS->getKind()) {
3199 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003200 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003201 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003202 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003203 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003204 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003205 FirstQualifierInScope, false))
3206 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
Douglas Gregor14454802011-02-25 02:25:35 +00003208 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003209
Douglas Gregor14454802011-02-25 02:25:35 +00003210 case NestedNameSpecifier::Namespace: {
3211 NamespaceDecl *NS
3212 = cast_or_null<NamespaceDecl>(
3213 getDerived().TransformDecl(
3214 Q.getLocalBeginLoc(),
3215 QNNS->getAsNamespace()));
3216 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3217 break;
3218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003219
Douglas Gregor14454802011-02-25 02:25:35 +00003220 case NestedNameSpecifier::NamespaceAlias: {
3221 NamespaceAliasDecl *Alias
3222 = cast_or_null<NamespaceAliasDecl>(
3223 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3224 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003226 Q.getLocalEndLoc());
3227 break;
3228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor14454802011-02-25 02:25:35 +00003230 case NestedNameSpecifier::Global:
3231 // There is no meaningful transformation that one could perform on the
3232 // global scope.
3233 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3234 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003235
Nikola Smiljanic67860242014-09-26 00:28:20 +00003236 case NestedNameSpecifier::Super: {
3237 CXXRecordDecl *RD =
3238 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3239 SourceLocation(), QNNS->getAsRecordDecl()));
3240 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3241 break;
3242 }
3243
Douglas Gregor14454802011-02-25 02:25:35 +00003244 case NestedNameSpecifier::TypeSpecWithTemplate:
3245 case NestedNameSpecifier::TypeSpec: {
3246 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3247 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003248
Douglas Gregor14454802011-02-25 02:25:35 +00003249 if (!TL)
3250 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003251
Douglas Gregor14454802011-02-25 02:25:35 +00003252 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003253 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003254 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003255 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003256 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003257 if (TL.getType()->isEnumeralType())
3258 SemaRef.Diag(TL.getBeginLoc(),
3259 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003260 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3261 Q.getLocalEndLoc());
3262 break;
3263 }
Richard Trieude756fb2011-05-07 01:36:37 +00003264 // If the nested-name-specifier is an invalid type def, don't emit an
3265 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003266 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3267 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003268 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003269 << TL.getType() << SS.getRange();
3270 }
Douglas Gregor14454802011-02-25 02:25:35 +00003271 return NestedNameSpecifierLoc();
3272 }
Douglas Gregore16af532011-02-28 18:50:33 +00003273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregore16af532011-02-28 18:50:33 +00003275 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003276 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003277 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003278 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregor14454802011-02-25 02:25:35 +00003280 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003281 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003282 !getDerived().AlwaysRebuild())
3283 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
3285 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003286 // nested-name-specifier, do so.
3287 if (SS.location_size() == NNS.getDataLength() &&
3288 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3289 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3290
3291 // Allocate new nested-name-specifier location information.
3292 return SS.getWithLocInContext(SemaRef.Context);
3293}
3294
3295template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003296DeclarationNameInfo
3297TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003298::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003299 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003300 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003301 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003302
3303 switch (Name.getNameKind()) {
3304 case DeclarationName::Identifier:
3305 case DeclarationName::ObjCZeroArgSelector:
3306 case DeclarationName::ObjCOneArgSelector:
3307 case DeclarationName::ObjCMultiArgSelector:
3308 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003309 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003310 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003311 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003312
Douglas Gregorf816bd72009-09-03 22:13:48 +00003313 case DeclarationName::CXXConstructorName:
3314 case DeclarationName::CXXDestructorName:
3315 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003316 TypeSourceInfo *NewTInfo;
3317 CanQualType NewCanTy;
3318 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003319 NewTInfo = getDerived().TransformType(OldTInfo);
3320 if (!NewTInfo)
3321 return DeclarationNameInfo();
3322 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003323 }
3324 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003325 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003326 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003327 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003328 if (NewT.isNull())
3329 return DeclarationNameInfo();
3330 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3331 }
Mike Stump11289f42009-09-09 15:08:12 +00003332
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003333 DeclarationName NewName
3334 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3335 NewCanTy);
3336 DeclarationNameInfo NewNameInfo(NameInfo);
3337 NewNameInfo.setName(NewName);
3338 NewNameInfo.setNamedTypeInfo(NewTInfo);
3339 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003340 }
Mike Stump11289f42009-09-09 15:08:12 +00003341 }
3342
David Blaikie83d382b2011-09-23 05:06:16 +00003343 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003344}
3345
3346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003347TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003348TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3349 TemplateName Name,
3350 SourceLocation NameLoc,
3351 QualType ObjectType,
3352 NamedDecl *FirstQualifierInScope) {
3353 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3354 TemplateDecl *Template = QTN->getTemplateDecl();
3355 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003356
Douglas Gregor9db53502011-03-02 18:07:45 +00003357 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003358 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003359 Template));
3360 if (!TransTemplate)
3361 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003362
Douglas Gregor9db53502011-03-02 18:07:45 +00003363 if (!getDerived().AlwaysRebuild() &&
3364 SS.getScopeRep() == QTN->getQualifier() &&
3365 TransTemplate == Template)
3366 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregor9db53502011-03-02 18:07:45 +00003368 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3369 TransTemplate);
3370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Douglas Gregor9db53502011-03-02 18:07:45 +00003372 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3373 if (SS.getScopeRep()) {
3374 // These apply to the scope specifier, not the template.
3375 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003376 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003377 }
3378
Douglas Gregor9db53502011-03-02 18:07:45 +00003379 if (!getDerived().AlwaysRebuild() &&
3380 SS.getScopeRep() == DTN->getQualifier() &&
3381 ObjectType.isNull())
3382 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003383
Douglas Gregor9db53502011-03-02 18:07:45 +00003384 if (DTN->isIdentifier()) {
3385 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003386 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003387 NameLoc,
3388 ObjectType,
3389 FirstQualifierInScope);
3390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Douglas Gregor9db53502011-03-02 18:07:45 +00003392 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3393 ObjectType);
3394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003395
Douglas Gregor9db53502011-03-02 18:07:45 +00003396 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3397 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003398 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003399 Template));
3400 if (!TransTemplate)
3401 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor9db53502011-03-02 18:07:45 +00003403 if (!getDerived().AlwaysRebuild() &&
3404 TransTemplate == Template)
3405 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9db53502011-03-02 18:07:45 +00003407 return TemplateName(TransTemplate);
3408 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003409
Douglas Gregor9db53502011-03-02 18:07:45 +00003410 if (SubstTemplateTemplateParmPackStorage *SubstPack
3411 = Name.getAsSubstTemplateTemplateParmPack()) {
3412 TemplateTemplateParmDecl *TransParam
3413 = cast_or_null<TemplateTemplateParmDecl>(
3414 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3415 if (!TransParam)
3416 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003417
Douglas Gregor9db53502011-03-02 18:07:45 +00003418 if (!getDerived().AlwaysRebuild() &&
3419 TransParam == SubstPack->getParameterPack())
3420 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
3422 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003423 SubstPack->getArgumentPack());
3424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregor9db53502011-03-02 18:07:45 +00003426 // These should be getting filtered out before they reach the AST.
3427 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003428}
3429
3430template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003431void TreeTransform<Derived>::InventTemplateArgumentLoc(
3432 const TemplateArgument &Arg,
3433 TemplateArgumentLoc &Output) {
3434 SourceLocation Loc = getDerived().getBaseLocation();
3435 switch (Arg.getKind()) {
3436 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003437 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003438 break;
3439
3440 case TemplateArgument::Type:
3441 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003442 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003443
John McCall0ad16662009-10-29 08:12:44 +00003444 break;
3445
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003446 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003447 case TemplateArgument::TemplateExpansion: {
3448 NestedNameSpecifierLocBuilder Builder;
3449 TemplateName Template = Arg.getAsTemplate();
3450 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3451 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3452 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3453 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003454
Douglas Gregor9d802122011-03-02 17:09:35 +00003455 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003456 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003457 Builder.getWithLocInContext(SemaRef.Context),
3458 Loc);
3459 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003460 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003461 Builder.getWithLocInContext(SemaRef.Context),
3462 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003464 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003465 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003466
John McCall0ad16662009-10-29 08:12:44 +00003467 case TemplateArgument::Expression:
3468 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3469 break;
3470
3471 case TemplateArgument::Declaration:
3472 case TemplateArgument::Integral:
3473 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003474 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003475 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003476 break;
3477 }
3478}
3479
3480template<typename Derived>
3481bool TreeTransform<Derived>::TransformTemplateArgument(
3482 const TemplateArgumentLoc &Input,
3483 TemplateArgumentLoc &Output) {
3484 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003485 switch (Arg.getKind()) {
3486 case TemplateArgument::Null:
3487 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003488 case TemplateArgument::Pack:
3489 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003490 case TemplateArgument::NullPtr:
3491 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregore922c772009-08-04 22:27:00 +00003493 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003494 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003495 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003496 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003497
3498 DI = getDerived().TransformType(DI);
3499 if (!DI) return true;
3500
3501 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3502 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003503 }
Mike Stump11289f42009-09-09 15:08:12 +00003504
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003505 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003506 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3507 if (QualifierLoc) {
3508 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3509 if (!QualifierLoc)
3510 return true;
3511 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003512
Douglas Gregordf846d12011-03-02 18:46:51 +00003513 CXXScopeSpec SS;
3514 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003515 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003516 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3517 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003518 if (Template.isNull())
3519 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregor9d802122011-03-02 17:09:35 +00003521 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003522 Input.getTemplateNameLoc());
3523 return false;
3524 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003525
3526 case TemplateArgument::TemplateExpansion:
3527 llvm_unreachable("Caller should expand pack expansions");
3528
Douglas Gregore922c772009-08-04 22:27:00 +00003529 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003530 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003531 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003532 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003533
John McCall0ad16662009-10-29 08:12:44 +00003534 Expr *InputExpr = Input.getSourceExpression();
3535 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3536
Chris Lattnercdb591a2011-04-25 20:37:58 +00003537 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003538 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003539 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003540 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003541 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003542 }
Douglas Gregore922c772009-08-04 22:27:00 +00003543 }
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregore922c772009-08-04 22:27:00 +00003545 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003546 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003547}
3548
Douglas Gregorfe921a72010-12-20 23:36:19 +00003549/// \brief Iterator adaptor that invents template argument location information
3550/// for each of the template arguments in its underlying iterator.
3551template<typename Derived, typename InputIterator>
3552class TemplateArgumentLocInventIterator {
3553 TreeTransform<Derived> &Self;
3554 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregorfe921a72010-12-20 23:36:19 +00003556public:
3557 typedef TemplateArgumentLoc value_type;
3558 typedef TemplateArgumentLoc reference;
3559 typedef typename std::iterator_traits<InputIterator>::difference_type
3560 difference_type;
3561 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Douglas Gregorfe921a72010-12-20 23:36:19 +00003563 class pointer {
3564 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003565
Douglas Gregorfe921a72010-12-20 23:36:19 +00003566 public:
3567 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003568
Douglas Gregorfe921a72010-12-20 23:36:19 +00003569 const TemplateArgumentLoc *operator->() const { return &Arg; }
3570 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregorfe921a72010-12-20 23:36:19 +00003572 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003573
Douglas Gregorfe921a72010-12-20 23:36:19 +00003574 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3575 InputIterator Iter)
3576 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Douglas Gregorfe921a72010-12-20 23:36:19 +00003578 TemplateArgumentLocInventIterator &operator++() {
3579 ++Iter;
3580 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003582
Douglas Gregorfe921a72010-12-20 23:36:19 +00003583 TemplateArgumentLocInventIterator operator++(int) {
3584 TemplateArgumentLocInventIterator Old(*this);
3585 ++(*this);
3586 return Old;
3587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregorfe921a72010-12-20 23:36:19 +00003589 reference operator*() const {
3590 TemplateArgumentLoc Result;
3591 Self.InventTemplateArgumentLoc(*Iter, Result);
3592 return Result;
3593 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregorfe921a72010-12-20 23:36:19 +00003595 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregorfe921a72010-12-20 23:36:19 +00003597 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3598 const TemplateArgumentLocInventIterator &Y) {
3599 return X.Iter == Y.Iter;
3600 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003601
Douglas Gregorfe921a72010-12-20 23:36:19 +00003602 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3603 const TemplateArgumentLocInventIterator &Y) {
3604 return X.Iter != Y.Iter;
3605 }
3606};
Chad Rosier1dcde962012-08-08 18:46:20 +00003607
Douglas Gregor42cafa82010-12-20 17:42:22 +00003608template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003609template<typename InputIterator>
3610bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3611 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003612 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003613 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003614 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003615 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003617 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3618 // Unpack argument packs, which we translate them into separate
3619 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003620 // FIXME: We could do much better if we could guarantee that the
3621 // TemplateArgumentLocInfo for the pack expansion would be usable for
3622 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003623 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003624 TemplateArgument::pack_iterator>
3625 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003626 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003627 In.getArgument().pack_begin()),
3628 PackLocIterator(*this,
3629 In.getArgument().pack_end()),
3630 Outputs))
3631 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003633 continue;
3634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003635
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003636 if (In.getArgument().isPackExpansion()) {
3637 // We have a pack expansion, for which we will be substituting into
3638 // the pattern.
3639 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003640 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003641 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003642 = getSema().getTemplateArgumentPackExpansionPattern(
3643 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Chris Lattner01cf8db2011-07-20 06:58:45 +00003645 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003646 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3647 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003649 // Determine whether the set of unexpanded parameter packs can and should
3650 // be expanded.
3651 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003652 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003653 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003654 if (getDerived().TryExpandParameterPacks(Ellipsis,
3655 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003656 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003657 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003658 RetainExpansion,
3659 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003660 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003661
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003662 if (!Expand) {
3663 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003664 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003665 // expansion.
3666 TemplateArgumentLoc OutPattern;
3667 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3668 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3669 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003671 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3672 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 if (Out.getArgument().isNull())
3674 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003676 Outputs.addArgument(Out);
3677 continue;
3678 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003680 // The transform has determined that we should perform an elementwise
3681 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003682 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003683 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3684
3685 if (getDerived().TransformTemplateArgument(Pattern, Out))
3686 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003687
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003688 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003689 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3690 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003691 if (Out.getArgument().isNull())
3692 return true;
3693 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003695 Outputs.addArgument(Out);
3696 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003697
Douglas Gregor48d24112011-01-10 20:53:55 +00003698 // If we're supposed to retain a pack expansion, do so by temporarily
3699 // forgetting the partially-substituted parameter pack.
3700 if (RetainExpansion) {
3701 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor48d24112011-01-10 20:53:55 +00003703 if (getDerived().TransformTemplateArgument(Pattern, Out))
3704 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003706 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3707 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003708 if (Out.getArgument().isNull())
3709 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregor48d24112011-01-10 20:53:55 +00003711 Outputs.addArgument(Out);
3712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003714 continue;
3715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003716
3717 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003718 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003719 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor42cafa82010-12-20 17:42:22 +00003721 Outputs.addArgument(Out);
3722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
Douglas Gregor42cafa82010-12-20 17:42:22 +00003724 return false;
3725
3726}
3727
Douglas Gregord6ff3322009-08-04 16:50:30 +00003728//===----------------------------------------------------------------------===//
3729// Type transformation
3730//===----------------------------------------------------------------------===//
3731
3732template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003733QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003734 if (getDerived().AlreadyTransformed(T))
3735 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003736
John McCall550e0c22009-10-21 00:40:46 +00003737 // Temporary workaround. All of these transformations should
3738 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003739 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3740 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003741
John McCall31f82722010-11-12 08:19:04 +00003742 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003743
John McCall550e0c22009-10-21 00:40:46 +00003744 if (!NewDI)
3745 return QualType();
3746
3747 return NewDI->getType();
3748}
3749
3750template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003751TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003752 // Refine the base location to the type's location.
3753 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3754 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003755 if (getDerived().AlreadyTransformed(DI->getType()))
3756 return DI;
3757
3758 TypeLocBuilder TLB;
3759
3760 TypeLoc TL = DI->getTypeLoc();
3761 TLB.reserve(TL.getFullDataSize());
3762
John McCall31f82722010-11-12 08:19:04 +00003763 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003764 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003765 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003766
John McCallbcd03502009-12-07 02:54:59 +00003767 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003768}
3769
3770template<typename Derived>
3771QualType
John McCall31f82722010-11-12 08:19:04 +00003772TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003773 switch (T.getTypeLocClass()) {
3774#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003775#define TYPELOC(CLASS, PARENT) \
3776 case TypeLoc::CLASS: \
3777 return getDerived().Transform##CLASS##Type(TLB, \
3778 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003779#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003780 }
Mike Stump11289f42009-09-09 15:08:12 +00003781
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003782 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003783}
3784
3785/// FIXME: By default, this routine adds type qualifiers only to types
3786/// that can have qualifiers, and silently suppresses those qualifiers
3787/// that are not permitted (e.g., qualifiers on reference or function
3788/// types). This is the right thing for template instantiation, but
3789/// probably not for other clients.
3790template<typename Derived>
3791QualType
3792TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003793 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003794 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003795
John McCall31f82722010-11-12 08:19:04 +00003796 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799
3800 // Silently suppress qualifiers if the result type can't be qualified.
3801 // FIXME: this is the right thing for template instantiation, but
3802 // probably not for other clients.
3803 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003804 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003805
John McCall31168b02011-06-15 23:02:42 +00003806 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003807 // resulting type.
3808 if (Quals.hasObjCLifetime()) {
3809 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3810 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003811 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003812 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003813 // A lifetime qualifier applied to a substituted template parameter
3814 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003815 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003816 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003817 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3818 QualType Replacement = SubstTypeParam->getReplacementType();
3819 Qualifiers Qs = Replacement.getQualifiers();
3820 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003821 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003822 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3823 Qs);
3824 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003825 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003826 Replacement);
3827 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003828 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3829 // 'auto' types behave the same way as template parameters.
3830 QualType Deduced = AutoTy->getDeducedType();
3831 Qualifiers Qs = Deduced.getQualifiers();
3832 Qs.removeObjCLifetime();
3833 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3834 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003835 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3836 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003837 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003838 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003839 // Otherwise, complain about the addition of a qualifier to an
3840 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003841 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003842 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003843 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregore46db902011-06-17 22:11:49 +00003845 Quals.removeObjCLifetime();
3846 }
3847 }
3848 }
John McCallcb0f89a2010-06-05 06:41:15 +00003849 if (!Quals.empty()) {
3850 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003851 // BuildQualifiedType might not add qualifiers if they are invalid.
3852 if (Result.hasLocalQualifiers())
3853 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003854 // No location information to preserve.
3855 }
John McCall550e0c22009-10-21 00:40:46 +00003856
3857 return Result;
3858}
3859
Douglas Gregor14454802011-02-25 02:25:35 +00003860template<typename Derived>
3861TypeLoc
3862TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3863 QualType ObjectType,
3864 NamedDecl *UnqualLookup,
3865 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003866 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003867 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003868
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003869 TypeSourceInfo *TSI =
3870 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3871 if (TSI)
3872 return TSI->getTypeLoc();
3873 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003874}
3875
Douglas Gregor579c15f2011-03-02 18:32:08 +00003876template<typename Derived>
3877TypeSourceInfo *
3878TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3879 QualType ObjectType,
3880 NamedDecl *UnqualLookup,
3881 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003882 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003883 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003885 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3886 UnqualLookup, SS);
3887}
3888
3889template <typename Derived>
3890TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3891 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3892 CXXScopeSpec &SS) {
3893 QualType T = TL.getType();
3894 assert(!getDerived().AlreadyTransformed(T));
3895
Douglas Gregor579c15f2011-03-02 18:32:08 +00003896 TypeLocBuilder TLB;
3897 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003898
Douglas Gregor579c15f2011-03-02 18:32:08 +00003899 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003900 TemplateSpecializationTypeLoc SpecTL =
3901 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003902
Douglas Gregor579c15f2011-03-02 18:32:08 +00003903 TemplateName Template
3904 = getDerived().TransformTemplateName(SS,
3905 SpecTL.getTypePtr()->getTemplateName(),
3906 SpecTL.getTemplateNameLoc(),
3907 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003908 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003909 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003910
3911 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003912 Template);
3913 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003914 DependentTemplateSpecializationTypeLoc SpecTL =
3915 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003916
Douglas Gregor579c15f2011-03-02 18:32:08 +00003917 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003918 = getDerived().RebuildTemplateName(SS,
3919 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003920 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003921 ObjectType, UnqualLookup);
3922 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003923 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003924
3925 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003926 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003927 Template,
3928 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003929 } else {
3930 // Nothing special needs to be done for these.
3931 Result = getDerived().TransformType(TLB, TL);
3932 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
3934 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003935 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003936
Douglas Gregor579c15f2011-03-02 18:32:08 +00003937 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3938}
3939
John McCall550e0c22009-10-21 00:40:46 +00003940template <class TyLoc> static inline
3941QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3942 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3943 NewT.setNameLoc(T.getNameLoc());
3944 return T.getType();
3945}
3946
John McCall550e0c22009-10-21 00:40:46 +00003947template<typename Derived>
3948QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003949 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003950 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3951 NewT.setBuiltinLoc(T.getBuiltinLoc());
3952 if (T.needsExtraLocalData())
3953 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3954 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955}
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003958QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003959 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003960 // FIXME: recurse?
3961 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962}
Mike Stump11289f42009-09-09 15:08:12 +00003963
Reid Kleckner0503a872013-12-05 01:23:43 +00003964template <typename Derived>
3965QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3966 AdjustedTypeLoc TL) {
3967 // Adjustments applied during transformation are handled elsewhere.
3968 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3969}
3970
Douglas Gregord6ff3322009-08-04 16:50:30 +00003971template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003972QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3973 DecayedTypeLoc TL) {
3974 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3975 if (OriginalType.isNull())
3976 return QualType();
3977
3978 QualType Result = TL.getType();
3979 if (getDerived().AlwaysRebuild() ||
3980 OriginalType != TL.getOriginalLoc().getType())
3981 Result = SemaRef.Context.getDecayedType(OriginalType);
3982 TLB.push<DecayedTypeLoc>(Result);
3983 // Nothing to set for DecayedTypeLoc.
3984 return Result;
3985}
3986
3987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003988QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003989 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003990 QualType PointeeType
3991 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003992 if (PointeeType.isNull())
3993 return QualType();
3994
3995 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003996 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003997 // A dependent pointer type 'T *' has is being transformed such
3998 // that an Objective-C class type is being replaced for 'T'. The
3999 // resulting pointer type is an ObjCObjectPointerType, not a
4000 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004001 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004002
John McCall8b07ec22010-05-15 11:32:37 +00004003 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4004 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004005 return Result;
4006 }
John McCall31f82722010-11-12 08:19:04 +00004007
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004008 if (getDerived().AlwaysRebuild() ||
4009 PointeeType != TL.getPointeeLoc().getType()) {
4010 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4011 if (Result.isNull())
4012 return QualType();
4013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004014
John McCall31168b02011-06-15 23:02:42 +00004015 // Objective-C ARC can add lifetime qualifiers to the type that we're
4016 // pointing to.
4017 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004018
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004019 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4020 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004021 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022}
Mike Stump11289f42009-09-09 15:08:12 +00004023
4024template<typename Derived>
4025QualType
John McCall550e0c22009-10-21 00:40:46 +00004026TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004027 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004028 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004029 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4030 if (PointeeType.isNull())
4031 return QualType();
4032
4033 QualType Result = TL.getType();
4034 if (getDerived().AlwaysRebuild() ||
4035 PointeeType != TL.getPointeeLoc().getType()) {
4036 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004037 TL.getSigilLoc());
4038 if (Result.isNull())
4039 return QualType();
4040 }
4041
Douglas Gregor049211a2010-04-22 16:50:51 +00004042 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004043 NewT.setSigilLoc(TL.getSigilLoc());
4044 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045}
4046
John McCall70dd5f62009-10-30 00:06:24 +00004047/// Transforms a reference type. Note that somewhat paradoxically we
4048/// don't care whether the type itself is an l-value type or an r-value
4049/// type; we only care if the type was *written* as an l-value type
4050/// or an r-value type.
4051template<typename Derived>
4052QualType
4053TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004054 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004055 const ReferenceType *T = TL.getTypePtr();
4056
4057 // Note that this works with the pointee-as-written.
4058 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4059 if (PointeeType.isNull())
4060 return QualType();
4061
4062 QualType Result = TL.getType();
4063 if (getDerived().AlwaysRebuild() ||
4064 PointeeType != T->getPointeeTypeAsWritten()) {
4065 Result = getDerived().RebuildReferenceType(PointeeType,
4066 T->isSpelledAsLValue(),
4067 TL.getSigilLoc());
4068 if (Result.isNull())
4069 return QualType();
4070 }
4071
John McCall31168b02011-06-15 23:02:42 +00004072 // Objective-C ARC can add lifetime qualifiers to the type that we're
4073 // referring to.
4074 TLB.TypeWasModifiedSafely(
4075 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4076
John McCall70dd5f62009-10-30 00:06:24 +00004077 // r-value references can be rebuilt as l-value references.
4078 ReferenceTypeLoc NewTL;
4079 if (isa<LValueReferenceType>(Result))
4080 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4081 else
4082 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4083 NewTL.setSigilLoc(TL.getSigilLoc());
4084
4085 return Result;
4086}
4087
Mike Stump11289f42009-09-09 15:08:12 +00004088template<typename Derived>
4089QualType
John McCall550e0c22009-10-21 00:40:46 +00004090TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004091 LValueReferenceTypeLoc TL) {
4092 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093}
4094
Mike Stump11289f42009-09-09 15:08:12 +00004095template<typename Derived>
4096QualType
John McCall550e0c22009-10-21 00:40:46 +00004097TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004098 RValueReferenceTypeLoc TL) {
4099 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004100}
Mike Stump11289f42009-09-09 15:08:12 +00004101
Douglas Gregord6ff3322009-08-04 16:50:30 +00004102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004103QualType
John McCall550e0c22009-10-21 00:40:46 +00004104TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004105 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004106 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004107 if (PointeeType.isNull())
4108 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004109
Abramo Bagnara509357842011-03-05 14:42:21 +00004110 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004111 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004112 if (OldClsTInfo) {
4113 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4114 if (!NewClsTInfo)
4115 return QualType();
4116 }
4117
4118 const MemberPointerType *T = TL.getTypePtr();
4119 QualType OldClsType = QualType(T->getClass(), 0);
4120 QualType NewClsType;
4121 if (NewClsTInfo)
4122 NewClsType = NewClsTInfo->getType();
4123 else {
4124 NewClsType = getDerived().TransformType(OldClsType);
4125 if (NewClsType.isNull())
4126 return QualType();
4127 }
Mike Stump11289f42009-09-09 15:08:12 +00004128
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType Result = TL.getType();
4130 if (getDerived().AlwaysRebuild() ||
4131 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004132 NewClsType != OldClsType) {
4133 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004134 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004135 if (Result.isNull())
4136 return QualType();
4137 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138
Reid Kleckner0503a872013-12-05 01:23:43 +00004139 // If we had to adjust the pointee type when building a member pointer, make
4140 // sure to push TypeLoc info for it.
4141 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4142 if (MPT && PointeeType != MPT->getPointeeType()) {
4143 assert(isa<AdjustedType>(MPT->getPointeeType()));
4144 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4145 }
4146
John McCall550e0c22009-10-21 00:40:46 +00004147 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4148 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004149 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004150
4151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152}
4153
Mike Stump11289f42009-09-09 15:08:12 +00004154template<typename Derived>
4155QualType
John McCall550e0c22009-10-21 00:40:46 +00004156TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004157 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004158 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004159 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004160 if (ElementType.isNull())
4161 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004162
John McCall550e0c22009-10-21 00:40:46 +00004163 QualType Result = TL.getType();
4164 if (getDerived().AlwaysRebuild() ||
4165 ElementType != T->getElementType()) {
4166 Result = getDerived().RebuildConstantArrayType(ElementType,
4167 T->getSizeModifier(),
4168 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004169 T->getIndexTypeCVRQualifiers(),
4170 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004171 if (Result.isNull())
4172 return QualType();
4173 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004174
4175 // We might have either a ConstantArrayType or a VariableArrayType now:
4176 // a ConstantArrayType is allowed to have an element type which is a
4177 // VariableArrayType if the type is dependent. Fortunately, all array
4178 // types have the same location layout.
4179 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004180 NewTL.setLBracketLoc(TL.getLBracketLoc());
4181 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004182
John McCall550e0c22009-10-21 00:40:46 +00004183 Expr *Size = TL.getSizeExpr();
4184 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004185 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4186 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004187 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4188 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004189 }
4190 NewTL.setSizeExpr(Size);
4191
4192 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193}
Mike Stump11289f42009-09-09 15:08:12 +00004194
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004196QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004197 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004198 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004199 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004200 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201 if (ElementType.isNull())
4202 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 QualType Result = TL.getType();
4205 if (getDerived().AlwaysRebuild() ||
4206 ElementType != T->getElementType()) {
4207 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004209 T->getIndexTypeCVRQualifiers(),
4210 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004211 if (Result.isNull())
4212 return QualType();
4213 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4216 NewTL.setLBracketLoc(TL.getLBracketLoc());
4217 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004218 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004219
4220 return Result;
4221}
4222
4223template<typename Derived>
4224QualType
4225TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004226 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004227 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004228 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4229 if (ElementType.isNull())
4230 return QualType();
4231
John McCalldadc5752010-08-24 06:29:42 +00004232 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004233 = getDerived().TransformExpr(T->getSizeExpr());
4234 if (SizeResult.isInvalid())
4235 return QualType();
4236
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004237 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004238
4239 QualType Result = TL.getType();
4240 if (getDerived().AlwaysRebuild() ||
4241 ElementType != T->getElementType() ||
4242 Size != T->getSizeExpr()) {
4243 Result = getDerived().RebuildVariableArrayType(ElementType,
4244 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004245 Size,
John McCall550e0c22009-10-21 00:40:46 +00004246 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004247 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004248 if (Result.isNull())
4249 return QualType();
4250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004251
Serge Pavlov774c6d02014-02-06 03:49:11 +00004252 // We might have constant size array now, but fortunately it has the same
4253 // location layout.
4254 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004255 NewTL.setLBracketLoc(TL.getLBracketLoc());
4256 NewTL.setRBracketLoc(TL.getRBracketLoc());
4257 NewTL.setSizeExpr(Size);
4258
4259 return Result;
4260}
4261
4262template<typename Derived>
4263QualType
4264TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004265 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004266 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004267 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4268 if (ElementType.isNull())
4269 return QualType();
4270
Richard Smith764d2fe2011-12-20 02:08:33 +00004271 // Array bounds are constant expressions.
4272 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4273 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004274
John McCall33ddac02011-01-19 10:06:00 +00004275 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4276 Expr *origSize = TL.getSizeExpr();
4277 if (!origSize) origSize = T->getSizeExpr();
4278
4279 ExprResult sizeResult
4280 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004281 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004282 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004283 return QualType();
4284
John McCall33ddac02011-01-19 10:06:00 +00004285 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004286
4287 QualType Result = TL.getType();
4288 if (getDerived().AlwaysRebuild() ||
4289 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004290 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004291 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4292 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004293 size,
John McCall550e0c22009-10-21 00:40:46 +00004294 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004295 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004296 if (Result.isNull())
4297 return QualType();
4298 }
John McCall550e0c22009-10-21 00:40:46 +00004299
4300 // We might have any sort of array type now, but fortunately they
4301 // all have the same location layout.
4302 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4303 NewTL.setLBracketLoc(TL.getLBracketLoc());
4304 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004305 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004306
4307 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004308}
Mike Stump11289f42009-09-09 15:08:12 +00004309
4310template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004311QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004312 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004313 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004314 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004315
4316 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004317 QualType ElementType = getDerived().TransformType(T->getElementType());
4318 if (ElementType.isNull())
4319 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004320
Richard Smith764d2fe2011-12-20 02:08:33 +00004321 // Vector sizes are constant expressions.
4322 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4323 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004324
John McCalldadc5752010-08-24 06:29:42 +00004325 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004326 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004327 if (Size.isInvalid())
4328 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004329
John McCall550e0c22009-10-21 00:40:46 +00004330 QualType Result = TL.getType();
4331 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004332 ElementType != T->getElementType() ||
4333 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004334 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004335 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004337 if (Result.isNull())
4338 return QualType();
4339 }
John McCall550e0c22009-10-21 00:40:46 +00004340
4341 // Result might be dependent or not.
4342 if (isa<DependentSizedExtVectorType>(Result)) {
4343 DependentSizedExtVectorTypeLoc NewTL
4344 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4345 NewTL.setNameLoc(TL.getNameLoc());
4346 } else {
4347 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4348 NewTL.setNameLoc(TL.getNameLoc());
4349 }
4350
4351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004352}
Mike Stump11289f42009-09-09 15:08:12 +00004353
4354template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004355QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004356 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004357 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004358 QualType ElementType = getDerived().TransformType(T->getElementType());
4359 if (ElementType.isNull())
4360 return QualType();
4361
John McCall550e0c22009-10-21 00:40:46 +00004362 QualType Result = TL.getType();
4363 if (getDerived().AlwaysRebuild() ||
4364 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004365 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004366 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004367 if (Result.isNull())
4368 return QualType();
4369 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004370
John McCall550e0c22009-10-21 00:40:46 +00004371 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4372 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004373
John McCall550e0c22009-10-21 00:40:46 +00004374 return Result;
4375}
4376
4377template<typename Derived>
4378QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004379 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004380 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004381 QualType ElementType = getDerived().TransformType(T->getElementType());
4382 if (ElementType.isNull())
4383 return QualType();
4384
4385 QualType Result = TL.getType();
4386 if (getDerived().AlwaysRebuild() ||
4387 ElementType != T->getElementType()) {
4388 Result = getDerived().RebuildExtVectorType(ElementType,
4389 T->getNumElements(),
4390 /*FIXME*/ SourceLocation());
4391 if (Result.isNull())
4392 return QualType();
4393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004394
John McCall550e0c22009-10-21 00:40:46 +00004395 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4396 NewTL.setNameLoc(TL.getNameLoc());
4397
4398 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
David Blaikie05785d12013-02-20 22:23:23 +00004401template <typename Derived>
4402ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4403 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4404 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004405 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004406 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregor715e4612011-01-14 22:40:04 +00004408 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004409 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004410 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004411 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004412 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004413
Douglas Gregor715e4612011-01-14 22:40:04 +00004414 TypeLocBuilder TLB;
4415 TypeLoc NewTL = OldDI->getTypeLoc();
4416 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004417
4418 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004419 OldExpansionTL.getPatternLoc());
4420 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004421 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004422
4423 Result = RebuildPackExpansionType(Result,
4424 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004425 OldExpansionTL.getEllipsisLoc(),
4426 NumExpansions);
4427 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004428 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004429
Douglas Gregor715e4612011-01-14 22:40:04 +00004430 PackExpansionTypeLoc NewExpansionTL
4431 = TLB.push<PackExpansionTypeLoc>(Result);
4432 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4433 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4434 } else
4435 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004436 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004437 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004438
John McCall8fb0d9d2011-05-01 22:35:37 +00004439 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004440 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004441
4442 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4443 OldParm->getDeclContext(),
4444 OldParm->getInnerLocStart(),
4445 OldParm->getLocation(),
4446 OldParm->getIdentifier(),
4447 NewDI->getType(),
4448 NewDI,
4449 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004450 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004451 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4452 OldParm->getFunctionScopeIndex() + indexAdjustment);
4453 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004454}
4455
4456template<typename Derived>
4457bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004458 TransformFunctionTypeParams(SourceLocation Loc,
4459 ParmVarDecl **Params, unsigned NumParams,
4460 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004461 SmallVectorImpl<QualType> &OutParamTypes,
4462 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004463 int indexAdjustment = 0;
4464
Douglas Gregordd472162011-01-07 00:20:55 +00004465 for (unsigned i = 0; i != NumParams; ++i) {
4466 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004467 assert(OldParm->getFunctionScopeIndex() == i);
4468
David Blaikie05785d12013-02-20 22:23:23 +00004469 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004470 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004471 if (OldParm->isParameterPack()) {
4472 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004473 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004474
Douglas Gregor5499af42011-01-05 23:12:31 +00004475 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004476 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004477 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004478 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4479 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004480 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4481
Douglas Gregor5499af42011-01-05 23:12:31 +00004482 // Determine whether we should expand the parameter packs.
4483 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004484 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004485 Optional<unsigned> OrigNumExpansions =
4486 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004487 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004488 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4489 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004490 Unexpanded,
4491 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004492 RetainExpansion,
4493 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 return true;
4495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004496
Douglas Gregor5499af42011-01-05 23:12:31 +00004497 if (ShouldExpand) {
4498 // Expand the function parameter pack into multiple, separate
4499 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004500 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004501 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004503 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004504 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004505 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004506 OrigNumExpansions,
4507 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004508 if (!NewParm)
4509 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004510
Douglas Gregordd472162011-01-07 00:20:55 +00004511 OutParamTypes.push_back(NewParm->getType());
4512 if (PVars)
4513 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004514 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004515
4516 // If we're supposed to retain a pack expansion, do so by temporarily
4517 // forgetting the partially-substituted parameter pack.
4518 if (RetainExpansion) {
4519 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004520 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004521 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004522 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004523 OrigNumExpansions,
4524 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004525 if (!NewParm)
4526 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004527
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004528 OutParamTypes.push_back(NewParm->getType());
4529 if (PVars)
4530 PVars->push_back(NewParm);
4531 }
4532
John McCall8fb0d9d2011-05-01 22:35:37 +00004533 // The next parameter should have the same adjustment as the
4534 // last thing we pushed, but we post-incremented indexAdjustment
4535 // on every push. Also, if we push nothing, the adjustment should
4536 // go down by one.
4537 indexAdjustment--;
4538
Douglas Gregor5499af42011-01-05 23:12:31 +00004539 // We're done with the pack expansion.
4540 continue;
4541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004542
4543 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004544 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4546 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004547 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004548 NumExpansions,
4549 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004550 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004551 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004552 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004553 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004554
John McCall58f10c32010-03-11 09:03:00 +00004555 if (!NewParm)
4556 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004557
Douglas Gregordd472162011-01-07 00:20:55 +00004558 OutParamTypes.push_back(NewParm->getType());
4559 if (PVars)
4560 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004561 continue;
4562 }
John McCall58f10c32010-03-11 09:03:00 +00004563
4564 // Deal with the possibility that we don't have a parameter
4565 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004566 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004567 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004568 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004569 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004570 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004571 = dyn_cast<PackExpansionType>(OldType)) {
4572 // We have a function parameter pack that may need to be expanded.
4573 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004574 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004575 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004576
Douglas Gregor5499af42011-01-05 23:12:31 +00004577 // Determine whether we should expand the parameter packs.
4578 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004579 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004580 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004581 Unexpanded,
4582 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004583 RetainExpansion,
4584 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004585 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004587
Douglas Gregor5499af42011-01-05 23:12:31 +00004588 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004589 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004590 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004591 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004592 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4593 QualType NewType = getDerived().TransformType(Pattern);
4594 if (NewType.isNull())
4595 return true;
John McCall58f10c32010-03-11 09:03:00 +00004596
Douglas Gregordd472162011-01-07 00:20:55 +00004597 OutParamTypes.push_back(NewType);
4598 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004599 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004600 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004601
Douglas Gregor5499af42011-01-05 23:12:31 +00004602 // We're done with the pack expansion.
4603 continue;
4604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004605
Douglas Gregor48d24112011-01-10 20:53:55 +00004606 // If we're supposed to retain a pack expansion, do so by temporarily
4607 // forgetting the partially-substituted parameter pack.
4608 if (RetainExpansion) {
4609 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4610 QualType NewType = getDerived().TransformType(Pattern);
4611 if (NewType.isNull())
4612 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004613
Douglas Gregor48d24112011-01-10 20:53:55 +00004614 OutParamTypes.push_back(NewType);
4615 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004616 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004617 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004618
Chad Rosier1dcde962012-08-08 18:46:20 +00004619 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004620 // expansion.
4621 OldType = Expansion->getPattern();
4622 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4624 NewType = getDerived().TransformType(OldType);
4625 } else {
4626 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004627 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004628
Douglas Gregor5499af42011-01-05 23:12:31 +00004629 if (NewType.isNull())
4630 return true;
4631
4632 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004633 NewType = getSema().Context.getPackExpansionType(NewType,
4634 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004635
Douglas Gregordd472162011-01-07 00:20:55 +00004636 OutParamTypes.push_back(NewType);
4637 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004638 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004639 }
4640
John McCall8fb0d9d2011-05-01 22:35:37 +00004641#ifndef NDEBUG
4642 if (PVars) {
4643 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4644 if (ParmVarDecl *parm = (*PVars)[i])
4645 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004646 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004647#endif
4648
4649 return false;
4650}
John McCall58f10c32010-03-11 09:03:00 +00004651
4652template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004653QualType
John McCall550e0c22009-10-21 00:40:46 +00004654TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004655 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004656 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004657 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004658 return getDerived().TransformFunctionProtoType(
4659 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004660 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4661 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4662 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004663 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004664}
4665
Richard Smith2e321552014-11-12 02:00:47 +00004666template<typename Derived> template<typename Fn>
4667QualType TreeTransform<Derived>::TransformFunctionProtoType(
4668 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4669 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004670 // Transform the parameters and return type.
4671 //
Richard Smithf623c962012-04-17 00:58:00 +00004672 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004673 // When the function has a trailing return type, we instantiate the
4674 // parameters before the return type, since the return type can then refer
4675 // to the parameters themselves (via decltype, sizeof, etc.).
4676 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004677 SmallVector<QualType, 4> ParamTypes;
4678 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004679 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004680
Douglas Gregor7fb25412010-10-01 18:44:50 +00004681 QualType ResultType;
4682
Richard Smith1226c602012-08-14 22:51:13 +00004683 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004684 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004685 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004686 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004687 return QualType();
4688
Douglas Gregor3024f072012-04-16 07:05:22 +00004689 {
4690 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004691 // If a declaration declares a member function or member function
4692 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004693 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004694 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004695 // declarator.
4696 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004697
Alp Toker42a16a62014-01-25 23:51:36 +00004698 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004699 if (ResultType.isNull())
4700 return QualType();
4701 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004702 }
4703 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004704 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004705 if (ResultType.isNull())
4706 return QualType();
4707
Alp Toker9cacbab2014-01-20 20:26:09 +00004708 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004709 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004710 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004711 return QualType();
4712 }
4713
Richard Smith2e321552014-11-12 02:00:47 +00004714 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4715
4716 bool EPIChanged = false;
4717 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4718 return QualType();
4719
4720 // FIXME: Need to transform ConsumedParameters for variadic template
4721 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004722
John McCall550e0c22009-10-21 00:40:46 +00004723 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004724 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004725 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004726 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004727 if (Result.isNull())
4728 return QualType();
4729 }
Mike Stump11289f42009-09-09 15:08:12 +00004730
John McCall550e0c22009-10-21 00:40:46 +00004731 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004732 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004733 NewTL.setLParenLoc(TL.getLParenLoc());
4734 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004735 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004736 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4737 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004738
4739 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004740}
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004743bool TreeTransform<Derived>::TransformExceptionSpec(
4744 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4745 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4746 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4747
4748 // Instantiate a dynamic noexcept expression, if any.
4749 if (ESI.Type == EST_ComputedNoexcept) {
4750 EnterExpressionEvaluationContext Unevaluated(getSema(),
4751 Sema::ConstantEvaluated);
4752 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4753 if (NoexceptExpr.isInvalid())
4754 return true;
4755
4756 NoexceptExpr = getSema().CheckBooleanCondition(
4757 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4758 if (NoexceptExpr.isInvalid())
4759 return true;
4760
4761 if (!NoexceptExpr.get()->isValueDependent()) {
4762 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4763 NoexceptExpr.get(), nullptr,
4764 diag::err_noexcept_needs_constant_expression,
4765 /*AllowFold*/false);
4766 if (NoexceptExpr.isInvalid())
4767 return true;
4768 }
4769
4770 if (ESI.NoexceptExpr != NoexceptExpr.get())
4771 Changed = true;
4772 ESI.NoexceptExpr = NoexceptExpr.get();
4773 }
4774
4775 if (ESI.Type != EST_Dynamic)
4776 return false;
4777
4778 // Instantiate a dynamic exception specification's type.
4779 for (QualType T : ESI.Exceptions) {
4780 if (const PackExpansionType *PackExpansion =
4781 T->getAs<PackExpansionType>()) {
4782 Changed = true;
4783
4784 // We have a pack expansion. Instantiate it.
4785 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4786 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4787 Unexpanded);
4788 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4789
4790 // Determine whether the set of unexpanded parameter packs can and
4791 // should
4792 // be expanded.
4793 bool Expand = false;
4794 bool RetainExpansion = false;
4795 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4796 // FIXME: Track the location of the ellipsis (and track source location
4797 // information for the types in the exception specification in general).
4798 if (getDerived().TryExpandParameterPacks(
4799 Loc, SourceRange(), Unexpanded, Expand,
4800 RetainExpansion, NumExpansions))
4801 return true;
4802
4803 if (!Expand) {
4804 // We can't expand this pack expansion into separate arguments yet;
4805 // just substitute into the pattern and create a new pack expansion
4806 // type.
4807 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4808 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4809 if (U.isNull())
4810 return true;
4811
4812 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4813 Exceptions.push_back(U);
4814 continue;
4815 }
4816
4817 // Substitute into the pack expansion pattern for each slice of the
4818 // pack.
4819 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4820 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4821
4822 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4823 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4824 return true;
4825
4826 Exceptions.push_back(U);
4827 }
4828 } else {
4829 QualType U = getDerived().TransformType(T);
4830 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4831 return true;
4832 if (T != U)
4833 Changed = true;
4834
4835 Exceptions.push_back(U);
4836 }
4837 }
4838
4839 ESI.Exceptions = Exceptions;
4840 return false;
4841}
4842
4843template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004844QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004845 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004846 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004847 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004848 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004849 if (ResultType.isNull())
4850 return QualType();
4851
4852 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004853 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004854 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4855
4856 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004857 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004858 NewTL.setLParenLoc(TL.getLParenLoc());
4859 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004860 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004861
4862 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004863}
Mike Stump11289f42009-09-09 15:08:12 +00004864
John McCallb96ec562009-12-04 22:46:56 +00004865template<typename Derived> QualType
4866TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004867 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004868 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004869 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004870 if (!D)
4871 return QualType();
4872
4873 QualType Result = TL.getType();
4874 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4875 Result = getDerived().RebuildUnresolvedUsingType(D);
4876 if (Result.isNull())
4877 return QualType();
4878 }
4879
4880 // We might get an arbitrary type spec type back. We should at
4881 // least always get a type spec type, though.
4882 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4883 NewTL.setNameLoc(TL.getNameLoc());
4884
4885 return Result;
4886}
4887
Douglas Gregord6ff3322009-08-04 16:50:30 +00004888template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004889QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004890 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004891 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004892 TypedefNameDecl *Typedef
4893 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4894 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004895 if (!Typedef)
4896 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004897
John McCall550e0c22009-10-21 00:40:46 +00004898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() ||
4900 Typedef != T->getDecl()) {
4901 Result = getDerived().RebuildTypedefType(Typedef);
4902 if (Result.isNull())
4903 return QualType();
4904 }
Mike Stump11289f42009-09-09 15:08:12 +00004905
John McCall550e0c22009-10-21 00:40:46 +00004906 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4907 NewTL.setNameLoc(TL.getNameLoc());
4908
4909 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004910}
Mike Stump11289f42009-09-09 15:08:12 +00004911
Douglas Gregord6ff3322009-08-04 16:50:30 +00004912template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004913QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004914 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004915 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004916 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4917 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004918
John McCalldadc5752010-08-24 06:29:42 +00004919 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004920 if (E.isInvalid())
4921 return QualType();
4922
Eli Friedmane4f22df2012-02-29 04:03:55 +00004923 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4924 if (E.isInvalid())
4925 return QualType();
4926
John McCall550e0c22009-10-21 00:40:46 +00004927 QualType Result = TL.getType();
4928 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004929 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004930 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004931 if (Result.isNull())
4932 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004933 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004934 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCall550e0c22009-10-21 00:40:46 +00004936 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004937 NewTL.setTypeofLoc(TL.getTypeofLoc());
4938 NewTL.setLParenLoc(TL.getLParenLoc());
4939 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004940
4941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004942}
Mike Stump11289f42009-09-09 15:08:12 +00004943
4944template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004945QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004946 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004947 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4948 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4949 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004950 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004951
John McCall550e0c22009-10-21 00:40:46 +00004952 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004953 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4954 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004955 if (Result.isNull())
4956 return QualType();
4957 }
Mike Stump11289f42009-09-09 15:08:12 +00004958
John McCall550e0c22009-10-21 00:40:46 +00004959 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004960 NewTL.setTypeofLoc(TL.getTypeofLoc());
4961 NewTL.setLParenLoc(TL.getLParenLoc());
4962 NewTL.setRParenLoc(TL.getRParenLoc());
4963 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004964
4965 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004966}
Mike Stump11289f42009-09-09 15:08:12 +00004967
4968template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004969QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004970 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004971 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004972
Douglas Gregore922c772009-08-04 22:27:00 +00004973 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004974 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4975 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004976
John McCalldadc5752010-08-24 06:29:42 +00004977 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004978 if (E.isInvalid())
4979 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004980
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004981 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00004982 if (E.isInvalid())
4983 return QualType();
4984
John McCall550e0c22009-10-21 00:40:46 +00004985 QualType Result = TL.getType();
4986 if (getDerived().AlwaysRebuild() ||
4987 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004988 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004989 if (Result.isNull())
4990 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004991 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004992 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004993
John McCall550e0c22009-10-21 00:40:46 +00004994 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4995 NewTL.setNameLoc(TL.getNameLoc());
4996
4997 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998}
4999
5000template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005001QualType TreeTransform<Derived>::TransformUnaryTransformType(
5002 TypeLocBuilder &TLB,
5003 UnaryTransformTypeLoc TL) {
5004 QualType Result = TL.getType();
5005 if (Result->isDependentType()) {
5006 const UnaryTransformType *T = TL.getTypePtr();
5007 QualType NewBase =
5008 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5009 Result = getDerived().RebuildUnaryTransformType(NewBase,
5010 T->getUTTKind(),
5011 TL.getKWLoc());
5012 if (Result.isNull())
5013 return QualType();
5014 }
5015
5016 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5017 NewTL.setKWLoc(TL.getKWLoc());
5018 NewTL.setParensRange(TL.getParensRange());
5019 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5020 return Result;
5021}
5022
5023template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005024QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5025 AutoTypeLoc TL) {
5026 const AutoType *T = TL.getTypePtr();
5027 QualType OldDeduced = T->getDeducedType();
5028 QualType NewDeduced;
5029 if (!OldDeduced.isNull()) {
5030 NewDeduced = getDerived().TransformType(OldDeduced);
5031 if (NewDeduced.isNull())
5032 return QualType();
5033 }
5034
5035 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005036 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5037 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005038 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005039 if (Result.isNull())
5040 return QualType();
5041 }
5042
5043 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5044 NewTL.setNameLoc(TL.getNameLoc());
5045
5046 return Result;
5047}
5048
5049template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005050QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005051 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005052 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005053 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005054 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5055 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005056 if (!Record)
5057 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005058
John McCall550e0c22009-10-21 00:40:46 +00005059 QualType Result = TL.getType();
5060 if (getDerived().AlwaysRebuild() ||
5061 Record != T->getDecl()) {
5062 Result = getDerived().RebuildRecordType(Record);
5063 if (Result.isNull())
5064 return QualType();
5065 }
Mike Stump11289f42009-09-09 15:08:12 +00005066
John McCall550e0c22009-10-21 00:40:46 +00005067 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5068 NewTL.setNameLoc(TL.getNameLoc());
5069
5070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005071}
Mike Stump11289f42009-09-09 15:08:12 +00005072
5073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005074QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005075 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005076 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005077 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005078 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5079 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005080 if (!Enum)
5081 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005082
John McCall550e0c22009-10-21 00:40:46 +00005083 QualType Result = TL.getType();
5084 if (getDerived().AlwaysRebuild() ||
5085 Enum != T->getDecl()) {
5086 Result = getDerived().RebuildEnumType(Enum);
5087 if (Result.isNull())
5088 return QualType();
5089 }
Mike Stump11289f42009-09-09 15:08:12 +00005090
John McCall550e0c22009-10-21 00:40:46 +00005091 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5092 NewTL.setNameLoc(TL.getNameLoc());
5093
5094 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005095}
John McCallfcc33b02009-09-05 00:15:47 +00005096
John McCalle78aac42010-03-10 03:28:59 +00005097template<typename Derived>
5098QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5099 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005100 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005101 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5102 TL.getTypePtr()->getDecl());
5103 if (!D) return QualType();
5104
5105 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5106 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5107 return T;
5108}
5109
Douglas Gregord6ff3322009-08-04 16:50:30 +00005110template<typename Derived>
5111QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005112 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005113 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005114 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115}
5116
Mike Stump11289f42009-09-09 15:08:12 +00005117template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005118QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005119 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005120 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005121 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005122
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005123 // Substitute into the replacement type, which itself might involve something
5124 // that needs to be transformed. This only tends to occur with default
5125 // template arguments of template template parameters.
5126 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5127 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5128 if (Replacement.isNull())
5129 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005130
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005131 // Always canonicalize the replacement type.
5132 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5133 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005134 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005135 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005136
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005137 // Propagate type-source information.
5138 SubstTemplateTypeParmTypeLoc NewTL
5139 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5140 NewTL.setNameLoc(TL.getNameLoc());
5141 return Result;
5142
John McCallcebee162009-10-18 09:09:24 +00005143}
5144
5145template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005146QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5147 TypeLocBuilder &TLB,
5148 SubstTemplateTypeParmPackTypeLoc TL) {
5149 return TransformTypeSpecType(TLB, TL);
5150}
5151
5152template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005153QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005154 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005155 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005156 const TemplateSpecializationType *T = TL.getTypePtr();
5157
Douglas Gregordf846d12011-03-02 18:46:51 +00005158 // The nested-name-specifier never matters in a TemplateSpecializationType,
5159 // because we can't have a dependent nested-name-specifier anyway.
5160 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005161 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005162 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5163 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005164 if (Template.isNull())
5165 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005166
John McCall31f82722010-11-12 08:19:04 +00005167 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5168}
5169
Eli Friedman0dfb8892011-10-06 23:00:33 +00005170template<typename Derived>
5171QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5172 AtomicTypeLoc TL) {
5173 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5174 if (ValueType.isNull())
5175 return QualType();
5176
5177 QualType Result = TL.getType();
5178 if (getDerived().AlwaysRebuild() ||
5179 ValueType != TL.getValueLoc().getType()) {
5180 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5181 if (Result.isNull())
5182 return QualType();
5183 }
5184
5185 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5186 NewTL.setKWLoc(TL.getKWLoc());
5187 NewTL.setLParenLoc(TL.getLParenLoc());
5188 NewTL.setRParenLoc(TL.getRParenLoc());
5189
5190 return Result;
5191}
5192
Chad Rosier1dcde962012-08-08 18:46:20 +00005193 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005194 /// container that provides a \c getArgLoc() member function.
5195 ///
5196 /// This iterator is intended to be used with the iterator form of
5197 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5198 template<typename ArgLocContainer>
5199 class TemplateArgumentLocContainerIterator {
5200 ArgLocContainer *Container;
5201 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
Douglas Gregorfe921a72010-12-20 23:36:19 +00005203 public:
5204 typedef TemplateArgumentLoc value_type;
5205 typedef TemplateArgumentLoc reference;
5206 typedef int difference_type;
5207 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
Douglas Gregorfe921a72010-12-20 23:36:19 +00005209 class pointer {
5210 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005211
Douglas Gregorfe921a72010-12-20 23:36:19 +00005212 public:
5213 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005214
Douglas Gregorfe921a72010-12-20 23:36:19 +00005215 const TemplateArgumentLoc *operator->() const {
5216 return &Arg;
5217 }
5218 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
5220
Douglas Gregorfe921a72010-12-20 23:36:19 +00005221 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005222
Douglas Gregorfe921a72010-12-20 23:36:19 +00005223 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5224 unsigned Index)
5225 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005226
Douglas Gregorfe921a72010-12-20 23:36:19 +00005227 TemplateArgumentLocContainerIterator &operator++() {
5228 ++Index;
5229 return *this;
5230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005231
Douglas Gregorfe921a72010-12-20 23:36:19 +00005232 TemplateArgumentLocContainerIterator operator++(int) {
5233 TemplateArgumentLocContainerIterator Old(*this);
5234 ++(*this);
5235 return Old;
5236 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005237
Douglas Gregorfe921a72010-12-20 23:36:19 +00005238 TemplateArgumentLoc operator*() const {
5239 return Container->getArgLoc(Index);
5240 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005241
Douglas Gregorfe921a72010-12-20 23:36:19 +00005242 pointer operator->() const {
5243 return pointer(Container->getArgLoc(Index));
5244 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005245
Douglas Gregorfe921a72010-12-20 23:36:19 +00005246 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005247 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005248 return X.Container == Y.Container && X.Index == Y.Index;
5249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005250
Douglas Gregorfe921a72010-12-20 23:36:19 +00005251 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005252 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005253 return !(X == Y);
5254 }
5255 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
5257
John McCall31f82722010-11-12 08:19:04 +00005258template <typename Derived>
5259QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5260 TypeLocBuilder &TLB,
5261 TemplateSpecializationTypeLoc TL,
5262 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005263 TemplateArgumentListInfo NewTemplateArgs;
5264 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5265 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005266 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5267 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005268 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005269 ArgIterator(TL, TL.getNumArgs()),
5270 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005272
John McCall0ad16662009-10-29 08:12:44 +00005273 // FIXME: maybe don't rebuild if all the template arguments are the same.
5274
5275 QualType Result =
5276 getDerived().RebuildTemplateSpecializationType(Template,
5277 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005278 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005279
5280 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005281 // Specializations of template template parameters are represented as
5282 // TemplateSpecializationTypes, and substitution of type alias templates
5283 // within a dependent context can transform them into
5284 // DependentTemplateSpecializationTypes.
5285 if (isa<DependentTemplateSpecializationType>(Result)) {
5286 DependentTemplateSpecializationTypeLoc NewTL
5287 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005288 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005289 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005290 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005291 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005292 NewTL.setLAngleLoc(TL.getLAngleLoc());
5293 NewTL.setRAngleLoc(TL.getRAngleLoc());
5294 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5295 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5296 return Result;
5297 }
5298
John McCall0ad16662009-10-29 08:12:44 +00005299 TemplateSpecializationTypeLoc NewTL
5300 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005301 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005302 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5303 NewTL.setLAngleLoc(TL.getLAngleLoc());
5304 NewTL.setRAngleLoc(TL.getRAngleLoc());
5305 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5306 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005307 }
Mike Stump11289f42009-09-09 15:08:12 +00005308
John McCall0ad16662009-10-29 08:12:44 +00005309 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310}
Mike Stump11289f42009-09-09 15:08:12 +00005311
Douglas Gregor5a064722011-02-28 17:23:35 +00005312template <typename Derived>
5313QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5314 TypeLocBuilder &TLB,
5315 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005316 TemplateName Template,
5317 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005318 TemplateArgumentListInfo NewTemplateArgs;
5319 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5320 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5321 typedef TemplateArgumentLocContainerIterator<
5322 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005323 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005324 ArgIterator(TL, TL.getNumArgs()),
5325 NewTemplateArgs))
5326 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005327
Douglas Gregor5a064722011-02-28 17:23:35 +00005328 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005329
Douglas Gregor5a064722011-02-28 17:23:35 +00005330 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5331 QualType Result
5332 = getSema().Context.getDependentTemplateSpecializationType(
5333 TL.getTypePtr()->getKeyword(),
5334 DTN->getQualifier(),
5335 DTN->getIdentifier(),
5336 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005337
Douglas Gregor5a064722011-02-28 17:23:35 +00005338 DependentTemplateSpecializationTypeLoc NewTL
5339 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005340 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005341 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005342 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005343 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005344 NewTL.setLAngleLoc(TL.getLAngleLoc());
5345 NewTL.setRAngleLoc(TL.getRAngleLoc());
5346 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5347 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5348 return Result;
5349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005350
5351 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005352 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005353 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005354 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005355
Douglas Gregor5a064722011-02-28 17:23:35 +00005356 if (!Result.isNull()) {
5357 /// FIXME: Wrap this in an elaborated-type-specifier?
5358 TemplateSpecializationTypeLoc NewTL
5359 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005360 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005361 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005362 NewTL.setLAngleLoc(TL.getLAngleLoc());
5363 NewTL.setRAngleLoc(TL.getRAngleLoc());
5364 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5365 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005367
Douglas Gregor5a064722011-02-28 17:23:35 +00005368 return Result;
5369}
5370
Mike Stump11289f42009-09-09 15:08:12 +00005371template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005372QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005373TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005374 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005375 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005376
Douglas Gregor844cb502011-03-01 18:12:44 +00005377 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005378 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005379 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005380 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005381 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5382 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005383 return QualType();
5384 }
Mike Stump11289f42009-09-09 15:08:12 +00005385
John McCall31f82722010-11-12 08:19:04 +00005386 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5387 if (NamedT.isNull())
5388 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005389
Richard Smith3f1b5d02011-05-05 21:57:07 +00005390 // C++0x [dcl.type.elab]p2:
5391 // If the identifier resolves to a typedef-name or the simple-template-id
5392 // resolves to an alias template specialization, the
5393 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005394 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5395 if (const TemplateSpecializationType *TST =
5396 NamedT->getAs<TemplateSpecializationType>()) {
5397 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005398 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5399 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005400 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5401 diag::err_tag_reference_non_tag) << 4;
5402 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5403 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005404 }
5405 }
5406
John McCall550e0c22009-10-21 00:40:46 +00005407 QualType Result = TL.getType();
5408 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005409 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005410 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005411 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005412 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005413 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005414 if (Result.isNull())
5415 return QualType();
5416 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005417
Abramo Bagnara6150c882010-05-11 21:36:43 +00005418 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005419 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005420 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005421 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005422}
Mike Stump11289f42009-09-09 15:08:12 +00005423
5424template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005425QualType TreeTransform<Derived>::TransformAttributedType(
5426 TypeLocBuilder &TLB,
5427 AttributedTypeLoc TL) {
5428 const AttributedType *oldType = TL.getTypePtr();
5429 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5430 if (modifiedType.isNull())
5431 return QualType();
5432
5433 QualType result = TL.getType();
5434
5435 // FIXME: dependent operand expressions?
5436 if (getDerived().AlwaysRebuild() ||
5437 modifiedType != oldType->getModifiedType()) {
5438 // TODO: this is really lame; we should really be rebuilding the
5439 // equivalent type from first principles.
5440 QualType equivalentType
5441 = getDerived().TransformType(oldType->getEquivalentType());
5442 if (equivalentType.isNull())
5443 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005444
5445 // Check whether we can add nullability; it is only represented as
5446 // type sugar, and therefore cannot be diagnosed in any other way.
5447 if (auto nullability = oldType->getImmediateNullability()) {
5448 if (!modifiedType->canHaveNullability()) {
5449 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005450 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005451 return QualType();
5452 }
5453 }
5454
John McCall81904512011-01-06 01:58:22 +00005455 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5456 modifiedType,
5457 equivalentType);
5458 }
5459
5460 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5461 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5462 if (TL.hasAttrOperand())
5463 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5464 if (TL.hasAttrExprOperand())
5465 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5466 else if (TL.hasAttrEnumOperand())
5467 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5468
5469 return result;
5470}
5471
5472template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005473QualType
5474TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5475 ParenTypeLoc TL) {
5476 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5477 if (Inner.isNull())
5478 return QualType();
5479
5480 QualType Result = TL.getType();
5481 if (getDerived().AlwaysRebuild() ||
5482 Inner != TL.getInnerLoc().getType()) {
5483 Result = getDerived().RebuildParenType(Inner);
5484 if (Result.isNull())
5485 return QualType();
5486 }
5487
5488 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5489 NewTL.setLParenLoc(TL.getLParenLoc());
5490 NewTL.setRParenLoc(TL.getRParenLoc());
5491 return Result;
5492}
5493
5494template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005495QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005496 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005497 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005498
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005499 NestedNameSpecifierLoc QualifierLoc
5500 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5501 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005502 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005503
John McCallc392f372010-06-11 00:33:02 +00005504 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005505 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005506 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005507 QualifierLoc,
5508 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005509 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005510 if (Result.isNull())
5511 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005512
Abramo Bagnarad7548482010-05-19 21:37:53 +00005513 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5514 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005515 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5516
Abramo Bagnarad7548482010-05-19 21:37:53 +00005517 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005518 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005519 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005520 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005521 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005522 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005523 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005524 NewTL.setNameLoc(TL.getNameLoc());
5525 }
John McCall550e0c22009-10-21 00:40:46 +00005526 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005527}
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregord6ff3322009-08-04 16:50:30 +00005529template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005530QualType TreeTransform<Derived>::
5531 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005532 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005533 NestedNameSpecifierLoc QualifierLoc;
5534 if (TL.getQualifierLoc()) {
5535 QualifierLoc
5536 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5537 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005538 return QualType();
5539 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005540
John McCall31f82722010-11-12 08:19:04 +00005541 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005542 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005543}
5544
5545template<typename Derived>
5546QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005547TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5548 DependentTemplateSpecializationTypeLoc TL,
5549 NestedNameSpecifierLoc QualifierLoc) {
5550 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005551
Douglas Gregora7a795b2011-03-01 20:11:18 +00005552 TemplateArgumentListInfo NewTemplateArgs;
5553 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5554 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005555
Douglas Gregora7a795b2011-03-01 20:11:18 +00005556 typedef TemplateArgumentLocContainerIterator<
5557 DependentTemplateSpecializationTypeLoc> ArgIterator;
5558 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5559 ArgIterator(TL, TL.getNumArgs()),
5560 NewTemplateArgs))
5561 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005562
Douglas Gregora7a795b2011-03-01 20:11:18 +00005563 QualType Result
5564 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5565 QualifierLoc,
5566 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005567 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005568 NewTemplateArgs);
5569 if (Result.isNull())
5570 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005571
Douglas Gregora7a795b2011-03-01 20:11:18 +00005572 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5573 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005574
Douglas Gregora7a795b2011-03-01 20:11:18 +00005575 // Copy information relevant to the template specialization.
5576 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005577 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005578 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005579 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005580 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5581 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005582 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005583 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregora7a795b2011-03-01 20:11:18 +00005585 // Copy information relevant to the elaborated type.
5586 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005587 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005588 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005589 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5590 DependentTemplateSpecializationTypeLoc SpecTL
5591 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005592 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005593 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005594 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005595 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005596 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5597 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005598 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005599 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005600 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005601 TemplateSpecializationTypeLoc SpecTL
5602 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005603 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005604 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005605 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5606 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005607 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005608 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005609 }
5610 return Result;
5611}
5612
5613template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005614QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5615 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005616 QualType Pattern
5617 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005618 if (Pattern.isNull())
5619 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005620
5621 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005622 if (getDerived().AlwaysRebuild() ||
5623 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005624 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005625 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005626 TL.getEllipsisLoc(),
5627 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005628 if (Result.isNull())
5629 return QualType();
5630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005631
Douglas Gregor822d0302011-01-12 17:07:58 +00005632 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5633 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5634 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005635}
5636
5637template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005638QualType
5639TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005640 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005641 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005642 TLB.pushFullCopy(TL);
5643 return TL.getType();
5644}
5645
5646template<typename Derived>
5647QualType
5648TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005649 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005650 // Transform base type.
5651 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5652 if (BaseType.isNull())
5653 return QualType();
5654
5655 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5656
5657 // Transform type arguments.
5658 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5659 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5660 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5661 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5662 QualType TypeArg = TypeArgInfo->getType();
5663 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5664 AnyChanged = true;
5665
5666 // We have a pack expansion. Instantiate it.
5667 const auto *PackExpansion = PackExpansionLoc.getType()
5668 ->castAs<PackExpansionType>();
5669 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5670 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5671 Unexpanded);
5672 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5673
5674 // Determine whether the set of unexpanded parameter packs can
5675 // and should be expanded.
5676 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5677 bool Expand = false;
5678 bool RetainExpansion = false;
5679 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5680 if (getDerived().TryExpandParameterPacks(
5681 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5682 Unexpanded, Expand, RetainExpansion, NumExpansions))
5683 return QualType();
5684
5685 if (!Expand) {
5686 // We can't expand this pack expansion into separate arguments yet;
5687 // just substitute into the pattern and create a new pack expansion
5688 // type.
5689 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5690
5691 TypeLocBuilder TypeArgBuilder;
5692 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5693 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5694 PatternLoc);
5695 if (NewPatternType.isNull())
5696 return QualType();
5697
5698 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5699 NewPatternType, NumExpansions);
5700 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5701 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5702 NewTypeArgInfos.push_back(
5703 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5704 continue;
5705 }
5706
5707 // Substitute into the pack expansion pattern for each slice of the
5708 // pack.
5709 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5710 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5711
5712 TypeLocBuilder TypeArgBuilder;
5713 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5714
5715 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5716 PatternLoc);
5717 if (NewTypeArg.isNull())
5718 return QualType();
5719
5720 NewTypeArgInfos.push_back(
5721 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5722 }
5723
5724 continue;
5725 }
5726
5727 TypeLocBuilder TypeArgBuilder;
5728 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5729 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5730 if (NewTypeArg.isNull())
5731 return QualType();
5732
5733 // If nothing changed, just keep the old TypeSourceInfo.
5734 if (NewTypeArg == TypeArg) {
5735 NewTypeArgInfos.push_back(TypeArgInfo);
5736 continue;
5737 }
5738
5739 NewTypeArgInfos.push_back(
5740 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5741 AnyChanged = true;
5742 }
5743
5744 QualType Result = TL.getType();
5745 if (getDerived().AlwaysRebuild() || AnyChanged) {
5746 // Rebuild the type.
5747 Result = getDerived().RebuildObjCObjectType(
5748 BaseType,
5749 TL.getLocStart(),
5750 TL.getTypeArgsLAngleLoc(),
5751 NewTypeArgInfos,
5752 TL.getTypeArgsRAngleLoc(),
5753 TL.getProtocolLAngleLoc(),
5754 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5755 TL.getNumProtocols()),
5756 TL.getProtocolLocs(),
5757 TL.getProtocolRAngleLoc());
5758
5759 if (Result.isNull())
5760 return QualType();
5761 }
5762
5763 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5764 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5765 NewT.setHasBaseTypeAsWritten(true);
5766 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5767 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5768 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5769 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5770 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5771 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5772 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5773 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5774 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005775}
Mike Stump11289f42009-09-09 15:08:12 +00005776
5777template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005778QualType
5779TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005780 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005781 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5782 if (PointeeType.isNull())
5783 return QualType();
5784
5785 QualType Result = TL.getType();
5786 if (getDerived().AlwaysRebuild() ||
5787 PointeeType != TL.getPointeeLoc().getType()) {
5788 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5789 TL.getStarLoc());
5790 if (Result.isNull())
5791 return QualType();
5792 }
5793
5794 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5795 NewT.setStarLoc(TL.getStarLoc());
5796 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005797}
5798
Douglas Gregord6ff3322009-08-04 16:50:30 +00005799//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005800// Statement transformation
5801//===----------------------------------------------------------------------===//
5802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005803StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005804TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005805 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005806}
5807
5808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005809StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005810TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5811 return getDerived().TransformCompoundStmt(S, false);
5812}
5813
5814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005815StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005816TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005817 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005818 Sema::CompoundScopeRAII CompoundScope(getSema());
5819
John McCall1ababa62010-08-27 19:56:05 +00005820 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005821 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005822 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005823 for (auto *B : S->body()) {
5824 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005825 if (Result.isInvalid()) {
5826 // Immediately fail if this was a DeclStmt, since it's very
5827 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005828 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005829 return StmtError();
5830
5831 // Otherwise, just keep processing substatements and fail later.
5832 SubStmtInvalid = true;
5833 continue;
5834 }
Mike Stump11289f42009-09-09 15:08:12 +00005835
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005836 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005837 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005838 }
Mike Stump11289f42009-09-09 15:08:12 +00005839
John McCall1ababa62010-08-27 19:56:05 +00005840 if (SubStmtInvalid)
5841 return StmtError();
5842
Douglas Gregorebe10102009-08-20 07:17:43 +00005843 if (!getDerived().AlwaysRebuild() &&
5844 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005845 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005846
5847 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005848 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 S->getRBracLoc(),
5850 IsStmtExpr);
5851}
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregorebe10102009-08-20 07:17:43 +00005853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005854StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005855TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005856 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005857 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005858 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5859 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005860
Eli Friedman06577382009-11-19 03:14:00 +00005861 // Transform the left-hand case value.
5862 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005863 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005864 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005865 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005866
Eli Friedman06577382009-11-19 03:14:00 +00005867 // Transform the right-hand case value (for the GNU case-range extension).
5868 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005869 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005870 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005872 }
Mike Stump11289f42009-09-09 15:08:12 +00005873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874 // Build the case statement.
5875 // Case statements are always rebuilt so that they will attached to their
5876 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005877 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005878 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005879 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005880 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005881 S->getColonLoc());
5882 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005883 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregorebe10102009-08-20 07:17:43 +00005885 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005886 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005887 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregorebe10102009-08-20 07:17:43 +00005890 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005891 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005892}
5893
5894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005895StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005896TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005897 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005898 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005899 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005900 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005901
Douglas Gregorebe10102009-08-20 07:17:43 +00005902 // Default statements are always rebuilt
5903 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005904 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005905}
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregorebe10102009-08-20 07:17:43 +00005907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005908StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005909TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005910 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005911 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005912 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005913
Chris Lattnercab02a62011-02-17 20:34:02 +00005914 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5915 S->getDecl());
5916 if (!LD)
5917 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005918
5919
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005921 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005922 cast<LabelDecl>(LD), SourceLocation(),
5923 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005924}
Mike Stump11289f42009-09-09 15:08:12 +00005925
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005926template <typename Derived>
5927const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5928 if (!R)
5929 return R;
5930
5931 switch (R->getKind()) {
5932// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5933#define ATTR(X)
5934#define PRAGMA_SPELLING_ATTR(X) \
5935 case attr::X: \
5936 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5937#include "clang/Basic/AttrList.inc"
5938 default:
5939 return R;
5940 }
5941}
5942
5943template <typename Derived>
5944StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5945 bool AttrsChanged = false;
5946 SmallVector<const Attr *, 1> Attrs;
5947
5948 // Visit attributes and keep track if any are transformed.
5949 for (const auto *I : S->getAttrs()) {
5950 const Attr *R = getDerived().TransformAttr(I);
5951 AttrsChanged |= (I != R);
5952 Attrs.push_back(R);
5953 }
5954
Richard Smithc202b282012-04-14 00:33:13 +00005955 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5956 if (SubStmt.isInvalid())
5957 return StmtError();
5958
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005959 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005960 return S;
5961
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005962 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005963 SubStmt.get());
5964}
5965
5966template<typename Derived>
5967StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005968TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005969 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005970 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005971 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005972 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005973 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005974 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005975 getDerived().TransformDefinition(
5976 S->getConditionVariable()->getLocation(),
5977 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00005978 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005979 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005980 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00005981 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005983 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005984 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005985
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005986 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005987 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00005988 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005989 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005990 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005991 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00005992
John McCallb268a282010-08-23 23:25:46 +00005993 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005994 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005995 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005996
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005997 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00005998 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005999 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006000
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006002 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006003 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006004 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregorebe10102009-08-20 07:17:43 +00006006 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006007 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006008 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregorebe10102009-08-20 07:17:43 +00006011 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006012 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006013 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006014 Then.get() == S->getThen() &&
6015 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006016 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006017
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006018 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006019 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006020 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006021}
6022
6023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006024StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006025TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006027 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006028 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006029 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006030 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006031 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006032 getDerived().TransformDefinition(
6033 S->getConditionVariable()->getLocation(),
6034 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006035 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006037 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006038 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006039
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006040 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006042 }
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006045 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006046 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006047 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006048 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006049 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006050
Douglas Gregorebe10102009-08-20 07:17:43 +00006051 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006052 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006053 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006054 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006055
Douglas Gregorebe10102009-08-20 07:17:43 +00006056 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006057 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6058 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006059}
Mike Stump11289f42009-09-09 15:08:12 +00006060
Douglas Gregorebe10102009-08-20 07:17:43 +00006061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006063TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006064 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006065 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006066 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006067 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006068 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006069 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006070 getDerived().TransformDefinition(
6071 S->getConditionVariable()->getLocation(),
6072 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006073 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006075 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006076 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006077
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006078 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006080
6081 if (S->getCond()) {
6082 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006083 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6084 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006085 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006086 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006087 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006088 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006089 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006090 }
Mike Stump11289f42009-09-09 15:08:12 +00006091
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006092 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006093 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006094 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006095
Douglas Gregorebe10102009-08-20 07:17:43 +00006096 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006097 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006098 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006099 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregorebe10102009-08-20 07:17:43 +00006101 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006102 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006103 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006104 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006105 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006107 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006108 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006109}
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregorebe10102009-08-20 07:17:43 +00006111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006112StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006113TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006114 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006115 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006116 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006118
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006119 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006120 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006121 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006123
Douglas Gregorebe10102009-08-20 07:17:43 +00006124 if (!getDerived().AlwaysRebuild() &&
6125 Cond.get() == S->getCond() &&
6126 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006127 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006128
John McCallb268a282010-08-23 23:25:46 +00006129 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6130 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006131 S->getRParenLoc());
6132}
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregorebe10102009-08-20 07:17:43 +00006134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006135StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006136TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006138 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorebe10102009-08-20 07:17:43 +00006142 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006143 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006144 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006145 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006146 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006147 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006148 getDerived().TransformDefinition(
6149 S->getConditionVariable()->getLocation(),
6150 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006151 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006152 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006153 } else {
6154 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006156 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006157 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006158
6159 if (S->getCond()) {
6160 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006161 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6162 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006163 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006164 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006165 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006166
John McCallb268a282010-08-23 23:25:46 +00006167 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006168 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006169 }
Mike Stump11289f42009-09-09 15:08:12 +00006170
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006171 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006172 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006174
Douglas Gregorebe10102009-08-20 07:17:43 +00006175 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006176 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006177 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006179
Richard Smith945f8d32013-01-14 22:39:08 +00006180 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006181 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006182 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006183
Douglas Gregorebe10102009-08-20 07:17:43 +00006184 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006185 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006186 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006188
Douglas Gregorebe10102009-08-20 07:17:43 +00006189 if (!getDerived().AlwaysRebuild() &&
6190 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006191 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006192 Inc.get() == S->getInc() &&
6193 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006194 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006195
Douglas Gregorebe10102009-08-20 07:17:43 +00006196 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006197 Init.get(), FullCond, ConditionVar,
6198 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006199}
6200
6201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006202StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006203TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006204 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6205 S->getLabel());
6206 if (!LD)
6207 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006208
Douglas Gregorebe10102009-08-20 07:17:43 +00006209 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006210 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006211 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006212}
6213
6214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006215StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006216TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006217 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006220 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregorebe10102009-08-20 07:17:43 +00006222 if (!getDerived().AlwaysRebuild() &&
6223 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006224 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006225
6226 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006227 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006228}
6229
6230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006231StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006232TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006233 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006234}
Mike Stump11289f42009-09-09 15:08:12 +00006235
Douglas Gregorebe10102009-08-20 07:17:43 +00006236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006237StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006238TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006239 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006240}
Mike Stump11289f42009-09-09 15:08:12 +00006241
Douglas Gregorebe10102009-08-20 07:17:43 +00006242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006243StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006244TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006245 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6246 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006247 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006248 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006249
Mike Stump11289f42009-09-09 15:08:12 +00006250 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006251 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006252 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006253}
Mike Stump11289f42009-09-09 15:08:12 +00006254
Douglas Gregorebe10102009-08-20 07:17:43 +00006255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006256StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006257TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006258 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006259 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006260 for (auto *D : S->decls()) {
6261 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006262 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006264
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006265 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006266 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268 Decls.push_back(Transformed);
6269 }
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregorebe10102009-08-20 07:17:43 +00006271 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006272 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006273
Rafael Espindolaab417692013-07-09 12:05:01 +00006274 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006275}
Mike Stump11289f42009-09-09 15:08:12 +00006276
Douglas Gregorebe10102009-08-20 07:17:43 +00006277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006278StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006279TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006280
Benjamin Kramerf0623432012-08-23 22:51:59 +00006281 SmallVector<Expr*, 8> Constraints;
6282 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006283 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006284
John McCalldadc5752010-08-24 06:29:42 +00006285 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006286 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006287
6288 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006289
Anders Carlssonaaeef072010-01-24 05:50:09 +00006290 // Go through the outputs.
6291 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006292 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006293
Anders Carlssonaaeef072010-01-24 05:50:09 +00006294 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006295 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006296
Anders Carlssonaaeef072010-01-24 05:50:09 +00006297 // Transform the output expr.
6298 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006299 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006300 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006302
Anders Carlssonaaeef072010-01-24 05:50:09 +00006303 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006304
John McCallb268a282010-08-23 23:25:46 +00006305 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006307
Anders Carlssonaaeef072010-01-24 05:50:09 +00006308 // Go through the inputs.
6309 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006310 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006311
Anders Carlssonaaeef072010-01-24 05:50:09 +00006312 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006313 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006314
Anders Carlssonaaeef072010-01-24 05:50:09 +00006315 // Transform the input expr.
6316 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006317 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006318 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006319 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006320
Anders Carlssonaaeef072010-01-24 05:50:09 +00006321 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
John McCallb268a282010-08-23 23:25:46 +00006323 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006325
Anders Carlssonaaeef072010-01-24 05:50:09 +00006326 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006327 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006328
6329 // Go through the clobbers.
6330 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006331 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006332
6333 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006334 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006335 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6336 S->isVolatile(), S->getNumOutputs(),
6337 S->getNumInputs(), Names.data(),
6338 Constraints, Exprs, AsmString.get(),
6339 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006340}
6341
Chad Rosier32503022012-06-11 20:47:18 +00006342template<typename Derived>
6343StmtResult
6344TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006345 ArrayRef<Token> AsmToks =
6346 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006347
John McCallf413f5e2013-05-03 00:10:13 +00006348 bool HadError = false, HadChange = false;
6349
6350 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6351 SmallVector<Expr*, 8> TransformedExprs;
6352 TransformedExprs.reserve(SrcExprs.size());
6353 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6354 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6355 if (!Result.isUsable()) {
6356 HadError = true;
6357 } else {
6358 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006359 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006360 }
6361 }
6362
6363 if (HadError) return StmtError();
6364 if (!HadChange && !getDerived().AlwaysRebuild())
6365 return Owned(S);
6366
Chad Rosierb6f46c12012-08-15 16:53:30 +00006367 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006368 AsmToks, S->getAsmString(),
6369 S->getNumOutputs(), S->getNumInputs(),
6370 S->getAllConstraints(), S->getClobbers(),
6371 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006372}
Douglas Gregorebe10102009-08-20 07:17:43 +00006373
6374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006375StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006376TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006377 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006378 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006379 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006381
Douglas Gregor96c79492010-04-23 22:50:49 +00006382 // Transform the @catch statements (if present).
6383 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006384 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006385 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006386 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006387 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006388 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006389 if (Catch.get() != S->getCatchStmt(I))
6390 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006391 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006392 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006393
Douglas Gregor306de2f2010-04-22 23:59:56 +00006394 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006395 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006396 if (S->getFinallyStmt()) {
6397 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6398 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006399 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006400 }
6401
6402 // If nothing changed, just retain this statement.
6403 if (!getDerived().AlwaysRebuild() &&
6404 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006405 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006406 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006407 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006408
Douglas Gregor306de2f2010-04-22 23:59:56 +00006409 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006410 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006411 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006412}
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregorebe10102009-08-20 07:17:43 +00006414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006416TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006417 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006418 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006419 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006420 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006421 if (FromVar->getTypeSourceInfo()) {
6422 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6423 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006424 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006426
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006427 QualType T;
6428 if (TSInfo)
6429 T = TSInfo->getType();
6430 else {
6431 T = getDerived().TransformType(FromVar->getType());
6432 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006433 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006434 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006435
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006436 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6437 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006438 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006440
John McCalldadc5752010-08-24 06:29:42 +00006441 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006442 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006443 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006444
6445 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006446 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006447 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006448}
Mike Stump11289f42009-09-09 15:08:12 +00006449
Douglas Gregorebe10102009-08-20 07:17:43 +00006450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006451StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006452TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006453 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006454 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006455 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006457
Douglas Gregor306de2f2010-04-22 23:59:56 +00006458 // If nothing changed, just retain this statement.
6459 if (!getDerived().AlwaysRebuild() &&
6460 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006461 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006462
6463 // Build a new statement.
6464 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006465 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006466}
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregorebe10102009-08-20 07:17:43 +00006468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006469StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006470TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006471 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006472 if (S->getThrowExpr()) {
6473 Operand = getDerived().TransformExpr(S->getThrowExpr());
6474 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006477
Douglas Gregor2900c162010-04-22 21:44:01 +00006478 if (!getDerived().AlwaysRebuild() &&
6479 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006480 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006481
John McCallb268a282010-08-23 23:25:46 +00006482 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006483}
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregorebe10102009-08-20 07:17:43 +00006485template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006486StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006487TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006488 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006489 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006490 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006491 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006492 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006493 Object =
6494 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6495 Object.get());
6496 if (Object.isInvalid())
6497 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006498
Douglas Gregor6148de72010-04-22 22:01:21 +00006499 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006500 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006501 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006502 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006503
Douglas Gregor6148de72010-04-22 22:01:21 +00006504 // If nothing change, just retain the current statement.
6505 if (!getDerived().AlwaysRebuild() &&
6506 Object.get() == S->getSynchExpr() &&
6507 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006508 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006509
6510 // Build a new statement.
6511 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006512 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006513}
6514
6515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516StmtResult
John McCall31168b02011-06-15 23:02:42 +00006517TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6518 ObjCAutoreleasePoolStmt *S) {
6519 // Transform the body.
6520 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6521 if (Body.isInvalid())
6522 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006523
John McCall31168b02011-06-15 23:02:42 +00006524 // If nothing changed, just retain this statement.
6525 if (!getDerived().AlwaysRebuild() &&
6526 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006527 return S;
John McCall31168b02011-06-15 23:02:42 +00006528
6529 // Build a new statement.
6530 return getDerived().RebuildObjCAutoreleasePoolStmt(
6531 S->getAtLoc(), Body.get());
6532}
6533
6534template<typename Derived>
6535StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006536TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006537 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006538 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006539 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006540 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006541 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006542
Douglas Gregorf68a5082010-04-22 23:10:45 +00006543 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006544 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006545 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006546 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006547
Douglas Gregorf68a5082010-04-22 23:10:45 +00006548 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006549 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006550 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006551 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006552
Douglas Gregorf68a5082010-04-22 23:10:45 +00006553 // If nothing changed, just retain this statement.
6554 if (!getDerived().AlwaysRebuild() &&
6555 Element.get() == S->getElement() &&
6556 Collection.get() == S->getCollection() &&
6557 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006558 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006559
Douglas Gregorf68a5082010-04-22 23:10:45 +00006560 // Build a new statement.
6561 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006562 Element.get(),
6563 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006564 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006565 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006566}
6567
David Majnemer5f7efef2013-10-15 09:50:08 +00006568template <typename Derived>
6569StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006570 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006571 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006572 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6573 TypeSourceInfo *T =
6574 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006575 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006577
David Majnemer5f7efef2013-10-15 09:50:08 +00006578 Var = getDerived().RebuildExceptionDecl(
6579 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6580 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006581 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006582 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006583 }
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregorebe10102009-08-20 07:17:43 +00006585 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006586 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006587 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006588 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006589
David Majnemer5f7efef2013-10-15 09:50:08 +00006590 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006591 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006592 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006593
David Majnemer5f7efef2013-10-15 09:50:08 +00006594 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006595}
Mike Stump11289f42009-09-09 15:08:12 +00006596
David Majnemer5f7efef2013-10-15 09:50:08 +00006597template <typename Derived>
6598StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006599 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006600 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006601 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006602 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006603
Douglas Gregorebe10102009-08-20 07:17:43 +00006604 // Transform the handlers.
6605 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006606 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006607 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006608 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006609 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006610 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006611
Douglas Gregorebe10102009-08-20 07:17:43 +00006612 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006613 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 }
Mike Stump11289f42009-09-09 15:08:12 +00006615
David Majnemer5f7efef2013-10-15 09:50:08 +00006616 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006617 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006618 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006619
John McCallb268a282010-08-23 23:25:46 +00006620 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006621 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006622}
Mike Stump11289f42009-09-09 15:08:12 +00006623
Richard Smith02e85f32011-04-14 22:09:26 +00006624template<typename Derived>
6625StmtResult
6626TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6627 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6628 if (Range.isInvalid())
6629 return StmtError();
6630
6631 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6632 if (BeginEnd.isInvalid())
6633 return StmtError();
6634
6635 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6636 if (Cond.isInvalid())
6637 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006638 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006639 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006640 if (Cond.isInvalid())
6641 return StmtError();
6642 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006643 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006644
6645 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6646 if (Inc.isInvalid())
6647 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006648 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006649 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006650
6651 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6652 if (LoopVar.isInvalid())
6653 return StmtError();
6654
6655 StmtResult NewStmt = S;
6656 if (getDerived().AlwaysRebuild() ||
6657 Range.get() != S->getRangeStmt() ||
6658 BeginEnd.get() != S->getBeginEndStmt() ||
6659 Cond.get() != S->getCond() ||
6660 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006661 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006662 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6663 S->getColonLoc(), Range.get(),
6664 BeginEnd.get(), Cond.get(),
6665 Inc.get(), LoopVar.get(),
6666 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006667 if (NewStmt.isInvalid())
6668 return StmtError();
6669 }
Richard Smith02e85f32011-04-14 22:09:26 +00006670
6671 StmtResult Body = getDerived().TransformStmt(S->getBody());
6672 if (Body.isInvalid())
6673 return StmtError();
6674
6675 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6676 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006677 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006678 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6679 S->getColonLoc(), Range.get(),
6680 BeginEnd.get(), Cond.get(),
6681 Inc.get(), LoopVar.get(),
6682 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006683 if (NewStmt.isInvalid())
6684 return StmtError();
6685 }
Richard Smith02e85f32011-04-14 22:09:26 +00006686
6687 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006688 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006689
6690 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6691}
6692
John Wiegley1c0675e2011-04-28 01:08:34 +00006693template<typename Derived>
6694StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006695TreeTransform<Derived>::TransformMSDependentExistsStmt(
6696 MSDependentExistsStmt *S) {
6697 // Transform the nested-name-specifier, if any.
6698 NestedNameSpecifierLoc QualifierLoc;
6699 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006700 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006701 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6702 if (!QualifierLoc)
6703 return StmtError();
6704 }
6705
6706 // Transform the declaration name.
6707 DeclarationNameInfo NameInfo = S->getNameInfo();
6708 if (NameInfo.getName()) {
6709 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6710 if (!NameInfo.getName())
6711 return StmtError();
6712 }
6713
6714 // Check whether anything changed.
6715 if (!getDerived().AlwaysRebuild() &&
6716 QualifierLoc == S->getQualifierLoc() &&
6717 NameInfo.getName() == S->getNameInfo().getName())
6718 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006719
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006720 // Determine whether this name exists, if we can.
6721 CXXScopeSpec SS;
6722 SS.Adopt(QualifierLoc);
6723 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006724 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006725 case Sema::IER_Exists:
6726 if (S->isIfExists())
6727 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006728
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006729 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6730
6731 case Sema::IER_DoesNotExist:
6732 if (S->isIfNotExists())
6733 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006734
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006735 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006736
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006737 case Sema::IER_Dependent:
6738 Dependent = true;
6739 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006740
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006741 case Sema::IER_Error:
6742 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006744
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006745 // We need to continue with the instantiation, so do so now.
6746 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6747 if (SubStmt.isInvalid())
6748 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006749
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006750 // If we have resolved the name, just transform to the substatement.
6751 if (!Dependent)
6752 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006753
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006754 // The name is still dependent, so build a dependent expression again.
6755 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6756 S->isIfExists(),
6757 QualifierLoc,
6758 NameInfo,
6759 SubStmt.get());
6760}
6761
6762template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006763ExprResult
6764TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6765 NestedNameSpecifierLoc QualifierLoc;
6766 if (E->getQualifierLoc()) {
6767 QualifierLoc
6768 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6769 if (!QualifierLoc)
6770 return ExprError();
6771 }
6772
6773 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6774 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6775 if (!PD)
6776 return ExprError();
6777
6778 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6779 if (Base.isInvalid())
6780 return ExprError();
6781
6782 return new (SemaRef.getASTContext())
6783 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6784 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6785 QualifierLoc, E->getMemberLoc());
6786}
6787
David Majnemerfad8f482013-10-15 09:33:02 +00006788template <typename Derived>
6789StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006790 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006791 if (TryBlock.isInvalid())
6792 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006793
6794 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006795 if (Handler.isInvalid())
6796 return StmtError();
6797
David Majnemerfad8f482013-10-15 09:33:02 +00006798 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6799 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006800 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006801
Warren Huntf6be4cb2014-07-25 20:52:51 +00006802 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6803 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006804}
6805
David Majnemerfad8f482013-10-15 09:33:02 +00006806template <typename Derived>
6807StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006808 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006809 if (Block.isInvalid())
6810 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006811
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006812 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006813}
6814
David Majnemerfad8f482013-10-15 09:33:02 +00006815template <typename Derived>
6816StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006817 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006818 if (FilterExpr.isInvalid())
6819 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006820
David Majnemer7e755502013-10-15 09:30:14 +00006821 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006822 if (Block.isInvalid())
6823 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006824
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006825 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6826 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006827}
6828
David Majnemerfad8f482013-10-15 09:33:02 +00006829template <typename Derived>
6830StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6831 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006832 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6833 else
6834 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6835}
6836
Nico Weber9b982072014-07-07 00:12:30 +00006837template<typename Derived>
6838StmtResult
6839TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6840 return S;
6841}
6842
Alexander Musman64d33f12014-06-04 07:53:32 +00006843//===----------------------------------------------------------------------===//
6844// OpenMP directive transformation
6845//===----------------------------------------------------------------------===//
6846template <typename Derived>
6847StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6848 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006849
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006850 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006851 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006852 ArrayRef<OMPClause *> Clauses = D->clauses();
6853 TClauses.reserve(Clauses.size());
6854 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6855 I != E; ++I) {
6856 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006857 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006858 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006859 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006860 if (Clause)
6861 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006862 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006863 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006864 }
6865 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006866 StmtResult AssociatedStmt;
6867 if (D->hasAssociatedStmt()) {
6868 if (!D->getAssociatedStmt()) {
6869 return StmtError();
6870 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006871 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6872 /*CurScope=*/nullptr);
6873 StmtResult Body;
6874 {
6875 Sema::CompoundScopeRAII CompoundScope(getSema());
6876 Body = getDerived().TransformStmt(
6877 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6878 }
6879 AssociatedStmt =
6880 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006881 if (AssociatedStmt.isInvalid()) {
6882 return StmtError();
6883 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006884 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006885 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006886 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006887 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006888
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006889 // Transform directive name for 'omp critical' directive.
6890 DeclarationNameInfo DirName;
6891 if (D->getDirectiveKind() == OMPD_critical) {
6892 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6893 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6894 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006895 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6896 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6897 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006898 } else if (D->getDirectiveKind() == OMPD_cancel) {
6899 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006900 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006901
Alexander Musman64d33f12014-06-04 07:53:32 +00006902 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006903 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6904 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006905}
6906
Alexander Musman64d33f12014-06-04 07:53:32 +00006907template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006908StmtResult
6909TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6910 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006911 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6912 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006913 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6914 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6915 return Res;
6916}
6917
Alexander Musman64d33f12014-06-04 07:53:32 +00006918template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006919StmtResult
6920TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6921 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006922 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6923 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006924 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6925 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006926 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006927}
6928
Alexey Bataevf29276e2014-06-18 04:14:57 +00006929template <typename Derived>
6930StmtResult
6931TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6932 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006933 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6934 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006935 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6936 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6937 return Res;
6938}
6939
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006940template <typename Derived>
6941StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006942TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6943 DeclarationNameInfo DirName;
6944 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6945 D->getLocStart());
6946 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6947 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6948 return Res;
6949}
6950
6951template <typename Derived>
6952StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006953TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6954 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006955 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6956 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006957 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6958 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6959 return Res;
6960}
6961
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006962template <typename Derived>
6963StmtResult
6964TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6965 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006966 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6967 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006968 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6969 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6970 return Res;
6971}
6972
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006973template <typename Derived>
6974StmtResult
6975TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6976 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006977 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
6978 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006979 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6980 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6981 return Res;
6982}
6983
Alexey Bataev4acb8592014-07-07 13:01:15 +00006984template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00006985StmtResult
6986TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
6987 DeclarationNameInfo DirName;
6988 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
6989 D->getLocStart());
6990 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6991 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6992 return Res;
6993}
6994
6995template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006996StmtResult
6997TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
6998 getDerived().getSema().StartOpenMPDSABlock(
6999 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7001 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7002 return Res;
7003}
7004
7005template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007006StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7007 OMPParallelForDirective *D) {
7008 DeclarationNameInfo DirName;
7009 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7010 nullptr, D->getLocStart());
7011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7013 return Res;
7014}
7015
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007016template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007017StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7018 OMPParallelForSimdDirective *D) {
7019 DeclarationNameInfo DirName;
7020 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7021 nullptr, D->getLocStart());
7022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7024 return Res;
7025}
7026
7027template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007028StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7029 OMPParallelSectionsDirective *D) {
7030 DeclarationNameInfo DirName;
7031 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7032 nullptr, D->getLocStart());
7033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7034 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7035 return Res;
7036}
7037
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007038template <typename Derived>
7039StmtResult
7040TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7041 DeclarationNameInfo DirName;
7042 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7043 D->getLocStart());
7044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7046 return Res;
7047}
7048
Alexey Bataev68446b72014-07-18 07:47:19 +00007049template <typename Derived>
7050StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7051 OMPTaskyieldDirective *D) {
7052 DeclarationNameInfo DirName;
7053 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7054 D->getLocStart());
7055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7057 return Res;
7058}
7059
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007060template <typename Derived>
7061StmtResult
7062TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7063 DeclarationNameInfo DirName;
7064 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7065 D->getLocStart());
7066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7067 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7068 return Res;
7069}
7070
Alexey Bataev2df347a2014-07-18 10:17:07 +00007071template <typename Derived>
7072StmtResult
7073TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7074 DeclarationNameInfo DirName;
7075 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7076 D->getLocStart());
7077 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7078 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7079 return Res;
7080}
7081
Alexey Bataev6125da92014-07-21 11:26:11 +00007082template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007083StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7084 OMPTaskgroupDirective *D) {
7085 DeclarationNameInfo DirName;
7086 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7087 D->getLocStart());
7088 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7090 return Res;
7091}
7092
7093template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007094StmtResult
7095TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7096 DeclarationNameInfo DirName;
7097 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7098 D->getLocStart());
7099 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7100 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7101 return Res;
7102}
7103
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007104template <typename Derived>
7105StmtResult
7106TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7107 DeclarationNameInfo DirName;
7108 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7109 D->getLocStart());
7110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7111 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7112 return Res;
7113}
7114
Alexey Bataev0162e452014-07-22 10:10:35 +00007115template <typename Derived>
7116StmtResult
7117TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7118 DeclarationNameInfo DirName;
7119 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7120 D->getLocStart());
7121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7122 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7123 return Res;
7124}
7125
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007126template <typename Derived>
7127StmtResult
7128TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7129 DeclarationNameInfo DirName;
7130 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7131 D->getLocStart());
7132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7133 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7134 return Res;
7135}
7136
Alexey Bataev13314bf2014-10-09 04:18:56 +00007137template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007138StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7139 OMPTargetDataDirective *D) {
7140 DeclarationNameInfo DirName;
7141 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7142 D->getLocStart());
7143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7144 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7145 return Res;
7146}
7147
7148template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007149StmtResult
7150TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7151 DeclarationNameInfo DirName;
7152 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7153 D->getLocStart());
7154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7155 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7156 return Res;
7157}
7158
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007159template <typename Derived>
7160StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7161 OMPCancellationPointDirective *D) {
7162 DeclarationNameInfo DirName;
7163 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7164 nullptr, D->getLocStart());
7165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7167 return Res;
7168}
7169
Alexey Bataev80909872015-07-02 11:25:17 +00007170template <typename Derived>
7171StmtResult
7172TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7173 DeclarationNameInfo DirName;
7174 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7175 D->getLocStart());
7176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7177 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7178 return Res;
7179}
7180
Alexander Musman64d33f12014-06-04 07:53:32 +00007181//===----------------------------------------------------------------------===//
7182// OpenMP clause transformation
7183//===----------------------------------------------------------------------===//
7184template <typename Derived>
7185OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007186 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7187 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007188 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007189 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007190 C->getLParenLoc(), C->getLocEnd());
7191}
7192
Alexander Musman64d33f12014-06-04 07:53:32 +00007193template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007194OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7195 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7196 if (Cond.isInvalid())
7197 return nullptr;
7198 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7199 C->getLParenLoc(), C->getLocEnd());
7200}
7201
7202template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007203OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007204TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7205 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7206 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007207 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007208 return getDerived().RebuildOMPNumThreadsClause(
7209 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007210}
7211
Alexey Bataev62c87d22014-03-21 04:51:18 +00007212template <typename Derived>
7213OMPClause *
7214TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7215 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7216 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007217 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007218 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007219 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007220}
7221
Alexander Musman8bd31e62014-05-27 15:12:19 +00007222template <typename Derived>
7223OMPClause *
7224TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7225 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7226 if (E.isInvalid())
7227 return 0;
7228 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007229 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007230}
7231
Alexander Musman64d33f12014-06-04 07:53:32 +00007232template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007233OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007234TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007235 return getDerived().RebuildOMPDefaultClause(
7236 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7237 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007238}
7239
Alexander Musman64d33f12014-06-04 07:53:32 +00007240template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007241OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007242TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007243 return getDerived().RebuildOMPProcBindClause(
7244 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7245 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007246}
7247
Alexander Musman64d33f12014-06-04 07:53:32 +00007248template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007249OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007250TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7251 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7252 if (E.isInvalid())
7253 return nullptr;
7254 return getDerived().RebuildOMPScheduleClause(
7255 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7256 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7257}
7258
7259template <typename Derived>
7260OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007261TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007262 ExprResult E;
7263 if (auto *Num = C->getNumForLoops()) {
7264 E = getDerived().TransformExpr(Num);
7265 if (E.isInvalid())
7266 return nullptr;
7267 }
7268 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7269 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007270}
7271
7272template <typename Derived>
7273OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007274TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7275 // No need to rebuild this clause, no template-dependent parameters.
7276 return C;
7277}
7278
7279template <typename Derived>
7280OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007281TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7282 // No need to rebuild this clause, no template-dependent parameters.
7283 return C;
7284}
7285
7286template <typename Derived>
7287OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007288TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7289 // No need to rebuild this clause, no template-dependent parameters.
7290 return C;
7291}
7292
7293template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007294OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7295 // No need to rebuild this clause, no template-dependent parameters.
7296 return C;
7297}
7298
7299template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007300OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7301 // No need to rebuild this clause, no template-dependent parameters.
7302 return C;
7303}
7304
7305template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007306OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007307TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7308 // No need to rebuild this clause, no template-dependent parameters.
7309 return C;
7310}
7311
7312template <typename Derived>
7313OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007314TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7315 // No need to rebuild this clause, no template-dependent parameters.
7316 return C;
7317}
7318
7319template <typename Derived>
7320OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007321TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7322 // No need to rebuild this clause, no template-dependent parameters.
7323 return C;
7324}
7325
7326template <typename Derived>
7327OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007328TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007329 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007330 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007331 for (auto *VE : C->varlists()) {
7332 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007333 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007334 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007335 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007336 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007337 return getDerived().RebuildOMPPrivateClause(
7338 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007339}
7340
Alexander Musman64d33f12014-06-04 07:53:32 +00007341template <typename Derived>
7342OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7343 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007344 llvm::SmallVector<Expr *, 16> Vars;
7345 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007346 for (auto *VE : C->varlists()) {
7347 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007348 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007349 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007350 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007351 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007352 return getDerived().RebuildOMPFirstprivateClause(
7353 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007354}
7355
Alexander Musman64d33f12014-06-04 07:53:32 +00007356template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007357OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007358TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7359 llvm::SmallVector<Expr *, 16> Vars;
7360 Vars.reserve(C->varlist_size());
7361 for (auto *VE : C->varlists()) {
7362 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7363 if (EVar.isInvalid())
7364 return nullptr;
7365 Vars.push_back(EVar.get());
7366 }
7367 return getDerived().RebuildOMPLastprivateClause(
7368 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7369}
7370
7371template <typename Derived>
7372OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007373TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7374 llvm::SmallVector<Expr *, 16> Vars;
7375 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007376 for (auto *VE : C->varlists()) {
7377 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007378 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007379 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007380 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007381 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007382 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7383 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007384}
7385
Alexander Musman64d33f12014-06-04 07:53:32 +00007386template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007387OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007388TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7389 llvm::SmallVector<Expr *, 16> Vars;
7390 Vars.reserve(C->varlist_size());
7391 for (auto *VE : C->varlists()) {
7392 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7393 if (EVar.isInvalid())
7394 return nullptr;
7395 Vars.push_back(EVar.get());
7396 }
7397 CXXScopeSpec ReductionIdScopeSpec;
7398 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7399
7400 DeclarationNameInfo NameInfo = C->getNameInfo();
7401 if (NameInfo.getName()) {
7402 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7403 if (!NameInfo.getName())
7404 return nullptr;
7405 }
7406 return getDerived().RebuildOMPReductionClause(
7407 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7408 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7409}
7410
7411template <typename Derived>
7412OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007413TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7414 llvm::SmallVector<Expr *, 16> Vars;
7415 Vars.reserve(C->varlist_size());
7416 for (auto *VE : C->varlists()) {
7417 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7418 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007419 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007420 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007421 }
7422 ExprResult Step = getDerived().TransformExpr(C->getStep());
7423 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007424 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007425 return getDerived().RebuildOMPLinearClause(
7426 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7427 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007428}
7429
Alexander Musman64d33f12014-06-04 07:53:32 +00007430template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007431OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007432TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7433 llvm::SmallVector<Expr *, 16> Vars;
7434 Vars.reserve(C->varlist_size());
7435 for (auto *VE : C->varlists()) {
7436 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7437 if (EVar.isInvalid())
7438 return nullptr;
7439 Vars.push_back(EVar.get());
7440 }
7441 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7442 if (Alignment.isInvalid())
7443 return nullptr;
7444 return getDerived().RebuildOMPAlignedClause(
7445 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7446 C->getColonLoc(), C->getLocEnd());
7447}
7448
Alexander Musman64d33f12014-06-04 07:53:32 +00007449template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007450OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007451TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7452 llvm::SmallVector<Expr *, 16> Vars;
7453 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007454 for (auto *VE : C->varlists()) {
7455 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007456 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007457 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007458 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007459 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007460 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7461 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007462}
7463
Alexey Bataevbae9a792014-06-27 10:37:06 +00007464template <typename Derived>
7465OMPClause *
7466TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7467 llvm::SmallVector<Expr *, 16> Vars;
7468 Vars.reserve(C->varlist_size());
7469 for (auto *VE : C->varlists()) {
7470 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7471 if (EVar.isInvalid())
7472 return nullptr;
7473 Vars.push_back(EVar.get());
7474 }
7475 return getDerived().RebuildOMPCopyprivateClause(
7476 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7477}
7478
Alexey Bataev6125da92014-07-21 11:26:11 +00007479template <typename Derived>
7480OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7481 llvm::SmallVector<Expr *, 16> Vars;
7482 Vars.reserve(C->varlist_size());
7483 for (auto *VE : C->varlists()) {
7484 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7485 if (EVar.isInvalid())
7486 return nullptr;
7487 Vars.push_back(EVar.get());
7488 }
7489 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7490 C->getLParenLoc(), C->getLocEnd());
7491}
7492
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007493template <typename Derived>
7494OMPClause *
7495TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7496 llvm::SmallVector<Expr *, 16> Vars;
7497 Vars.reserve(C->varlist_size());
7498 for (auto *VE : C->varlists()) {
7499 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7500 if (EVar.isInvalid())
7501 return nullptr;
7502 Vars.push_back(EVar.get());
7503 }
7504 return getDerived().RebuildOMPDependClause(
7505 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7506 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7507}
7508
Michael Wonge710d542015-08-07 16:16:36 +00007509template <typename Derived>
7510OMPClause *
7511TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7512 ExprResult E = getDerived().TransformExpr(C->getDevice());
7513 if (E.isInvalid())
7514 return nullptr;
7515 return getDerived().RebuildOMPDeviceClause(
7516 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7517}
7518
Douglas Gregorebe10102009-08-20 07:17:43 +00007519//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007520// Expression transformation
7521//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007523ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007524TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007525 if (!E->isTypeDependent())
7526 return E;
7527
7528 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7529 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007530}
Mike Stump11289f42009-09-09 15:08:12 +00007531
7532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007534TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007535 NestedNameSpecifierLoc QualifierLoc;
7536 if (E->getQualifierLoc()) {
7537 QualifierLoc
7538 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7539 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007540 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007541 }
John McCallce546572009-12-08 09:08:17 +00007542
7543 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007544 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7545 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007547 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007548
John McCall815039a2010-08-17 21:27:17 +00007549 DeclarationNameInfo NameInfo = E->getNameInfo();
7550 if (NameInfo.getName()) {
7551 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7552 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007553 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007554 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007555
7556 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007557 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007558 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007559 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007560 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007561
7562 // Mark it referenced in the new context regardless.
7563 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007564 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007565
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007566 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007567 }
John McCallce546572009-12-08 09:08:17 +00007568
Craig Topperc3ec1492014-05-26 06:22:03 +00007569 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007570 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007571 TemplateArgs = &TransArgs;
7572 TransArgs.setLAngleLoc(E->getLAngleLoc());
7573 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007574 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7575 E->getNumTemplateArgs(),
7576 TransArgs))
7577 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007578 }
7579
Chad Rosier1dcde962012-08-08 18:46:20 +00007580 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007581 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007582}
Mike Stump11289f42009-09-09 15:08:12 +00007583
Douglas Gregora16548e2009-08-11 05:31:07 +00007584template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007585ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007586TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007587 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007588}
Mike Stump11289f42009-09-09 15:08:12 +00007589
Douglas Gregora16548e2009-08-11 05:31:07 +00007590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007592TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007593 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007594}
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregora16548e2009-08-11 05:31:07 +00007596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007598TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007599 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007600}
Mike Stump11289f42009-09-09 15:08:12 +00007601
Douglas Gregora16548e2009-08-11 05:31:07 +00007602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007603ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007604TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007605 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007606}
Mike Stump11289f42009-09-09 15:08:12 +00007607
Douglas Gregora16548e2009-08-11 05:31:07 +00007608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007609ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007610TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007611 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007612}
7613
7614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007615ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007616TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007617 if (FunctionDecl *FD = E->getDirectCallee())
7618 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007619 return SemaRef.MaybeBindToTemporary(E);
7620}
7621
7622template<typename Derived>
7623ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007624TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7625 ExprResult ControllingExpr =
7626 getDerived().TransformExpr(E->getControllingExpr());
7627 if (ControllingExpr.isInvalid())
7628 return ExprError();
7629
Chris Lattner01cf8db2011-07-20 06:58:45 +00007630 SmallVector<Expr *, 4> AssocExprs;
7631 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007632 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7633 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7634 if (TS) {
7635 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7636 if (!AssocType)
7637 return ExprError();
7638 AssocTypes.push_back(AssocType);
7639 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007640 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007641 }
7642
7643 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7644 if (AssocExpr.isInvalid())
7645 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007646 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007647 }
7648
7649 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7650 E->getDefaultLoc(),
7651 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007652 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007653 AssocTypes,
7654 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007655}
7656
7657template<typename Derived>
7658ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007659TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007660 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007663
Douglas Gregora16548e2009-08-11 05:31:07 +00007664 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007665 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007666
John McCallb268a282010-08-23 23:25:46 +00007667 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007668 E->getRParen());
7669}
7670
Richard Smithdb2630f2012-10-21 03:28:35 +00007671/// \brief The operand of a unary address-of operator has special rules: it's
7672/// allowed to refer to a non-static member of a class even if there's no 'this'
7673/// object available.
7674template<typename Derived>
7675ExprResult
7676TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7677 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007678 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007679 else
7680 return getDerived().TransformExpr(E);
7681}
7682
Mike Stump11289f42009-09-09 15:08:12 +00007683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007685TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007686 ExprResult SubExpr;
7687 if (E->getOpcode() == UO_AddrOf)
7688 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7689 else
7690 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007691 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007693
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007695 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007696
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7698 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007699 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007700}
Mike Stump11289f42009-09-09 15:08:12 +00007701
Douglas Gregora16548e2009-08-11 05:31:07 +00007702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007703ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007704TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7705 // Transform the type.
7706 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7707 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007708 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007709
Douglas Gregor882211c2010-04-28 22:16:22 +00007710 // Transform all of the components into components similar to what the
7711 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007712 // FIXME: It would be slightly more efficient in the non-dependent case to
7713 // just map FieldDecls, rather than requiring the rebuilder to look for
7714 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007715 // template code that we don't care.
7716 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007717 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007718 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007719 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007720 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7721 const Node &ON = E->getComponent(I);
7722 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007723 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007724 Comp.LocStart = ON.getSourceRange().getBegin();
7725 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007726 switch (ON.getKind()) {
7727 case Node::Array: {
7728 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007729 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007730 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007731 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007732
Douglas Gregor882211c2010-04-28 22:16:22 +00007733 ExprChanged = ExprChanged || Index.get() != FromIndex;
7734 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007735 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007736 break;
7737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007738
Douglas Gregor882211c2010-04-28 22:16:22 +00007739 case Node::Field:
7740 case Node::Identifier:
7741 Comp.isBrackets = false;
7742 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007743 if (!Comp.U.IdentInfo)
7744 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007745
Douglas Gregor882211c2010-04-28 22:16:22 +00007746 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007747
Douglas Gregord1702062010-04-29 00:18:15 +00007748 case Node::Base:
7749 // Will be recomputed during the rebuild.
7750 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007752
Douglas Gregor882211c2010-04-28 22:16:22 +00007753 Components.push_back(Comp);
7754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007755
Douglas Gregor882211c2010-04-28 22:16:22 +00007756 // If nothing changed, retain the existing expression.
7757 if (!getDerived().AlwaysRebuild() &&
7758 Type == E->getTypeSourceInfo() &&
7759 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007760 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007761
Douglas Gregor882211c2010-04-28 22:16:22 +00007762 // Build a new offsetof expression.
7763 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7764 Components.data(), Components.size(),
7765 E->getRParenLoc());
7766}
7767
7768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007769ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007770TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7771 assert(getDerived().AlreadyTransformed(E->getType()) &&
7772 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007773 return E;
John McCall8d69a212010-11-15 23:31:06 +00007774}
7775
7776template<typename Derived>
7777ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007778TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7779 return E;
7780}
7781
7782template<typename Derived>
7783ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007784TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007785 // Rebuild the syntactic form. The original syntactic form has
7786 // opaque-value expressions in it, so strip those away and rebuild
7787 // the result. This is a really awful way of doing this, but the
7788 // better solution (rebuilding the semantic expressions and
7789 // rebinding OVEs as necessary) doesn't work; we'd need
7790 // TreeTransform to not strip away implicit conversions.
7791 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7792 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007793 if (result.isInvalid()) return ExprError();
7794
7795 // If that gives us a pseudo-object result back, the pseudo-object
7796 // expression must have been an lvalue-to-rvalue conversion which we
7797 // should reapply.
7798 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007799 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007800
7801 return result;
7802}
7803
7804template<typename Derived>
7805ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007806TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7807 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007808 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007809 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007810
John McCallbcd03502009-12-07 02:54:59 +00007811 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007812 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007814
John McCall4c98fd82009-11-04 07:28:41 +00007815 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007816 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007817
Peter Collingbournee190dee2011-03-11 19:24:49 +00007818 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7819 E->getKind(),
7820 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007821 }
Mike Stump11289f42009-09-09 15:08:12 +00007822
Eli Friedmane4f22df2012-02-29 04:03:55 +00007823 // C++0x [expr.sizeof]p1:
7824 // The operand is either an expression, which is an unevaluated operand
7825 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007826 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7827 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007828
Reid Kleckner32506ed2014-06-12 23:03:48 +00007829 // Try to recover if we have something like sizeof(T::X) where X is a type.
7830 // Notably, there must be *exactly* one set of parens if X is a type.
7831 TypeSourceInfo *RecoveryTSI = nullptr;
7832 ExprResult SubExpr;
7833 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7834 if (auto *DRE =
7835 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7836 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7837 PE, DRE, false, &RecoveryTSI);
7838 else
7839 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7840
7841 if (RecoveryTSI) {
7842 return getDerived().RebuildUnaryExprOrTypeTrait(
7843 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7844 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007845 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007846
Eli Friedmane4f22df2012-02-29 04:03:55 +00007847 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007848 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007849
Peter Collingbournee190dee2011-03-11 19:24:49 +00007850 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7851 E->getOperatorLoc(),
7852 E->getKind(),
7853 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007854}
Mike Stump11289f42009-09-09 15:08:12 +00007855
Douglas Gregora16548e2009-08-11 05:31:07 +00007856template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007857ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007858TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007859 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007860 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007861 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007862
John McCalldadc5752010-08-24 06:29:42 +00007863 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007864 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007866
7867
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 if (!getDerived().AlwaysRebuild() &&
7869 LHS.get() == E->getLHS() &&
7870 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007871 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007872
John McCallb268a282010-08-23 23:25:46 +00007873 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007875 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 E->getRBracketLoc());
7877}
Mike Stump11289f42009-09-09 15:08:12 +00007878
7879template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007880ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007881TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007882 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007883 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007884 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007885 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007886
7887 // Transform arguments.
7888 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007889 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007890 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007891 &ArgChanged))
7892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007893
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 if (!getDerived().AlwaysRebuild() &&
7895 Callee.get() == E->getCallee() &&
7896 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007897 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007898
Douglas Gregora16548e2009-08-11 05:31:07 +00007899 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007900 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007902 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007903 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007904 E->getRParenLoc());
7905}
Mike Stump11289f42009-09-09 15:08:12 +00007906
7907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007909TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007910 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007911 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007913
Douglas Gregorea972d32011-02-28 21:54:11 +00007914 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007915 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007916 QualifierLoc
7917 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007918
Douglas Gregorea972d32011-02-28 21:54:11 +00007919 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007920 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007921 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007922 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007923
Eli Friedman2cfcef62009-12-04 06:40:45 +00007924 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007925 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7926 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007929
John McCall16df1e52010-03-30 21:47:33 +00007930 NamedDecl *FoundDecl = E->getFoundDecl();
7931 if (FoundDecl == E->getMemberDecl()) {
7932 FoundDecl = Member;
7933 } else {
7934 FoundDecl = cast_or_null<NamedDecl>(
7935 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7936 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00007937 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00007938 }
7939
Douglas Gregora16548e2009-08-11 05:31:07 +00007940 if (!getDerived().AlwaysRebuild() &&
7941 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007942 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007943 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00007944 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00007945 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007946
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007947 // Mark it referenced in the new context regardless.
7948 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007949 SemaRef.MarkMemberReferenced(E);
7950
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007951 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00007952 }
Douglas Gregora16548e2009-08-11 05:31:07 +00007953
John McCall6b51f282009-11-23 01:53:49 +00007954 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00007955 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00007956 TransArgs.setLAngleLoc(E->getLAngleLoc());
7957 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007958 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7959 E->getNumTemplateArgs(),
7960 TransArgs))
7961 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007963
Douglas Gregora16548e2009-08-11 05:31:07 +00007964 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00007965 SourceLocation FakeOperatorLoc =
7966 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00007967
John McCall38836f02010-01-15 08:34:02 +00007968 // FIXME: to do this check properly, we will need to preserve the
7969 // first-qualifier-in-scope here, just in case we had a dependent
7970 // base (and therefore couldn't do the check) and a
7971 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00007972 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00007973
John McCallb268a282010-08-23 23:25:46 +00007974 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00007975 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00007976 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00007977 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007978 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00007979 Member,
John McCall16df1e52010-03-30 21:47:33 +00007980 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00007981 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00007982 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00007983 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00007984}
Mike Stump11289f42009-09-09 15:08:12 +00007985
Douglas Gregora16548e2009-08-11 05:31:07 +00007986template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007988TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00007989 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007992
John McCalldadc5752010-08-24 06:29:42 +00007993 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007996
Douglas Gregora16548e2009-08-11 05:31:07 +00007997 if (!getDerived().AlwaysRebuild() &&
7998 LHS.get() == E->getLHS() &&
7999 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008000 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008001
Lang Hames5de91cc2012-10-02 04:45:10 +00008002 Sema::FPContractStateRAII FPContractState(getSema());
8003 getSema().FPFeatures.fp_contract = E->isFPContractable();
8004
Douglas Gregora16548e2009-08-11 05:31:07 +00008005 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008006 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008007}
8008
Mike Stump11289f42009-09-09 15:08:12 +00008009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008010ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008011TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008012 CompoundAssignOperator *E) {
8013 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008014}
Mike Stump11289f42009-09-09 15:08:12 +00008015
Douglas Gregora16548e2009-08-11 05:31:07 +00008016template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008017ExprResult TreeTransform<Derived>::
8018TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8019 // Just rebuild the common and RHS expressions and see whether we
8020 // get any changes.
8021
8022 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8023 if (commonExpr.isInvalid())
8024 return ExprError();
8025
8026 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8027 if (rhs.isInvalid())
8028 return ExprError();
8029
8030 if (!getDerived().AlwaysRebuild() &&
8031 commonExpr.get() == e->getCommon() &&
8032 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008033 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008034
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008035 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008036 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008037 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008038 e->getColonLoc(),
8039 rhs.get());
8040}
8041
8042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008044TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008045 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008046 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008047 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008048
John McCalldadc5752010-08-24 06:29:42 +00008049 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008050 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008052
John McCalldadc5752010-08-24 06:29:42 +00008053 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008054 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008055 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008056
Douglas Gregora16548e2009-08-11 05:31:07 +00008057 if (!getDerived().AlwaysRebuild() &&
8058 Cond.get() == E->getCond() &&
8059 LHS.get() == E->getLHS() &&
8060 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008061 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008062
John McCallb268a282010-08-23 23:25:46 +00008063 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008064 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008065 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008066 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008067 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008068}
Mike Stump11289f42009-09-09 15:08:12 +00008069
8070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008072TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008073 // Implicit casts are eliminated during transformation, since they
8074 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008075 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008076}
Mike Stump11289f42009-09-09 15:08:12 +00008077
Douglas Gregora16548e2009-08-11 05:31:07 +00008078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008080TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008081 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8082 if (!Type)
8083 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008084
John McCalldadc5752010-08-24 06:29:42 +00008085 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008086 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008087 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008088 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008089
Douglas Gregora16548e2009-08-11 05:31:07 +00008090 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008091 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008092 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008093 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008094
John McCall97513962010-01-15 18:39:57 +00008095 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008096 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008097 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008098 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008099}
Mike Stump11289f42009-09-09 15:08:12 +00008100
Douglas Gregora16548e2009-08-11 05:31:07 +00008101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008103TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008104 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8105 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8106 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008108
John McCalldadc5752010-08-24 06:29:42 +00008109 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008110 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008112
Douglas Gregora16548e2009-08-11 05:31:07 +00008113 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008114 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008115 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008116 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008117
John McCall5d7aa7f2010-01-19 22:33:45 +00008118 // Note: the expression type doesn't necessarily match the
8119 // type-as-written, but that's okay, because it should always be
8120 // derivable from the initializer.
8121
John McCalle15bbff2010-01-18 19:35:47 +00008122 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008123 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008124 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008125}
Mike Stump11289f42009-09-09 15:08:12 +00008126
Douglas Gregora16548e2009-08-11 05:31:07 +00008127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008129TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008130 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008133
Douglas Gregora16548e2009-08-11 05:31:07 +00008134 if (!getDerived().AlwaysRebuild() &&
8135 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008136 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008137
Douglas Gregora16548e2009-08-11 05:31:07 +00008138 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008139 SourceLocation FakeOperatorLoc =
8140 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008141 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 E->getAccessorLoc(),
8143 E->getAccessor());
8144}
Mike Stump11289f42009-09-09 15:08:12 +00008145
Douglas Gregora16548e2009-08-11 05:31:07 +00008146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008148TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008149 if (InitListExpr *Syntactic = E->getSyntacticForm())
8150 E = Syntactic;
8151
Douglas Gregora16548e2009-08-11 05:31:07 +00008152 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008153
Benjamin Kramerf0623432012-08-23 22:51:59 +00008154 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008155 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008156 Inits, &InitChanged))
8157 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008158
Richard Smith520449d2015-02-05 06:15:50 +00008159 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8160 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8161 // in some cases. We can't reuse it in general, because the syntactic and
8162 // semantic forms are linked, and we can't know that semantic form will
8163 // match even if the syntactic form does.
8164 }
Mike Stump11289f42009-09-09 15:08:12 +00008165
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008166 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008167 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008168}
Mike Stump11289f42009-09-09 15:08:12 +00008169
Douglas Gregora16548e2009-08-11 05:31:07 +00008170template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008171ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008172TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008174
Douglas Gregorebe10102009-08-20 07:17:43 +00008175 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008176 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008178 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008179
Douglas Gregorebe10102009-08-20 07:17:43 +00008180 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008181 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008182 bool ExprChanged = false;
8183 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8184 DEnd = E->designators_end();
8185 D != DEnd; ++D) {
8186 if (D->isFieldDesignator()) {
8187 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8188 D->getDotLoc(),
8189 D->getFieldLoc()));
8190 continue;
8191 }
Mike Stump11289f42009-09-09 15:08:12 +00008192
Douglas Gregora16548e2009-08-11 05:31:07 +00008193 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008194 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008197
8198 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008199 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008200
Douglas Gregora16548e2009-08-11 05:31:07 +00008201 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008202 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008203 continue;
8204 }
Mike Stump11289f42009-09-09 15:08:12 +00008205
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008207 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008208 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8209 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008211
John McCalldadc5752010-08-24 06:29:42 +00008212 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008213 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008214 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008215
8216 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008217 End.get(),
8218 D->getLBracketLoc(),
8219 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008220
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8222 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008223
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008224 ArrayExprs.push_back(Start.get());
8225 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008226 }
Mike Stump11289f42009-09-09 15:08:12 +00008227
Douglas Gregora16548e2009-08-11 05:31:07 +00008228 if (!getDerived().AlwaysRebuild() &&
8229 Init.get() == E->getInit() &&
8230 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008231 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008232
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008233 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008234 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008235 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008236}
Mike Stump11289f42009-09-09 15:08:12 +00008237
Yunzhong Gaocb779302015-06-10 00:27:52 +00008238// Seems that if TransformInitListExpr() only works on the syntactic form of an
8239// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8240template<typename Derived>
8241ExprResult
8242TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8243 DesignatedInitUpdateExpr *E) {
8244 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8245 "initializer");
8246 return ExprError();
8247}
8248
8249template<typename Derived>
8250ExprResult
8251TreeTransform<Derived>::TransformNoInitExpr(
8252 NoInitExpr *E) {
8253 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8254 return ExprError();
8255}
8256
Douglas Gregora16548e2009-08-11 05:31:07 +00008257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008258ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008259TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008260 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008261 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008262
Douglas Gregor3da3c062009-10-28 00:29:27 +00008263 // FIXME: Will we ever have proper type location here? Will we actually
8264 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 QualType T = getDerived().TransformType(E->getType());
8266 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008268
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 if (!getDerived().AlwaysRebuild() &&
8270 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008271 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008272
Douglas Gregora16548e2009-08-11 05:31:07 +00008273 return getDerived().RebuildImplicitValueInitExpr(T);
8274}
Mike Stump11289f42009-09-09 15:08:12 +00008275
Douglas Gregora16548e2009-08-11 05:31:07 +00008276template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008277ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008278TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008279 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8280 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008282
John McCalldadc5752010-08-24 06:29:42 +00008283 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008285 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008286
Douglas Gregora16548e2009-08-11 05:31:07 +00008287 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008288 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008289 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008290 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008291
John McCallb268a282010-08-23 23:25:46 +00008292 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008293 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008294}
8295
8296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008297ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008298TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008299 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008300 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008301 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8302 &ArgumentChanged))
8303 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008306 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008307 E->getRParenLoc());
8308}
Mike Stump11289f42009-09-09 15:08:12 +00008309
Douglas Gregora16548e2009-08-11 05:31:07 +00008310/// \brief Transform an address-of-label expression.
8311///
8312/// By default, the transformation of an address-of-label expression always
8313/// rebuilds the expression, so that the label identifier can be resolved to
8314/// the corresponding label statement by semantic analysis.
8315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008317TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008318 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8319 E->getLabel());
8320 if (!LD)
8321 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008322
Douglas Gregora16548e2009-08-11 05:31:07 +00008323 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008324 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008325}
Mike Stump11289f42009-09-09 15:08:12 +00008326
8327template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008329TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008330 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008331 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008332 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008333 if (SubStmt.isInvalid()) {
8334 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008335 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008336 }
Mike Stump11289f42009-09-09 15:08:12 +00008337
Douglas Gregora16548e2009-08-11 05:31:07 +00008338 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008339 SubStmt.get() == E->getSubStmt()) {
8340 // Calling this an 'error' is unintuitive, but it does the right thing.
8341 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008342 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008343 }
Mike Stump11289f42009-09-09 15:08:12 +00008344
8345 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008346 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008347 E->getRParenLoc());
8348}
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregora16548e2009-08-11 05:31:07 +00008350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008352TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008353 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008356
John McCalldadc5752010-08-24 06:29:42 +00008357 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008360
John McCalldadc5752010-08-24 06:29:42 +00008361 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008364
Douglas Gregora16548e2009-08-11 05:31:07 +00008365 if (!getDerived().AlwaysRebuild() &&
8366 Cond.get() == E->getCond() &&
8367 LHS.get() == E->getLHS() &&
8368 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008369 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008370
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008372 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008373 E->getRParenLoc());
8374}
Mike Stump11289f42009-09-09 15:08:12 +00008375
Douglas Gregora16548e2009-08-11 05:31:07 +00008376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008378TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008379 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008380}
8381
8382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008384TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008385 switch (E->getOperator()) {
8386 case OO_New:
8387 case OO_Delete:
8388 case OO_Array_New:
8389 case OO_Array_Delete:
8390 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008391
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008392 case OO_Call: {
8393 // This is a call to an object's operator().
8394 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8395
8396 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008397 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008398 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008399 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008400
8401 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008402 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8403 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008404
8405 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008406 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008407 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008408 Args))
8409 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008410
John McCallb268a282010-08-23 23:25:46 +00008411 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008412 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008413 E->getLocEnd());
8414 }
8415
8416#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8417 case OO_##Name:
8418#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8419#include "clang/Basic/OperatorKinds.def"
8420 case OO_Subscript:
8421 // Handled below.
8422 break;
8423
8424 case OO_Conditional:
8425 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008426
8427 case OO_None:
8428 case NUM_OVERLOADED_OPERATORS:
8429 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008430 }
8431
John McCalldadc5752010-08-24 06:29:42 +00008432 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008433 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008435
Richard Smithdb2630f2012-10-21 03:28:35 +00008436 ExprResult First;
8437 if (E->getOperator() == OO_Amp)
8438 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8439 else
8440 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008442 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008443
John McCalldadc5752010-08-24 06:29:42 +00008444 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008445 if (E->getNumArgs() == 2) {
8446 Second = getDerived().TransformExpr(E->getArg(1));
8447 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008448 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008449 }
Mike Stump11289f42009-09-09 15:08:12 +00008450
Douglas Gregora16548e2009-08-11 05:31:07 +00008451 if (!getDerived().AlwaysRebuild() &&
8452 Callee.get() == E->getCallee() &&
8453 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008454 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008455 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008456
Lang Hames5de91cc2012-10-02 04:45:10 +00008457 Sema::FPContractStateRAII FPContractState(getSema());
8458 getSema().FPFeatures.fp_contract = E->isFPContractable();
8459
Douglas Gregora16548e2009-08-11 05:31:07 +00008460 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8461 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008462 Callee.get(),
8463 First.get(),
8464 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008465}
Mike Stump11289f42009-09-09 15:08:12 +00008466
Douglas Gregora16548e2009-08-11 05:31:07 +00008467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008469TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8470 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008471}
Mike Stump11289f42009-09-09 15:08:12 +00008472
Douglas Gregora16548e2009-08-11 05:31:07 +00008473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008474ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008475TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8476 // Transform the callee.
8477 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8478 if (Callee.isInvalid())
8479 return ExprError();
8480
8481 // Transform exec config.
8482 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8483 if (EC.isInvalid())
8484 return ExprError();
8485
8486 // Transform arguments.
8487 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008488 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008489 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008490 &ArgChanged))
8491 return ExprError();
8492
8493 if (!getDerived().AlwaysRebuild() &&
8494 Callee.get() == E->getCallee() &&
8495 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008496 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008497
8498 // FIXME: Wrong source location information for the '('.
8499 SourceLocation FakeLParenLoc
8500 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8501 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008502 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008503 E->getRParenLoc(), EC.get());
8504}
8505
8506template<typename Derived>
8507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008508TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008509 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8510 if (!Type)
8511 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008512
John McCalldadc5752010-08-24 06:29:42 +00008513 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008514 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008515 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008516 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008517
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008519 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008520 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008521 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008522 return getDerived().RebuildCXXNamedCastExpr(
8523 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8524 Type, E->getAngleBrackets().getEnd(),
8525 // FIXME. this should be '(' location
8526 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008527}
Mike Stump11289f42009-09-09 15:08:12 +00008528
Douglas Gregora16548e2009-08-11 05:31:07 +00008529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008530ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008531TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8532 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008533}
Mike Stump11289f42009-09-09 15:08:12 +00008534
8535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008537TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8538 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008539}
8540
Douglas Gregora16548e2009-08-11 05:31:07 +00008541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008542ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008543TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008544 CXXReinterpretCastExpr *E) {
8545 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008546}
Mike Stump11289f42009-09-09 15:08:12 +00008547
Douglas Gregora16548e2009-08-11 05:31:07 +00008548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008549ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008550TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8551 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008552}
Mike Stump11289f42009-09-09 15:08:12 +00008553
Douglas Gregora16548e2009-08-11 05:31:07 +00008554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008555ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008556TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008557 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008558 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8559 if (!Type)
8560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008561
John McCalldadc5752010-08-24 06:29:42 +00008562 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008563 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008564 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008566
Douglas Gregora16548e2009-08-11 05:31:07 +00008567 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008568 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008569 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008570 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008571
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008572 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008573 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008574 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008575 E->getRParenLoc());
8576}
Mike Stump11289f42009-09-09 15:08:12 +00008577
Douglas Gregora16548e2009-08-11 05:31:07 +00008578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008579ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008580TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008581 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008582 TypeSourceInfo *TInfo
8583 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8584 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008586
Douglas Gregora16548e2009-08-11 05:31:07 +00008587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008588 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008589 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008590
Douglas Gregor9da64192010-04-26 22:37:10 +00008591 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8592 E->getLocStart(),
8593 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008594 E->getLocEnd());
8595 }
Mike Stump11289f42009-09-09 15:08:12 +00008596
Eli Friedman456f0182012-01-20 01:26:23 +00008597 // We don't know whether the subexpression is potentially evaluated until
8598 // after we perform semantic analysis. We speculatively assume it is
8599 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008600 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008601 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8602 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008603
John McCalldadc5752010-08-24 06:29:42 +00008604 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008607
Douglas Gregora16548e2009-08-11 05:31:07 +00008608 if (!getDerived().AlwaysRebuild() &&
8609 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008610 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008611
Douglas Gregor9da64192010-04-26 22:37:10 +00008612 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8613 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008614 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008615 E->getLocEnd());
8616}
8617
8618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008619ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008620TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8621 if (E->isTypeOperand()) {
8622 TypeSourceInfo *TInfo
8623 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8624 if (!TInfo)
8625 return ExprError();
8626
8627 if (!getDerived().AlwaysRebuild() &&
8628 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008629 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008630
Douglas Gregor69735112011-03-06 17:40:41 +00008631 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008632 E->getLocStart(),
8633 TInfo,
8634 E->getLocEnd());
8635 }
8636
Francois Pichet9f4f2072010-09-08 12:20:18 +00008637 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8638
8639 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8640 if (SubExpr.isInvalid())
8641 return ExprError();
8642
8643 if (!getDerived().AlwaysRebuild() &&
8644 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008645 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008646
8647 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8648 E->getLocStart(),
8649 SubExpr.get(),
8650 E->getLocEnd());
8651}
8652
8653template<typename Derived>
8654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008655TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008656 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008657}
Mike Stump11289f42009-09-09 15:08:12 +00008658
Douglas Gregora16548e2009-08-11 05:31:07 +00008659template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008660ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008661TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008662 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008663 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008664}
Mike Stump11289f42009-09-09 15:08:12 +00008665
Douglas Gregora16548e2009-08-11 05:31:07 +00008666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008667ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008668TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008669 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008670
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008671 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8672 // Make sure that we capture 'this'.
8673 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008674 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008676
Douglas Gregorb15af892010-01-07 23:12:05 +00008677 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008678}
Mike Stump11289f42009-09-09 15:08:12 +00008679
Douglas Gregora16548e2009-08-11 05:31:07 +00008680template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008681ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008682TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008683 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008684 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008686
Douglas Gregora16548e2009-08-11 05:31:07 +00008687 if (!getDerived().AlwaysRebuild() &&
8688 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008689 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008690
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008691 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8692 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008693}
Mike Stump11289f42009-09-09 15:08:12 +00008694
Douglas Gregora16548e2009-08-11 05:31:07 +00008695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008696ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008697TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008698 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008699 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8700 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008701 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008702 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008703
Chandler Carruth794da4c2010-02-08 06:42:49 +00008704 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008705 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008706 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008707
Douglas Gregor033f6752009-12-23 23:03:06 +00008708 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008709}
Mike Stump11289f42009-09-09 15:08:12 +00008710
Douglas Gregora16548e2009-08-11 05:31:07 +00008711template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008712ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008713TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8714 FieldDecl *Field
8715 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8716 E->getField()));
8717 if (!Field)
8718 return ExprError();
8719
8720 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008721 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008722
8723 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8724}
8725
8726template<typename Derived>
8727ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008728TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8729 CXXScalarValueInitExpr *E) {
8730 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8731 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008732 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008733
Douglas Gregora16548e2009-08-11 05:31:07 +00008734 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008735 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008736 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008737
Chad Rosier1dcde962012-08-08 18:46:20 +00008738 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008739 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008740 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008741}
Mike Stump11289f42009-09-09 15:08:12 +00008742
Douglas Gregora16548e2009-08-11 05:31:07 +00008743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008745TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008746 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008747 TypeSourceInfo *AllocTypeInfo
8748 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8749 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008751
Douglas Gregora16548e2009-08-11 05:31:07 +00008752 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008753 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008754 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008755 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008756
Douglas Gregora16548e2009-08-11 05:31:07 +00008757 // Transform the placement arguments (if any).
8758 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008759 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008760 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008761 E->getNumPlacementArgs(), true,
8762 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008763 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008764
Sebastian Redl6047f072012-02-16 12:22:20 +00008765 // Transform the initializer (if any).
8766 Expr *OldInit = E->getInitializer();
8767 ExprResult NewInit;
8768 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008769 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008770 if (NewInit.isInvalid())
8771 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008772
Sebastian Redl6047f072012-02-16 12:22:20 +00008773 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008774 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008775 if (E->getOperatorNew()) {
8776 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008777 getDerived().TransformDecl(E->getLocStart(),
8778 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008779 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008780 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008781 }
8782
Craig Topperc3ec1492014-05-26 06:22:03 +00008783 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008784 if (E->getOperatorDelete()) {
8785 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008786 getDerived().TransformDecl(E->getLocStart(),
8787 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008788 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008789 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008790 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008791
Douglas Gregora16548e2009-08-11 05:31:07 +00008792 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008793 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008794 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008795 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008796 OperatorNew == E->getOperatorNew() &&
8797 OperatorDelete == E->getOperatorDelete() &&
8798 !ArgumentChanged) {
8799 // Mark any declarations we need as referenced.
8800 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008801 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008802 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008803 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008804 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008805
Sebastian Redl6047f072012-02-16 12:22:20 +00008806 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008807 QualType ElementType
8808 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8809 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8810 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8811 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008812 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008813 }
8814 }
8815 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008816
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008817 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008818 }
Mike Stump11289f42009-09-09 15:08:12 +00008819
Douglas Gregor0744ef62010-09-07 21:49:58 +00008820 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008821 if (!ArraySize.get()) {
8822 // If no array size was specified, but the new expression was
8823 // instantiated with an array type (e.g., "new T" where T is
8824 // instantiated with "int[4]"), extract the outer bound from the
8825 // array type as our array size. We do this with constant and
8826 // dependently-sized array types.
8827 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8828 if (!ArrayT) {
8829 // Do nothing
8830 } else if (const ConstantArrayType *ConsArrayT
8831 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008832 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8833 SemaRef.Context.getSizeType(),
8834 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008835 AllocType = ConsArrayT->getElementType();
8836 } else if (const DependentSizedArrayType *DepArrayT
8837 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8838 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008839 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008840 AllocType = DepArrayT->getElementType();
8841 }
8842 }
8843 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008844
Douglas Gregora16548e2009-08-11 05:31:07 +00008845 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8846 E->isGlobalNew(),
8847 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008848 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008849 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008850 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008851 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008852 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008853 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008854 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008855 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008856}
Mike Stump11289f42009-09-09 15:08:12 +00008857
Douglas Gregora16548e2009-08-11 05:31:07 +00008858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008860TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008861 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008862 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008864
Douglas Gregord2d9da02010-02-26 00:38:10 +00008865 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008866 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008867 if (E->getOperatorDelete()) {
8868 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008869 getDerived().TransformDecl(E->getLocStart(),
8870 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008871 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008874
Douglas Gregora16548e2009-08-11 05:31:07 +00008875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008876 Operand.get() == E->getArgument() &&
8877 OperatorDelete == E->getOperatorDelete()) {
8878 // Mark any declarations we need as referenced.
8879 // FIXME: instantiation-specific.
8880 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008881 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008882
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008883 if (!E->getArgument()->isTypeDependent()) {
8884 QualType Destroyed = SemaRef.Context.getBaseElementType(
8885 E->getDestroyedType());
8886 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8887 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008888 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008889 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008890 }
8891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008892
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008893 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008894 }
Mike Stump11289f42009-09-09 15:08:12 +00008895
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8897 E->isGlobalDelete(),
8898 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008899 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008900}
Mike Stump11289f42009-09-09 15:08:12 +00008901
Douglas Gregora16548e2009-08-11 05:31:07 +00008902template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008903ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008904TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008905 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008906 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008907 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008908 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008909
John McCallba7bf592010-08-24 05:47:05 +00008910 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008911 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008912 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008913 E->getOperatorLoc(),
8914 E->isArrow()? tok::arrow : tok::period,
8915 ObjectTypePtr,
8916 MayBePseudoDestructor);
8917 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008918 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008919
John McCallba7bf592010-08-24 05:47:05 +00008920 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008921 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8922 if (QualifierLoc) {
8923 QualifierLoc
8924 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8925 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008926 return ExprError();
8927 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008928 CXXScopeSpec SS;
8929 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregor678f90d2010-02-25 01:56:36 +00008931 PseudoDestructorTypeStorage Destroyed;
8932 if (E->getDestroyedTypeInfo()) {
8933 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008934 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008935 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008936 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008937 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00008938 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00008939 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00008940 // We aren't likely to be able to resolve the identifier down to a type
8941 // now anyway, so just retain the identifier.
8942 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
8943 E->getDestroyedTypeLoc());
8944 } else {
8945 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00008946 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008947 *E->getDestroyedTypeIdentifier(),
8948 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008949 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008950 SS, ObjectTypePtr,
8951 false);
8952 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008953 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008954
Douglas Gregor678f90d2010-02-25 01:56:36 +00008955 Destroyed
8956 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
8957 E->getDestroyedTypeLoc());
8958 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008959
Craig Topperc3ec1492014-05-26 06:22:03 +00008960 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008961 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00008962 CXXScopeSpec EmptySS;
8963 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00008964 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008965 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008966 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00008967 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008968
John McCallb268a282010-08-23 23:25:46 +00008969 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00008970 E->getOperatorLoc(),
8971 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00008972 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008973 ScopeTypeInfo,
8974 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008975 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008976 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00008977}
Mike Stump11289f42009-09-09 15:08:12 +00008978
Douglas Gregorad8a3362009-09-04 17:36:40 +00008979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008980ExprResult
John McCalld14a8642009-11-21 08:51:07 +00008981TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008982 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00008983 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
8984 Sema::LookupOrdinaryName);
8985
8986 // Transform all the decls.
8987 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
8988 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008989 NamedDecl *InstD = static_cast<NamedDecl*>(
8990 getDerived().TransformDecl(Old->getNameLoc(),
8991 *I));
John McCall84d87672009-12-10 09:41:52 +00008992 if (!InstD) {
8993 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8994 // This can happen because of dependent hiding.
8995 if (isa<UsingShadowDecl>(*I))
8996 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00008997 else {
8998 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00008999 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009000 }
John McCall84d87672009-12-10 09:41:52 +00009001 }
John McCalle66edc12009-11-24 19:00:30 +00009002
9003 // Expand using declarations.
9004 if (isa<UsingDecl>(InstD)) {
9005 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009006 for (auto *I : UD->shadows())
9007 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009008 continue;
9009 }
9010
9011 R.addDecl(InstD);
9012 }
9013
9014 // Resolve a kind, but don't do any further analysis. If it's
9015 // ambiguous, the callee needs to deal with it.
9016 R.resolveKind();
9017
9018 // Rebuild the nested-name qualifier, if present.
9019 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009020 if (Old->getQualifierLoc()) {
9021 NestedNameSpecifierLoc QualifierLoc
9022 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9023 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009024 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009025
Douglas Gregor0da1d432011-02-28 20:01:57 +00009026 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009027 }
9028
Douglas Gregor9262f472010-04-27 18:19:34 +00009029 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009030 CXXRecordDecl *NamingClass
9031 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9032 Old->getNameLoc(),
9033 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009034 if (!NamingClass) {
9035 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009036 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009038
Douglas Gregorda7be082010-04-27 16:10:10 +00009039 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009040 }
9041
Abramo Bagnara7945c982012-01-27 09:46:47 +00009042 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9043
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009044 // If we have neither explicit template arguments, nor the template keyword,
9045 // it's a normal declaration name.
9046 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009047 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9048
9049 // If we have template arguments, rebuild them, then rebuild the
9050 // templateid expression.
9051 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009052 if (Old->hasExplicitTemplateArgs() &&
9053 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009054 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009055 TransArgs)) {
9056 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009057 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009058 }
John McCalle66edc12009-11-24 19:00:30 +00009059
Abramo Bagnara7945c982012-01-27 09:46:47 +00009060 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009061 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009062}
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregora16548e2009-08-11 05:31:07 +00009064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009066TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9067 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009068 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009069 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9070 TypeSourceInfo *From = E->getArg(I);
9071 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009072 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009073 TypeLocBuilder TLB;
9074 TLB.reserve(FromTL.getFullDataSize());
9075 QualType To = getDerived().TransformType(TLB, FromTL);
9076 if (To.isNull())
9077 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009078
Douglas Gregor29c42f22012-02-24 07:38:34 +00009079 if (To == From->getType())
9080 Args.push_back(From);
9081 else {
9082 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9083 ArgChanged = true;
9084 }
9085 continue;
9086 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009087
Douglas Gregor29c42f22012-02-24 07:38:34 +00009088 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009089
Douglas Gregor29c42f22012-02-24 07:38:34 +00009090 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009091 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009092 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9093 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9094 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009095
Douglas Gregor29c42f22012-02-24 07:38:34 +00009096 // Determine whether the set of unexpanded parameter packs can and should
9097 // be expanded.
9098 bool Expand = true;
9099 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009100 Optional<unsigned> OrigNumExpansions =
9101 ExpansionTL.getTypePtr()->getNumExpansions();
9102 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009103 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9104 PatternTL.getSourceRange(),
9105 Unexpanded,
9106 Expand, RetainExpansion,
9107 NumExpansions))
9108 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009109
Douglas Gregor29c42f22012-02-24 07:38:34 +00009110 if (!Expand) {
9111 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009112 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009113 // expansion.
9114 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregor29c42f22012-02-24 07:38:34 +00009116 TypeLocBuilder TLB;
9117 TLB.reserve(From->getTypeLoc().getFullDataSize());
9118
9119 QualType To = getDerived().TransformType(TLB, PatternTL);
9120 if (To.isNull())
9121 return ExprError();
9122
Chad Rosier1dcde962012-08-08 18:46:20 +00009123 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009124 PatternTL.getSourceRange(),
9125 ExpansionTL.getEllipsisLoc(),
9126 NumExpansions);
9127 if (To.isNull())
9128 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009129
Douglas Gregor29c42f22012-02-24 07:38:34 +00009130 PackExpansionTypeLoc ToExpansionTL
9131 = TLB.push<PackExpansionTypeLoc>(To);
9132 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9133 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9134 continue;
9135 }
9136
9137 // Expand the pack expansion by substituting for each argument in the
9138 // pack(s).
9139 for (unsigned I = 0; I != *NumExpansions; ++I) {
9140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9141 TypeLocBuilder TLB;
9142 TLB.reserve(PatternTL.getFullDataSize());
9143 QualType To = getDerived().TransformType(TLB, PatternTL);
9144 if (To.isNull())
9145 return ExprError();
9146
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009147 if (To->containsUnexpandedParameterPack()) {
9148 To = getDerived().RebuildPackExpansionType(To,
9149 PatternTL.getSourceRange(),
9150 ExpansionTL.getEllipsisLoc(),
9151 NumExpansions);
9152 if (To.isNull())
9153 return ExprError();
9154
9155 PackExpansionTypeLoc ToExpansionTL
9156 = TLB.push<PackExpansionTypeLoc>(To);
9157 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9158 }
9159
Douglas Gregor29c42f22012-02-24 07:38:34 +00009160 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9161 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009162
Douglas Gregor29c42f22012-02-24 07:38:34 +00009163 if (!RetainExpansion)
9164 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009165
Douglas Gregor29c42f22012-02-24 07:38:34 +00009166 // If we're supposed to retain a pack expansion, do so by temporarily
9167 // forgetting the partially-substituted parameter pack.
9168 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9169
9170 TypeLocBuilder TLB;
9171 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
Douglas Gregor29c42f22012-02-24 07:38:34 +00009173 QualType To = getDerived().TransformType(TLB, PatternTL);
9174 if (To.isNull())
9175 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009176
9177 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009178 PatternTL.getSourceRange(),
9179 ExpansionTL.getEllipsisLoc(),
9180 NumExpansions);
9181 if (To.isNull())
9182 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
Douglas Gregor29c42f22012-02-24 07:38:34 +00009184 PackExpansionTypeLoc ToExpansionTL
9185 = TLB.push<PackExpansionTypeLoc>(To);
9186 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9187 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009189
Douglas Gregor29c42f22012-02-24 07:38:34 +00009190 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009191 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009192
9193 return getDerived().RebuildTypeTrait(E->getTrait(),
9194 E->getLocStart(),
9195 Args,
9196 E->getLocEnd());
9197}
9198
9199template<typename Derived>
9200ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009201TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9202 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9203 if (!T)
9204 return ExprError();
9205
9206 if (!getDerived().AlwaysRebuild() &&
9207 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009208 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009209
9210 ExprResult SubExpr;
9211 {
9212 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9213 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9214 if (SubExpr.isInvalid())
9215 return ExprError();
9216
9217 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009218 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009219 }
9220
9221 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9222 E->getLocStart(),
9223 T,
9224 SubExpr.get(),
9225 E->getLocEnd());
9226}
9227
9228template<typename Derived>
9229ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009230TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9231 ExprResult SubExpr;
9232 {
9233 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9234 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9235 if (SubExpr.isInvalid())
9236 return ExprError();
9237
9238 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009239 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009240 }
9241
9242 return getDerived().RebuildExpressionTrait(
9243 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9244}
9245
Reid Kleckner32506ed2014-06-12 23:03:48 +00009246template <typename Derived>
9247ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9248 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9249 TypeSourceInfo **RecoveryTSI) {
9250 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9251 DRE, AddrTaken, RecoveryTSI);
9252
9253 // Propagate both errors and recovered types, which return ExprEmpty.
9254 if (!NewDRE.isUsable())
9255 return NewDRE;
9256
9257 // We got an expr, wrap it up in parens.
9258 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9259 return PE;
9260 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9261 PE->getRParen());
9262}
9263
9264template <typename Derived>
9265ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9266 DependentScopeDeclRefExpr *E) {
9267 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9268 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009269}
9270
9271template<typename Derived>
9272ExprResult
9273TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9274 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009275 bool IsAddressOfOperand,
9276 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009277 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009278 NestedNameSpecifierLoc QualifierLoc
9279 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9280 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009281 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009282 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009283
John McCall31f82722010-11-12 08:19:04 +00009284 // TODO: If this is a conversion-function-id, verify that the
9285 // destination type name (if present) resolves the same way after
9286 // instantiation as it did in the local scope.
9287
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009288 DeclarationNameInfo NameInfo
9289 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9290 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009292
John McCalle66edc12009-11-24 19:00:30 +00009293 if (!E->hasExplicitTemplateArgs()) {
9294 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009295 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009296 // Note: it is sufficient to compare the Name component of NameInfo:
9297 // if name has not changed, DNLoc has not changed either.
9298 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009299 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009300
Reid Kleckner32506ed2014-06-12 23:03:48 +00009301 return getDerived().RebuildDependentScopeDeclRefExpr(
9302 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9303 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009304 }
John McCall6b51f282009-11-23 01:53:49 +00009305
9306 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009307 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9308 E->getNumTemplateArgs(),
9309 TransArgs))
9310 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009311
Reid Kleckner32506ed2014-06-12 23:03:48 +00009312 return getDerived().RebuildDependentScopeDeclRefExpr(
9313 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9314 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009315}
9316
9317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009319TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009320 // CXXConstructExprs other than for list-initialization and
9321 // CXXTemporaryObjectExpr are always implicit, so when we have
9322 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009323 if ((E->getNumArgs() == 1 ||
9324 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009325 (!getDerived().DropCallArgument(E->getArg(0))) &&
9326 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009327 return getDerived().TransformExpr(E->getArg(0));
9328
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9330
9331 QualType T = getDerived().TransformType(E->getType());
9332 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009333 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009334
9335 CXXConstructorDecl *Constructor
9336 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009337 getDerived().TransformDecl(E->getLocStart(),
9338 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009339 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009341
Douglas Gregora16548e2009-08-11 05:31:07 +00009342 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009343 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009344 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009345 &ArgumentChanged))
9346 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009347
Douglas Gregora16548e2009-08-11 05:31:07 +00009348 if (!getDerived().AlwaysRebuild() &&
9349 T == E->getType() &&
9350 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009351 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009352 // Mark the constructor as referenced.
9353 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009354 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009355 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009356 }
Mike Stump11289f42009-09-09 15:08:12 +00009357
Douglas Gregordb121ba2009-12-14 16:27:04 +00009358 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9359 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009360 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009361 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009362 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009363 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009364 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009365 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009366 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009367}
Mike Stump11289f42009-09-09 15:08:12 +00009368
Douglas Gregora16548e2009-08-11 05:31:07 +00009369/// \brief Transform a C++ temporary-binding expression.
9370///
Douglas Gregor363b1512009-12-24 18:51:59 +00009371/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9372/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009375TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009376 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009377}
Mike Stump11289f42009-09-09 15:08:12 +00009378
John McCall5d413782010-12-06 08:20:24 +00009379/// \brief Transform a C++ expression that contains cleanups that should
9380/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009381///
John McCall5d413782010-12-06 08:20:24 +00009382/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009383/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009385ExprResult
John McCall5d413782010-12-06 08:20:24 +00009386TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009387 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009388}
Mike Stump11289f42009-09-09 15:08:12 +00009389
Douglas Gregora16548e2009-08-11 05:31:07 +00009390template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009391ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009392TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009393 CXXTemporaryObjectExpr *E) {
9394 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9395 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009396 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009397
Douglas Gregora16548e2009-08-11 05:31:07 +00009398 CXXConstructorDecl *Constructor
9399 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009400 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009401 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009402 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009404
Douglas Gregora16548e2009-08-11 05:31:07 +00009405 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009406 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009407 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009408 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009409 &ArgumentChanged))
9410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009411
Douglas Gregora16548e2009-08-11 05:31:07 +00009412 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009413 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009414 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009415 !ArgumentChanged) {
9416 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009417 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009418 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009420
Richard Smithd59b8322012-12-19 01:39:02 +00009421 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009422 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9423 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009424 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009425 E->getLocEnd());
9426}
Mike Stump11289f42009-09-09 15:08:12 +00009427
Douglas Gregora16548e2009-08-11 05:31:07 +00009428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009429ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009430TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009431 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009432 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009433 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009434 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9435 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009436 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009437 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009438 CEnd = E->capture_end();
9439 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009440 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009441 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009442 EnterExpressionEvaluationContext EEEC(getSema(),
9443 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009444 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9445 C->getCapturedVar()->getInit(),
9446 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009447
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009448 if (NewExprInitResult.isInvalid())
9449 return ExprError();
9450 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009451
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009452 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009453 QualType NewInitCaptureType =
9454 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9455 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009456 NewExprInit);
9457 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009458 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9459 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009460 }
9461
Faisal Vali2cba1332013-10-23 06:44:28 +00009462 // Transform the template parameters, and add them to the current
9463 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009464 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009465 E->getTemplateParameterList());
9466
Richard Smith01014ce2014-11-20 23:53:14 +00009467 // Transform the type of the original lambda's call operator.
9468 // The transformation MUST be done in the CurrentInstantiationScope since
9469 // it introduces a mapping of the original to the newly created
9470 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009471 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009472 {
9473 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9474 FunctionProtoTypeLoc OldCallOpFPTL =
9475 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009476
9477 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009478 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009479 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009480 QualType NewCallOpType = TransformFunctionProtoType(
9481 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009482 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9483 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9484 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009485 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009486 if (NewCallOpType.isNull())
9487 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009488 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9489 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009490 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009491
Richard Smithc38498f2015-04-27 21:27:54 +00009492 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9493 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9494 LSI->GLTemplateParameterList = TPL;
9495
Eli Friedmand564afb2012-09-19 01:18:11 +00009496 // Create the local class that will describe the lambda.
9497 CXXRecordDecl *Class
9498 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009499 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009500 /*KnownDependent=*/false,
9501 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009502 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9503
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009504 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009505 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9506 Class, E->getIntroducerRange(), NewCallOpTSI,
9507 E->getCallOperator()->getLocEnd(),
9508 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009509 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009510
Faisal Vali2cba1332013-10-23 06:44:28 +00009511 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009512 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009513
Douglas Gregorb4328232012-02-14 00:00:48 +00009514 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009515 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009516 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009517
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009518 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009519 getSema().buildLambdaScope(LSI, NewCallOperator,
9520 E->getIntroducerRange(),
9521 E->getCaptureDefault(),
9522 E->getCaptureDefaultLoc(),
9523 E->hasExplicitParameters(),
9524 E->hasExplicitResultType(),
9525 E->isMutable());
9526
9527 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009528
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009529 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009530 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009531 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009532 CEnd = E->capture_end();
9533 C != CEnd; ++C) {
9534 // When we hit the first implicit capture, tell Sema that we've finished
9535 // the list of explicit captures.
9536 if (!FinishedExplicitCaptures && C->isImplicit()) {
9537 getSema().finishLambdaExplicitCaptures(LSI);
9538 FinishedExplicitCaptures = true;
9539 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009540
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009541 // Capturing 'this' is trivial.
9542 if (C->capturesThis()) {
9543 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9544 continue;
9545 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009546 // Captured expression will be recaptured during captured variables
9547 // rebuilding.
9548 if (C->capturesVLAType())
9549 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009550
Richard Smithba71c082013-05-16 06:20:58 +00009551 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009552 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009553 InitCaptureInfoTy InitExprTypePair =
9554 InitCaptureExprsAndTypes[C - E->capture_begin()];
9555 ExprResult Init = InitExprTypePair.first;
9556 QualType InitQualType = InitExprTypePair.second;
9557 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009558 Invalid = true;
9559 continue;
9560 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009561 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009562 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9563 OldVD->getLocation(), InitExprTypePair.second,
9564 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009565 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009566 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009567 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009568 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009569 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009570 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009571 continue;
9572 }
9573
9574 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9575
Douglas Gregor3e308b12012-02-14 19:27:52 +00009576 // Determine the capture kind for Sema.
9577 Sema::TryCaptureKind Kind
9578 = C->isImplicit()? Sema::TryCapture_Implicit
9579 : C->getCaptureKind() == LCK_ByCopy
9580 ? Sema::TryCapture_ExplicitByVal
9581 : Sema::TryCapture_ExplicitByRef;
9582 SourceLocation EllipsisLoc;
9583 if (C->isPackExpansion()) {
9584 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9585 bool ShouldExpand = false;
9586 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009587 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009588 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9589 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009590 Unexpanded,
9591 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009592 NumExpansions)) {
9593 Invalid = true;
9594 continue;
9595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009596
Douglas Gregor3e308b12012-02-14 19:27:52 +00009597 if (ShouldExpand) {
9598 // The transform has determined that we should perform an expansion;
9599 // transform and capture each of the arguments.
9600 // expansion of the pattern. Do so.
9601 VarDecl *Pack = C->getCapturedVar();
9602 for (unsigned I = 0; I != *NumExpansions; ++I) {
9603 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9604 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009605 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009606 Pack));
9607 if (!CapturedVar) {
9608 Invalid = true;
9609 continue;
9610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009611
Douglas Gregor3e308b12012-02-14 19:27:52 +00009612 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009613 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9614 }
Richard Smith9467be42014-06-06 17:33:35 +00009615
9616 // FIXME: Retain a pack expansion if RetainExpansion is true.
9617
Douglas Gregor3e308b12012-02-14 19:27:52 +00009618 continue;
9619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009620
Douglas Gregor3e308b12012-02-14 19:27:52 +00009621 EllipsisLoc = C->getEllipsisLoc();
9622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009624 // Transform the captured variable.
9625 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009626 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009627 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009628 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009629 Invalid = true;
9630 continue;
9631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009632
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009633 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009634 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9635 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009636 }
9637 if (!FinishedExplicitCaptures)
9638 getSema().finishLambdaExplicitCaptures(LSI);
9639
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009640 // Enter a new evaluation context to insulate the lambda from any
9641 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009642 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009643
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009644 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009645 StmtResult Body =
9646 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9647
9648 // ActOnLambda* will pop the function scope for us.
9649 FuncScopeCleanup.disable();
9650
Douglas Gregorb4328232012-02-14 00:00:48 +00009651 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009652 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009653 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009654 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009655 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009656 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009657
Richard Smithc38498f2015-04-27 21:27:54 +00009658 // Copy the LSI before ActOnFinishFunctionBody removes it.
9659 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9660 // the call operator.
9661 auto LSICopy = *LSI;
9662 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9663 /*IsInstantiation*/ true);
9664 SavedContext.pop();
9665
9666 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9667 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009668}
9669
9670template<typename Derived>
9671ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009672TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009673 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009674 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9675 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009677
Douglas Gregora16548e2009-08-11 05:31:07 +00009678 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009679 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009680 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009681 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009682 &ArgumentChanged))
9683 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009684
Douglas Gregora16548e2009-08-11 05:31:07 +00009685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009686 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009687 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009688 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009689
Douglas Gregora16548e2009-08-11 05:31:07 +00009690 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009691 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009692 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009693 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 E->getRParenLoc());
9695}
Mike Stump11289f42009-09-09 15:08:12 +00009696
Douglas Gregora16548e2009-08-11 05:31:07 +00009697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009698ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009699TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009700 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009702 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009703 Expr *OldBase;
9704 QualType BaseType;
9705 QualType ObjectType;
9706 if (!E->isImplicitAccess()) {
9707 OldBase = E->getBase();
9708 Base = getDerived().TransformExpr(OldBase);
9709 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009711
John McCall2d74de92009-12-01 22:10:20 +00009712 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009713 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009714 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009715 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009716 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009717 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009718 ObjectTy,
9719 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009720 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009722
John McCallba7bf592010-08-24 05:47:05 +00009723 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009724 BaseType = ((Expr*) Base.get())->getType();
9725 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009726 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009727 BaseType = getDerived().TransformType(E->getBaseType());
9728 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9729 }
Mike Stump11289f42009-09-09 15:08:12 +00009730
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009731 // Transform the first part of the nested-name-specifier that qualifies
9732 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009733 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009734 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009735 E->getFirstQualifierFoundInScope(),
9736 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009737
Douglas Gregore16af532011-02-28 18:50:33 +00009738 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009739 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009740 QualifierLoc
9741 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9742 ObjectType,
9743 FirstQualifierInScope);
9744 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009745 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009746 }
Mike Stump11289f42009-09-09 15:08:12 +00009747
Abramo Bagnara7945c982012-01-27 09:46:47 +00009748 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9749
John McCall31f82722010-11-12 08:19:04 +00009750 // TODO: If this is a conversion-function-id, verify that the
9751 // destination type name (if present) resolves the same way after
9752 // instantiation as it did in the local scope.
9753
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009754 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009755 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009756 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009757 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009758
John McCall2d74de92009-12-01 22:10:20 +00009759 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009760 // This is a reference to a member without an explicitly-specified
9761 // template argument list. Optimize for this common case.
9762 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009763 Base.get() == OldBase &&
9764 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009765 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009766 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009767 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009768 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009769
John McCallb268a282010-08-23 23:25:46 +00009770 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009771 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009772 E->isArrow(),
9773 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009774 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009775 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009776 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009777 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009778 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009779 }
9780
John McCall6b51f282009-11-23 01:53:49 +00009781 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009782 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9783 E->getNumTemplateArgs(),
9784 TransArgs))
9785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009786
John McCallb268a282010-08-23 23:25:46 +00009787 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009788 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009789 E->isArrow(),
9790 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009791 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009792 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009793 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009794 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009795 &TransArgs);
9796}
9797
9798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009799ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009800TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009801 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009802 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009803 QualType BaseType;
9804 if (!Old->isImplicitAccess()) {
9805 Base = getDerived().TransformExpr(Old->getBase());
9806 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009807 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009808 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009809 Old->isArrow());
9810 if (Base.isInvalid())
9811 return ExprError();
9812 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009813 } else {
9814 BaseType = getDerived().TransformType(Old->getBaseType());
9815 }
John McCall10eae182009-11-30 22:42:35 +00009816
Douglas Gregor0da1d432011-02-28 20:01:57 +00009817 NestedNameSpecifierLoc QualifierLoc;
9818 if (Old->getQualifierLoc()) {
9819 QualifierLoc
9820 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9821 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009822 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009823 }
9824
Abramo Bagnara7945c982012-01-27 09:46:47 +00009825 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9826
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009827 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009828 Sema::LookupOrdinaryName);
9829
9830 // Transform all the decls.
9831 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9832 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009833 NamedDecl *InstD = static_cast<NamedDecl*>(
9834 getDerived().TransformDecl(Old->getMemberLoc(),
9835 *I));
John McCall84d87672009-12-10 09:41:52 +00009836 if (!InstD) {
9837 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9838 // This can happen because of dependent hiding.
9839 if (isa<UsingShadowDecl>(*I))
9840 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009841 else {
9842 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009843 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009844 }
John McCall84d87672009-12-10 09:41:52 +00009845 }
John McCall10eae182009-11-30 22:42:35 +00009846
9847 // Expand using declarations.
9848 if (isa<UsingDecl>(InstD)) {
9849 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009850 for (auto *I : UD->shadows())
9851 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009852 continue;
9853 }
9854
9855 R.addDecl(InstD);
9856 }
9857
9858 R.resolveKind();
9859
Douglas Gregor9262f472010-04-27 18:19:34 +00009860 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009861 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009862 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009863 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009864 Old->getMemberLoc(),
9865 Old->getNamingClass()));
9866 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009867 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009868
Douglas Gregorda7be082010-04-27 16:10:10 +00009869 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009871
John McCall10eae182009-11-30 22:42:35 +00009872 TemplateArgumentListInfo TransArgs;
9873 if (Old->hasExplicitTemplateArgs()) {
9874 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9875 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009876 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9877 Old->getNumTemplateArgs(),
9878 TransArgs))
9879 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009880 }
John McCall38836f02010-01-15 08:34:02 +00009881
9882 // FIXME: to do this check properly, we will need to preserve the
9883 // first-qualifier-in-scope here, just in case we had a dependent
9884 // base (and therefore couldn't do the check) and a
9885 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009886 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009887
John McCallb268a282010-08-23 23:25:46 +00009888 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009889 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009890 Old->getOperatorLoc(),
9891 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009892 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009893 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009894 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009895 R,
9896 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009897 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009898}
9899
9900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009901ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009902TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009903 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009904 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9905 if (SubExpr.isInvalid())
9906 return ExprError();
9907
9908 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009909 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009910
9911 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9912}
9913
9914template<typename Derived>
9915ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009916TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009917 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9918 if (Pattern.isInvalid())
9919 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009920
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009921 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009922 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009923
Douglas Gregorb8840002011-01-14 21:20:45 +00009924 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9925 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009926}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009927
9928template<typename Derived>
9929ExprResult
9930TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9931 // If E is not value-dependent, then nothing will change when we transform it.
9932 // Note: This is an instantiation-centric view.
9933 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009934 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009935
9936 // Note: None of the implementations of TryExpandParameterPacks can ever
9937 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00009938 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009939 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
9940 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009941 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009942 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009943 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00009944 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00009945 ShouldExpand, RetainExpansion,
9946 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009947 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009948
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009949 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009950 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009951
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009952 NamedDecl *Pack = E->getPack();
9953 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009954 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009955 Pack));
9956 if (!Pack)
9957 return ExprError();
9958 }
9959
Chad Rosier1dcde962012-08-08 18:46:20 +00009960
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009961 // We now know the length of the parameter pack, so build a new expression
9962 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +00009963 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
9964 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +00009965 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009966}
9967
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009968template<typename Derived>
9969ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009970TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
9971 SubstNonTypeTemplateParmPackExpr *E) {
9972 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009973 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +00009974}
9975
9976template<typename Derived>
9977ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00009978TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
9979 SubstNonTypeTemplateParmExpr *E) {
9980 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009981 return E;
John McCall7c454bb2011-07-15 05:09:51 +00009982}
9983
9984template<typename Derived>
9985ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +00009986TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
9987 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009988 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +00009989}
9990
9991template<typename Derived>
9992ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00009993TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
9994 MaterializeTemporaryExpr *E) {
9995 return getDerived().TransformExpr(E->GetTemporaryExpr());
9996}
Chad Rosier1dcde962012-08-08 18:46:20 +00009997
Douglas Gregorfe314812011-06-21 17:03:29 +00009998template<typename Derived>
9999ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010000TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10001 Expr *Pattern = E->getPattern();
10002
10003 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10004 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10005 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10006
10007 // Determine whether the set of unexpanded parameter packs can and should
10008 // be expanded.
10009 bool Expand = true;
10010 bool RetainExpansion = false;
10011 Optional<unsigned> NumExpansions;
10012 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10013 Pattern->getSourceRange(),
10014 Unexpanded,
10015 Expand, RetainExpansion,
10016 NumExpansions))
10017 return true;
10018
10019 if (!Expand) {
10020 // Do not expand any packs here, just transform and rebuild a fold
10021 // expression.
10022 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10023
10024 ExprResult LHS =
10025 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10026 if (LHS.isInvalid())
10027 return true;
10028
10029 ExprResult RHS =
10030 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10031 if (RHS.isInvalid())
10032 return true;
10033
10034 if (!getDerived().AlwaysRebuild() &&
10035 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10036 return E;
10037
10038 return getDerived().RebuildCXXFoldExpr(
10039 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10040 RHS.get(), E->getLocEnd());
10041 }
10042
10043 // The transform has determined that we should perform an elementwise
10044 // expansion of the pattern. Do so.
10045 ExprResult Result = getDerived().TransformExpr(E->getInit());
10046 if (Result.isInvalid())
10047 return true;
10048 bool LeftFold = E->isLeftFold();
10049
10050 // If we're retaining an expansion for a right fold, it is the innermost
10051 // component and takes the init (if any).
10052 if (!LeftFold && RetainExpansion) {
10053 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10054
10055 ExprResult Out = getDerived().TransformExpr(Pattern);
10056 if (Out.isInvalid())
10057 return true;
10058
10059 Result = getDerived().RebuildCXXFoldExpr(
10060 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10061 Result.get(), E->getLocEnd());
10062 if (Result.isInvalid())
10063 return true;
10064 }
10065
10066 for (unsigned I = 0; I != *NumExpansions; ++I) {
10067 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10068 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10069 ExprResult Out = getDerived().TransformExpr(Pattern);
10070 if (Out.isInvalid())
10071 return true;
10072
10073 if (Out.get()->containsUnexpandedParameterPack()) {
10074 // We still have a pack; retain a pack expansion for this slice.
10075 Result = getDerived().RebuildCXXFoldExpr(
10076 E->getLocStart(),
10077 LeftFold ? Result.get() : Out.get(),
10078 E->getOperator(), E->getEllipsisLoc(),
10079 LeftFold ? Out.get() : Result.get(),
10080 E->getLocEnd());
10081 } else if (Result.isUsable()) {
10082 // We've got down to a single element; build a binary operator.
10083 Result = getDerived().RebuildBinaryOperator(
10084 E->getEllipsisLoc(), E->getOperator(),
10085 LeftFold ? Result.get() : Out.get(),
10086 LeftFold ? Out.get() : Result.get());
10087 } else
10088 Result = Out;
10089
10090 if (Result.isInvalid())
10091 return true;
10092 }
10093
10094 // If we're retaining an expansion for a left fold, it is the outermost
10095 // component and takes the complete expansion so far as its init (if any).
10096 if (LeftFold && RetainExpansion) {
10097 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10098
10099 ExprResult Out = getDerived().TransformExpr(Pattern);
10100 if (Out.isInvalid())
10101 return true;
10102
10103 Result = getDerived().RebuildCXXFoldExpr(
10104 E->getLocStart(), Result.get(),
10105 E->getOperator(), E->getEllipsisLoc(),
10106 Out.get(), E->getLocEnd());
10107 if (Result.isInvalid())
10108 return true;
10109 }
10110
10111 // If we had no init and an empty pack, and we're not retaining an expansion,
10112 // then produce a fallback value or error.
10113 if (Result.isUnset())
10114 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10115 E->getOperator());
10116
10117 return Result;
10118}
10119
10120template<typename Derived>
10121ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010122TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10123 CXXStdInitializerListExpr *E) {
10124 return getDerived().TransformExpr(E->getSubExpr());
10125}
10126
10127template<typename Derived>
10128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010129TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010130 return SemaRef.MaybeBindToTemporary(E);
10131}
10132
10133template<typename Derived>
10134ExprResult
10135TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010136 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010137}
10138
10139template<typename Derived>
10140ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010141TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10142 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10143 if (SubExpr.isInvalid())
10144 return ExprError();
10145
10146 if (!getDerived().AlwaysRebuild() &&
10147 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010148 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010149
10150 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010151}
10152
10153template<typename Derived>
10154ExprResult
10155TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10156 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010157 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010158 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010159 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010160 /*IsCall=*/false, Elements, &ArgChanged))
10161 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010162
Ted Kremeneke65b0862012-03-06 20:05:56 +000010163 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10164 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010165
Ted Kremeneke65b0862012-03-06 20:05:56 +000010166 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10167 Elements.data(),
10168 Elements.size());
10169}
10170
10171template<typename Derived>
10172ExprResult
10173TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010174 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010175 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010176 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010177 bool ArgChanged = false;
10178 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10179 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010180
Ted Kremeneke65b0862012-03-06 20:05:56 +000010181 if (OrigElement.isPackExpansion()) {
10182 // This key/value element is a pack expansion.
10183 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10184 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10185 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10186 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10187
10188 // Determine whether the set of unexpanded parameter packs can
10189 // and should be expanded.
10190 bool Expand = true;
10191 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010192 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10193 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010194 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10195 OrigElement.Value->getLocEnd());
10196 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10197 PatternRange,
10198 Unexpanded,
10199 Expand, RetainExpansion,
10200 NumExpansions))
10201 return ExprError();
10202
10203 if (!Expand) {
10204 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010205 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010206 // expansion.
10207 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10208 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10209 if (Key.isInvalid())
10210 return ExprError();
10211
10212 if (Key.get() != OrigElement.Key)
10213 ArgChanged = true;
10214
10215 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10216 if (Value.isInvalid())
10217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010218
Ted Kremeneke65b0862012-03-06 20:05:56 +000010219 if (Value.get() != OrigElement.Value)
10220 ArgChanged = true;
10221
Chad Rosier1dcde962012-08-08 18:46:20 +000010222 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010223 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10224 };
10225 Elements.push_back(Expansion);
10226 continue;
10227 }
10228
10229 // Record right away that the argument was changed. This needs
10230 // to happen even if the array expands to nothing.
10231 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010232
Ted Kremeneke65b0862012-03-06 20:05:56 +000010233 // The transform has determined that we should perform an elementwise
10234 // expansion of the pattern. Do so.
10235 for (unsigned I = 0; I != *NumExpansions; ++I) {
10236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10237 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10238 if (Key.isInvalid())
10239 return ExprError();
10240
10241 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10242 if (Value.isInvalid())
10243 return ExprError();
10244
Chad Rosier1dcde962012-08-08 18:46:20 +000010245 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010246 Key.get(), Value.get(), SourceLocation(), NumExpansions
10247 };
10248
10249 // If any unexpanded parameter packs remain, we still have a
10250 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010251 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010252 if (Key.get()->containsUnexpandedParameterPack() ||
10253 Value.get()->containsUnexpandedParameterPack())
10254 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010255
Ted Kremeneke65b0862012-03-06 20:05:56 +000010256 Elements.push_back(Element);
10257 }
10258
Richard Smith9467be42014-06-06 17:33:35 +000010259 // FIXME: Retain a pack expansion if RetainExpansion is true.
10260
Ted Kremeneke65b0862012-03-06 20:05:56 +000010261 // We've finished with this pack expansion.
10262 continue;
10263 }
10264
10265 // Transform and check key.
10266 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10267 if (Key.isInvalid())
10268 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010269
Ted Kremeneke65b0862012-03-06 20:05:56 +000010270 if (Key.get() != OrigElement.Key)
10271 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010272
Ted Kremeneke65b0862012-03-06 20:05:56 +000010273 // Transform and check value.
10274 ExprResult Value
10275 = getDerived().TransformExpr(OrigElement.Value);
10276 if (Value.isInvalid())
10277 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010278
Ted Kremeneke65b0862012-03-06 20:05:56 +000010279 if (Value.get() != OrigElement.Value)
10280 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010281
10282 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010283 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010284 };
10285 Elements.push_back(Element);
10286 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010287
Ted Kremeneke65b0862012-03-06 20:05:56 +000010288 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10289 return SemaRef.MaybeBindToTemporary(E);
10290
10291 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10292 Elements.data(),
10293 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010294}
10295
Mike Stump11289f42009-09-09 15:08:12 +000010296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010297ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010298TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010299 TypeSourceInfo *EncodedTypeInfo
10300 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10301 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010303
Douglas Gregora16548e2009-08-11 05:31:07 +000010304 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010305 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010306 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010307
10308 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010309 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010310 E->getRParenLoc());
10311}
Mike Stump11289f42009-09-09 15:08:12 +000010312
Douglas Gregora16548e2009-08-11 05:31:07 +000010313template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010314ExprResult TreeTransform<Derived>::
10315TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010316 // This is a kind of implicit conversion, and it needs to get dropped
10317 // and recomputed for the same general reasons that ImplicitCastExprs
10318 // do, as well a more specific one: this expression is only valid when
10319 // it appears *immediately* as an argument expression.
10320 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010321}
10322
10323template<typename Derived>
10324ExprResult TreeTransform<Derived>::
10325TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010326 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010327 = getDerived().TransformType(E->getTypeInfoAsWritten());
10328 if (!TSInfo)
10329 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010330
John McCall31168b02011-06-15 23:02:42 +000010331 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010332 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010333 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010334
John McCall31168b02011-06-15 23:02:42 +000010335 if (!getDerived().AlwaysRebuild() &&
10336 TSInfo == E->getTypeInfoAsWritten() &&
10337 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010338 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010339
John McCall31168b02011-06-15 23:02:42 +000010340 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010341 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010342 Result.get());
10343}
10344
10345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010346ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010347TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010348 // Transform arguments.
10349 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010350 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010351 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010352 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010353 &ArgChanged))
10354 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010355
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010356 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10357 // Class message: transform the receiver type.
10358 TypeSourceInfo *ReceiverTypeInfo
10359 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10360 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010361 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010362
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010363 // If nothing changed, just retain the existing message send.
10364 if (!getDerived().AlwaysRebuild() &&
10365 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010366 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010367
10368 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010369 SmallVector<SourceLocation, 16> SelLocs;
10370 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010371 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10372 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010373 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010374 E->getMethodDecl(),
10375 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010376 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010377 E->getRightLoc());
10378 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010379 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10380 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10381 // Build a new class message send to 'super'.
10382 SmallVector<SourceLocation, 16> SelLocs;
10383 E->getSelectorLocs(SelLocs);
10384 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10385 E->getSelector(),
10386 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010387 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010388 E->getMethodDecl(),
10389 E->getLeftLoc(),
10390 Args,
10391 E->getRightLoc());
10392 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010393
10394 // Instance message: transform the receiver
10395 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10396 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010397 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010398 = getDerived().TransformExpr(E->getInstanceReceiver());
10399 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010400 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010401
10402 // If nothing changed, just retain the existing message send.
10403 if (!getDerived().AlwaysRebuild() &&
10404 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010405 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010406
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010407 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010408 SmallVector<SourceLocation, 16> SelLocs;
10409 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010410 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010411 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010412 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010413 E->getMethodDecl(),
10414 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010415 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010416 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010417}
10418
Mike Stump11289f42009-09-09 15:08:12 +000010419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010420ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010421TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010422 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010423}
10424
Mike Stump11289f42009-09-09 15:08:12 +000010425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010426ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010427TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010428 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010429}
10430
Mike Stump11289f42009-09-09 15:08:12 +000010431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010433TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010434 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010435 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010436 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010437 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010438
10439 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010440
Douglas Gregord51d90d2010-04-26 20:11:03 +000010441 // If nothing changed, just retain the existing expression.
10442 if (!getDerived().AlwaysRebuild() &&
10443 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010444 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010445
John McCallb268a282010-08-23 23:25:46 +000010446 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010447 E->getLocation(),
10448 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010449}
10450
Mike Stump11289f42009-09-09 15:08:12 +000010451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010452ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010453TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010454 // 'super' and types never change. Property never changes. Just
10455 // retain the existing expression.
10456 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010457 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010458
Douglas Gregor9faee212010-04-26 20:47:02 +000010459 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010460 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010461 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010462 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010463
Douglas Gregor9faee212010-04-26 20:47:02 +000010464 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010465
Douglas Gregor9faee212010-04-26 20:47:02 +000010466 // If nothing changed, just retain the existing expression.
10467 if (!getDerived().AlwaysRebuild() &&
10468 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010469 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010470
John McCallb7bd14f2010-12-02 01:19:52 +000010471 if (E->isExplicitProperty())
10472 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10473 E->getExplicitProperty(),
10474 E->getLocation());
10475
10476 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010477 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010478 E->getImplicitPropertyGetter(),
10479 E->getImplicitPropertySetter(),
10480 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010481}
10482
Mike Stump11289f42009-09-09 15:08:12 +000010483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010484ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010485TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10486 // Transform the base expression.
10487 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10488 if (Base.isInvalid())
10489 return ExprError();
10490
10491 // Transform the key expression.
10492 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10493 if (Key.isInvalid())
10494 return ExprError();
10495
10496 // If nothing changed, just retain the existing expression.
10497 if (!getDerived().AlwaysRebuild() &&
10498 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010499 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010500
Chad Rosier1dcde962012-08-08 18:46:20 +000010501 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010502 Base.get(), Key.get(),
10503 E->getAtIndexMethodDecl(),
10504 E->setAtIndexMethodDecl());
10505}
10506
10507template<typename Derived>
10508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010509TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010510 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010511 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010512 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010514
Douglas Gregord51d90d2010-04-26 20:11:03 +000010515 // If nothing changed, just retain the existing expression.
10516 if (!getDerived().AlwaysRebuild() &&
10517 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010518 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010519
John McCallb268a282010-08-23 23:25:46 +000010520 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010521 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010522 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010523}
10524
Mike Stump11289f42009-09-09 15:08:12 +000010525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010527TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010528 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010529 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010530 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010531 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010532 SubExprs, &ArgumentChanged))
10533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010534
Douglas Gregora16548e2009-08-11 05:31:07 +000010535 if (!getDerived().AlwaysRebuild() &&
10536 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010537 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010538
Douglas Gregora16548e2009-08-11 05:31:07 +000010539 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010540 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010541 E->getRParenLoc());
10542}
10543
Mike Stump11289f42009-09-09 15:08:12 +000010544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010545ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010546TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10547 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10548 if (SrcExpr.isInvalid())
10549 return ExprError();
10550
10551 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10552 if (!Type)
10553 return ExprError();
10554
10555 if (!getDerived().AlwaysRebuild() &&
10556 Type == E->getTypeSourceInfo() &&
10557 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010558 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010559
10560 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10561 SrcExpr.get(), Type,
10562 E->getRParenLoc());
10563}
10564
10565template<typename Derived>
10566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010567TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010568 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010569
Craig Topperc3ec1492014-05-26 06:22:03 +000010570 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010571 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10572
10573 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010574 blockScope->TheDecl->setBlockMissingReturnType(
10575 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010576
Chris Lattner01cf8db2011-07-20 06:58:45 +000010577 SmallVector<ParmVarDecl*, 4> params;
10578 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010579
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010580 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010581 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10582 oldBlock->param_begin(),
10583 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010584 nullptr, paramTypes, &params)) {
10585 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010586 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010587 }
John McCall490112f2011-02-04 18:33:18 +000010588
Jordan Rosea0a86be2013-03-08 22:25:36 +000010589 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010590 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010591 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010592
Jordan Rose5c382722013-03-08 21:51:21 +000010593 QualType functionType =
10594 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010595 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010596 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010597
10598 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010599 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010600 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010601
10602 if (!oldBlock->blockMissingReturnType()) {
10603 blockScope->HasImplicitReturnType = false;
10604 blockScope->ReturnType = exprResultType;
10605 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010606
John McCall3882ace2011-01-05 12:14:39 +000010607 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010608 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010609 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010610 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010611 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010612 }
John McCall3882ace2011-01-05 12:14:39 +000010613
John McCall490112f2011-02-04 18:33:18 +000010614#ifndef NDEBUG
10615 // In builds with assertions, make sure that we captured everything we
10616 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010617 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010618 for (const auto &I : oldBlock->captures()) {
10619 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010620
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010621 // Ignore parameter packs.
10622 if (isa<ParmVarDecl>(oldCapture) &&
10623 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10624 continue;
John McCall490112f2011-02-04 18:33:18 +000010625
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010626 VarDecl *newCapture =
10627 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10628 oldCapture));
10629 assert(blockScope->CaptureMap.count(newCapture));
10630 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010631 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010632 }
10633#endif
10634
10635 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010636 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010637}
10638
Mike Stump11289f42009-09-09 15:08:12 +000010639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010640ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010641TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010642 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010643}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010644
10645template<typename Derived>
10646ExprResult
10647TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010648 QualType RetTy = getDerived().TransformType(E->getType());
10649 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010650 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010651 SubExprs.reserve(E->getNumSubExprs());
10652 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10653 SubExprs, &ArgumentChanged))
10654 return ExprError();
10655
10656 if (!getDerived().AlwaysRebuild() &&
10657 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010658 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010659
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010660 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010661 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010662}
Chad Rosier1dcde962012-08-08 18:46:20 +000010663
Douglas Gregora16548e2009-08-11 05:31:07 +000010664//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010665// Type reconstruction
10666//===----------------------------------------------------------------------===//
10667
Mike Stump11289f42009-09-09 15:08:12 +000010668template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010669QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10670 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010671 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010672 getDerived().getBaseEntity());
10673}
10674
Mike Stump11289f42009-09-09 15:08:12 +000010675template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010676QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10677 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010678 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010679 getDerived().getBaseEntity());
10680}
10681
Mike Stump11289f42009-09-09 15:08:12 +000010682template<typename Derived>
10683QualType
John McCall70dd5f62009-10-30 00:06:24 +000010684TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10685 bool WrittenAsLValue,
10686 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010687 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010688 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010689}
10690
10691template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010692QualType
John McCall70dd5f62009-10-30 00:06:24 +000010693TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10694 QualType ClassType,
10695 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010696 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10697 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010698}
10699
10700template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010701QualType TreeTransform<Derived>::RebuildObjCObjectType(
10702 QualType BaseType,
10703 SourceLocation Loc,
10704 SourceLocation TypeArgsLAngleLoc,
10705 ArrayRef<TypeSourceInfo *> TypeArgs,
10706 SourceLocation TypeArgsRAngleLoc,
10707 SourceLocation ProtocolLAngleLoc,
10708 ArrayRef<ObjCProtocolDecl *> Protocols,
10709 ArrayRef<SourceLocation> ProtocolLocs,
10710 SourceLocation ProtocolRAngleLoc) {
10711 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10712 TypeArgs, TypeArgsRAngleLoc,
10713 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10714 ProtocolRAngleLoc,
10715 /*FailOnError=*/true);
10716}
10717
10718template<typename Derived>
10719QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10720 QualType PointeeType,
10721 SourceLocation Star) {
10722 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10723}
10724
10725template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010726QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010727TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10728 ArrayType::ArraySizeModifier SizeMod,
10729 const llvm::APInt *Size,
10730 Expr *SizeExpr,
10731 unsigned IndexTypeQuals,
10732 SourceRange BracketsRange) {
10733 if (SizeExpr || !Size)
10734 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10735 IndexTypeQuals, BracketsRange,
10736 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010737
10738 QualType Types[] = {
10739 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10740 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10741 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010742 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010743 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010744 QualType SizeType;
10745 for (unsigned I = 0; I != NumTypes; ++I)
10746 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10747 SizeType = Types[I];
10748 break;
10749 }
Mike Stump11289f42009-09-09 15:08:12 +000010750
Eli Friedman9562f392012-01-25 23:20:27 +000010751 // Note that we can return a VariableArrayType here in the case where
10752 // the element type was a dependent VariableArrayType.
10753 IntegerLiteral *ArraySize
10754 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10755 /*FIXME*/BracketsRange.getBegin());
10756 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010757 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010758 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010759}
Mike Stump11289f42009-09-09 15:08:12 +000010760
Douglas Gregord6ff3322009-08-04 16:50:30 +000010761template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010762QualType
10763TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010764 ArrayType::ArraySizeModifier SizeMod,
10765 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010766 unsigned IndexTypeQuals,
10767 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010768 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010769 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010770}
10771
10772template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010773QualType
Mike Stump11289f42009-09-09 15:08:12 +000010774TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010775 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010776 unsigned IndexTypeQuals,
10777 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010778 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010779 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010780}
Mike Stump11289f42009-09-09 15:08:12 +000010781
Douglas Gregord6ff3322009-08-04 16:50:30 +000010782template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010783QualType
10784TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010785 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010786 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010787 unsigned IndexTypeQuals,
10788 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010789 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010790 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010791 IndexTypeQuals, BracketsRange);
10792}
10793
10794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010795QualType
10796TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010799 unsigned IndexTypeQuals,
10800 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010801 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010802 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010803 IndexTypeQuals, BracketsRange);
10804}
10805
10806template<typename Derived>
10807QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010808 unsigned NumElements,
10809 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010810 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010811 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010812}
Mike Stump11289f42009-09-09 15:08:12 +000010813
Douglas Gregord6ff3322009-08-04 16:50:30 +000010814template<typename Derived>
10815QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10816 unsigned NumElements,
10817 SourceLocation AttributeLoc) {
10818 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10819 NumElements, true);
10820 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010821 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10822 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010823 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010824}
Mike Stump11289f42009-09-09 15:08:12 +000010825
Douglas Gregord6ff3322009-08-04 16:50:30 +000010826template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010827QualType
10828TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010829 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010830 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010831 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010832}
Mike Stump11289f42009-09-09 15:08:12 +000010833
Douglas Gregord6ff3322009-08-04 16:50:30 +000010834template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010835QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10836 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010837 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010838 const FunctionProtoType::ExtProtoInfo &EPI) {
10839 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010840 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010841 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010842 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010843}
Mike Stump11289f42009-09-09 15:08:12 +000010844
Douglas Gregord6ff3322009-08-04 16:50:30 +000010845template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010846QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10847 return SemaRef.Context.getFunctionNoProtoType(T);
10848}
10849
10850template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010851QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10852 assert(D && "no decl found");
10853 if (D->isInvalidDecl()) return QualType();
10854
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010855 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010856 TypeDecl *Ty;
10857 if (isa<UsingDecl>(D)) {
10858 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010859 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010860 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10861
10862 // A valid resolved using typename decl points to exactly one type decl.
10863 assert(++Using->shadow_begin() == Using->shadow_end());
10864 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010865
John McCallb96ec562009-12-04 22:46:56 +000010866 } else {
10867 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10868 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10869 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10870 }
10871
10872 return SemaRef.Context.getTypeDeclType(Ty);
10873}
10874
10875template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010876QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10877 SourceLocation Loc) {
10878 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010879}
10880
10881template<typename Derived>
10882QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10883 return SemaRef.Context.getTypeOfType(Underlying);
10884}
10885
10886template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010887QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10888 SourceLocation Loc) {
10889 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010890}
10891
10892template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010893QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10894 UnaryTransformType::UTTKind UKind,
10895 SourceLocation Loc) {
10896 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10897}
10898
10899template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010900QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010901 TemplateName Template,
10902 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010903 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010904 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010905}
Mike Stump11289f42009-09-09 15:08:12 +000010906
Douglas Gregor1135c352009-08-06 05:28:30 +000010907template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010908QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10909 SourceLocation KWLoc) {
10910 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10911}
10912
10913template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010914TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010915TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010916 bool TemplateKW,
10917 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010918 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010919 Template);
10920}
10921
10922template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010923TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010924TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10925 const IdentifierInfo &Name,
10926 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010927 QualType ObjectType,
10928 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010929 UnqualifiedId TemplateName;
10930 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010931 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010932 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010933 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010934 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010935 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010936 /*EnteringContext=*/false,
10937 Template);
John McCall31f82722010-11-12 08:19:04 +000010938 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000010939}
Mike Stump11289f42009-09-09 15:08:12 +000010940
Douglas Gregora16548e2009-08-11 05:31:07 +000010941template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000010942TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010943TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010944 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000010945 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000010946 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000010947 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000010948 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000010949 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000010950 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000010951 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000010952 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000010953 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010954 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000010955 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010956 /*EnteringContext=*/false,
10957 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000010958 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000010959}
Chad Rosier1dcde962012-08-08 18:46:20 +000010960
Douglas Gregor71395fa2009-11-04 00:56:37 +000010961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010962ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010963TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
10964 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000010965 Expr *OrigCallee,
10966 Expr *First,
10967 Expr *Second) {
10968 Expr *Callee = OrigCallee->IgnoreParenCasts();
10969 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000010970
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000010971 if (First->getObjectKind() == OK_ObjCProperty) {
10972 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
10973 if (BinaryOperator::isAssignmentOp(Opc))
10974 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
10975 First, Second);
10976 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
10977 if (Result.isInvalid())
10978 return ExprError();
10979 First = Result.get();
10980 }
10981
10982 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
10983 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
10984 if (Result.isInvalid())
10985 return ExprError();
10986 Second = Result.get();
10987 }
10988
Douglas Gregora16548e2009-08-11 05:31:07 +000010989 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000010990 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000010991 if (!First->getType()->isOverloadableType() &&
10992 !Second->getType()->isOverloadableType())
10993 return getSema().CreateBuiltinArraySubscriptExpr(First,
10994 Callee->getLocStart(),
10995 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000010996 } else if (Op == OO_Arrow) {
10997 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000010998 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
10999 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011000 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011001 // The argument is not of overloadable type, so try to create a
11002 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011003 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011004 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011005
John McCallb268a282010-08-23 23:25:46 +000011006 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011007 }
11008 } else {
John McCallb268a282010-08-23 23:25:46 +000011009 if (!First->getType()->isOverloadableType() &&
11010 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011011 // Neither of the arguments is an overloadable type, so try to
11012 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011013 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011014 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011015 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011016 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011017 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011018
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011019 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011020 }
11021 }
Mike Stump11289f42009-09-09 15:08:12 +000011022
11023 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011024 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011025 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011026
John McCallb268a282010-08-23 23:25:46 +000011027 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011028 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011029 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011030 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011031 // If we've resolved this to a particular non-member function, just call
11032 // that function. If we resolved it to a member function,
11033 // CreateOverloaded* will find that function for us.
11034 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11035 if (!isa<CXXMethodDecl>(ND))
11036 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011037 }
Mike Stump11289f42009-09-09 15:08:12 +000011038
Douglas Gregora16548e2009-08-11 05:31:07 +000011039 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011040 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011041 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011042
Douglas Gregora16548e2009-08-11 05:31:07 +000011043 // Create the overloaded operator invocation for unary operators.
11044 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011045 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011046 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011047 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011048 }
Mike Stump11289f42009-09-09 15:08:12 +000011049
Douglas Gregore9d62932011-07-15 16:25:15 +000011050 if (Op == OO_Subscript) {
11051 SourceLocation LBrace;
11052 SourceLocation RBrace;
11053
11054 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011055 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011056 LBrace = SourceLocation::getFromRawEncoding(
11057 NameLoc.CXXOperatorName.BeginOpNameLoc);
11058 RBrace = SourceLocation::getFromRawEncoding(
11059 NameLoc.CXXOperatorName.EndOpNameLoc);
11060 } else {
11061 LBrace = Callee->getLocStart();
11062 RBrace = OpLoc;
11063 }
11064
11065 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11066 First, Second);
11067 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011068
Douglas Gregora16548e2009-08-11 05:31:07 +000011069 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011070 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011071 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011072 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11073 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011075
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011076 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011077}
Mike Stump11289f42009-09-09 15:08:12 +000011078
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011079template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011080ExprResult
John McCallb268a282010-08-23 23:25:46 +000011081TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011082 SourceLocation OperatorLoc,
11083 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011084 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011085 TypeSourceInfo *ScopeType,
11086 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011087 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011088 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011089 QualType BaseType = Base->getType();
11090 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011091 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011092 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011093 !BaseType->getAs<PointerType>()->getPointeeType()
11094 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011095 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011096 return SemaRef.BuildPseudoDestructorExpr(
11097 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11098 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011099 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011100
Douglas Gregor678f90d2010-02-25 01:56:36 +000011101 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011102 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11103 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11104 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11105 NameInfo.setNamedTypeInfo(DestroyedType);
11106
Richard Smith8e4a3862012-05-15 06:15:11 +000011107 // The scope type is now known to be a valid nested name specifier
11108 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011109 if (ScopeType) {
11110 if (!ScopeType->getType()->getAs<TagType>()) {
11111 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11112 diag::err_expected_class_or_namespace)
11113 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11114 return ExprError();
11115 }
11116 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11117 CCLoc);
11118 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011119
Abramo Bagnara7945c982012-01-27 09:46:47 +000011120 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011121 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011122 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011123 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011124 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011125 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011126 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011127}
11128
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011129template<typename Derived>
11130StmtResult
11131TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011132 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011133 CapturedDecl *CD = S->getCapturedDecl();
11134 unsigned NumParams = CD->getNumParams();
11135 unsigned ContextParamPos = CD->getContextParamPosition();
11136 SmallVector<Sema::CapturedParamNameType, 4> Params;
11137 for (unsigned I = 0; I < NumParams; ++I) {
11138 if (I != ContextParamPos) {
11139 Params.push_back(
11140 std::make_pair(
11141 CD->getParam(I)->getName(),
11142 getDerived().TransformType(CD->getParam(I)->getType())));
11143 } else {
11144 Params.push_back(std::make_pair(StringRef(), QualType()));
11145 }
11146 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011147 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011148 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011149 StmtResult Body;
11150 {
11151 Sema::CompoundScopeRAII CompoundScope(getSema());
11152 Body = getDerived().TransformStmt(S->getCapturedStmt());
11153 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011154
11155 if (Body.isInvalid()) {
11156 getSema().ActOnCapturedRegionError();
11157 return StmtError();
11158 }
11159
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011160 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011161}
11162
Douglas Gregord6ff3322009-08-04 16:50:30 +000011163} // end namespace clang
11164
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011165#endif