blob: 117ae56969dcc8e82c69b6f68dd96e6e1786ad54 [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"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000851 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000855 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
James Dennett2a4d13c2012-06-15 07:13:21 +00001290 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001296 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001297 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001298 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001299 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001300 }
1301
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001302 /// \brief Rebuild an Objective-C exception declaration.
1303 ///
1304 /// By default, performs semantic analysis to build the new declaration.
1305 /// Subclasses may override this routine to provide different behavior.
1306 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1307 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001308 return getSema().BuildObjCExceptionDecl(TInfo, T,
1309 ExceptionDecl->getInnerLocStart(),
1310 ExceptionDecl->getLocation(),
1311 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001319 SourceLocation RParenLoc,
1320 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001322 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001323 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *Body) {
1332 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001334
James Dennett2a4d13c2012-06-15 07:13:21 +00001335 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001340 Expr *Operand) {
1341 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001343
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001344 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001348 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001349 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001350 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001351 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001352 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001353 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001354 return getSema().ActOnOpenMPExecutableDirective(
1355 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001356 }
1357
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001358 /// \brief Build a new OpenMP 'if' clause.
1359 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001360 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001361 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001362 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1363 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001364 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001365 SourceLocation NameModifierLoc,
1366 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001367 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001368 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1369 LParenLoc, NameModifierLoc, ColonLoc,
1370 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001371 }
1372
Alexey Bataev3778b602014-07-17 07:32:53 +00001373 /// \brief Build a new OpenMP 'final' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new OpenMP clause.
1376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1378 SourceLocation LParenLoc,
1379 SourceLocation EndLoc) {
1380 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1381 EndLoc);
1382 }
1383
Alexey Bataev568a8332014-03-06 06:15:19 +00001384 /// \brief Build a new OpenMP 'num_threads' clause.
1385 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001386 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001387 /// Subclasses may override this routine to provide different behavior.
1388 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1389 SourceLocation StartLoc,
1390 SourceLocation LParenLoc,
1391 SourceLocation EndLoc) {
1392 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1393 LParenLoc, EndLoc);
1394 }
1395
Alexey Bataev62c87d22014-03-21 04:51:18 +00001396 /// \brief Build a new OpenMP 'safelen' clause.
1397 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001398 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1401 SourceLocation LParenLoc,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1404 }
1405
Alexey Bataev66b15b52015-08-21 11:14:16 +00001406 /// \brief Build a new OpenMP 'simdlen' clause.
1407 ///
1408 /// By default, performs semantic analysis to build the new OpenMP clause.
1409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1414 }
1415
Alexander Musman8bd31e62014-05-27 15:12:19 +00001416 /// \brief Build a new OpenMP 'collapse' clause.
1417 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001418 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001419 /// Subclasses may override this routine to provide different behavior.
1420 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation EndLoc) {
1423 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1424 EndLoc);
1425 }
1426
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001427 /// \brief Build a new OpenMP 'default' clause.
1428 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001429 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001430 /// Subclasses may override this routine to provide different behavior.
1431 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1432 SourceLocation KindKwLoc,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1437 StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001440 /// \brief Build a new OpenMP 'proc_bind' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1445 SourceLocation KindKwLoc,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1450 StartLoc, LParenLoc, EndLoc);
1451 }
1452
Alexey Bataev56dafe82014-06-20 07:16:17 +00001453 /// \brief Build a new OpenMP 'schedule' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new OpenMP clause.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1458 Expr *ChunkSize,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation KindLoc,
1462 SourceLocation CommaLoc,
1463 SourceLocation EndLoc) {
1464 return getSema().ActOnOpenMPScheduleClause(
1465 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1466 }
1467
Alexey Bataev10e775f2015-07-30 11:36:16 +00001468 /// \brief Build a new OpenMP 'ordered' clause.
1469 ///
1470 /// By default, performs semantic analysis to build the new OpenMP clause.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1473 SourceLocation EndLoc,
1474 SourceLocation LParenLoc, Expr *Num) {
1475 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1476 }
1477
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001478 /// \brief Build a new OpenMP 'private' clause.
1479 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001480 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001481 /// Subclasses may override this routine to provide different behavior.
1482 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation EndLoc) {
1486 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1487 EndLoc);
1488 }
1489
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001490 /// \brief Build a new OpenMP 'firstprivate' clause.
1491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001493 /// Subclasses may override this routine to provide different behavior.
1494 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1495 SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation EndLoc) {
1498 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1499 EndLoc);
1500 }
1501
Alexander Musman1bb328c2014-06-04 13:06:39 +00001502 /// \brief Build a new OpenMP 'lastprivate' clause.
1503 ///
1504 /// By default, performs semantic analysis to build the new OpenMP clause.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001514 /// \brief Build a new OpenMP 'shared' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001517 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001518 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexey Bataevc5e02582014-06-16 07:08:35 +00001526 /// \brief Build a new OpenMP 'reduction' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new statement.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation ColonLoc,
1534 SourceLocation EndLoc,
1535 CXXScopeSpec &ReductionIdScopeSpec,
1536 const DeclarationNameInfo &ReductionId) {
1537 return getSema().ActOnOpenMPReductionClause(
1538 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1539 ReductionId);
1540 }
1541
Alexander Musman8dba6642014-04-22 13:09:42 +00001542 /// \brief Build a new OpenMP 'linear' clause.
1543 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001544 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001549 OpenMPLinearClauseKind Modifier,
1550 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001551 SourceLocation ColonLoc,
1552 SourceLocation EndLoc) {
1553 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001554 Modifier, ModifierLoc, ColonLoc,
1555 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001556 }
1557
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001558 /// \brief Build a new OpenMP 'aligned' clause.
1559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1563 SourceLocation StartLoc,
1564 SourceLocation LParenLoc,
1565 SourceLocation ColonLoc,
1566 SourceLocation EndLoc) {
1567 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1568 LParenLoc, ColonLoc, EndLoc);
1569 }
1570
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001571 /// \brief Build a new OpenMP 'copyin' clause.
1572 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001573 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001574 /// Subclasses may override this routine to provide different behavior.
1575 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1576 SourceLocation StartLoc,
1577 SourceLocation LParenLoc,
1578 SourceLocation EndLoc) {
1579 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1580 EndLoc);
1581 }
1582
Alexey Bataevbae9a792014-06-27 10:37:06 +00001583 /// \brief Build a new OpenMP 'copyprivate' clause.
1584 ///
1585 /// By default, performs semantic analysis to build the new OpenMP clause.
1586 /// Subclasses may override this routine to provide different behavior.
1587 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1588 SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1592 EndLoc);
1593 }
1594
Alexey Bataev6125da92014-07-21 11:26:11 +00001595 /// \brief Build a new OpenMP 'flush' pseudo clause.
1596 ///
1597 /// By default, performs semantic analysis to build the new OpenMP clause.
1598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001607 /// \brief Build a new OpenMP 'depend' pseudo clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *
1612 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1613 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1614 SourceLocation StartLoc, SourceLocation LParenLoc,
1615 SourceLocation EndLoc) {
1616 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1617 StartLoc, LParenLoc, EndLoc);
1618 }
1619
Michael Wonge710d542015-08-07 16:16:36 +00001620 /// \brief Build a new OpenMP 'device' clause.
1621 ///
1622 /// By default, performs semantic analysis to build the new statement.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
James Dennett2a4d13c2012-06-15 07:13:21 +00001631 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1635 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1636 Expr *object) {
1637 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1638 }
1639
James Dennett2a4d13c2012-06-15 07:13:21 +00001640 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001641 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001642 /// 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 RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001645 Expr *Object, Stmt *Body) {
1646 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001647 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001648
James Dennett2a4d13c2012-06-15 07:13:21 +00001649 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1654 Stmt *Body) {
1655 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1656 }
John McCall53848232011-07-27 01:07:15 +00001657
Douglas Gregorf68a5082010-04-22 23:10:45 +00001658 /// \brief Build a new Objective-C fast enumeration statement.
1659 ///
1660 /// By default, performs semantic analysis to build the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001663 Stmt *Element,
1664 Expr *Collection,
1665 SourceLocation RParenLoc,
1666 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001667 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001668 Element,
John McCallb268a282010-08-23 23:25:46 +00001669 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001670 RParenLoc);
1671 if (ForEachStmt.isInvalid())
1672 return StmtError();
1673
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001674 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001676
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 /// \brief Build a new C++ exception declaration.
1678 ///
1679 /// By default, performs semantic analysis to build the new decaration.
1680 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001681 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001682 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001683 SourceLocation StartLoc,
1684 SourceLocation IdLoc,
1685 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001686 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001687 StartLoc, IdLoc, Id);
1688 if (Var)
1689 getSema().CurContext->addDecl(Var);
1690 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001691 }
1692
1693 /// \brief Build a new C++ catch statement.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001697 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001698 VarDecl *ExceptionDecl,
1699 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001700 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1701 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 /// \brief Build a new C++ try statement.
1705 ///
1706 /// By default, performs semantic analysis to build the new statement.
1707 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001708 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1709 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001710 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001711 }
Mike Stump11289f42009-09-09 15:08:12 +00001712
Richard Smith02e85f32011-04-14 22:09:26 +00001713 /// \brief Build a new C++0x range-based for statement.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1718 SourceLocation ColonLoc,
1719 Stmt *Range, Stmt *BeginEnd,
1720 Expr *Cond, Expr *Inc,
1721 Stmt *LoopVar,
1722 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001723 // If we've just learned that the range is actually an Objective-C
1724 // collection, treat this as an Objective-C fast enumeration loop.
1725 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1726 if (RangeStmt->isSingleDecl()) {
1727 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001728 if (RangeVar->isInvalidDecl())
1729 return StmtError();
1730
Douglas Gregorf7106af2013-04-08 18:40:13 +00001731 Expr *RangeExpr = RangeVar->getInit();
1732 if (!RangeExpr->isTypeDependent() &&
1733 RangeExpr->getType()->isObjCObjectPointerType())
1734 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1735 RParenLoc);
1736 }
1737 }
1738 }
1739
Richard Smithcfd53b42015-10-22 06:13:50 +00001740 SourceLocation CoawaitLoc; // FIXME
1741 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
1742 Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001743 Cond, Inc, LoopVar, RParenLoc,
1744 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001745 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001746
1747 /// \brief Build a new C++0x range-based for statement.
1748 ///
1749 /// By default, performs semantic analysis to build the new statement.
1750 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001751 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001752 bool IsIfExists,
1753 NestedNameSpecifierLoc QualifierLoc,
1754 DeclarationNameInfo NameInfo,
1755 Stmt *Nested) {
1756 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1757 QualifierLoc, NameInfo, Nested);
1758 }
1759
Richard Smith02e85f32011-04-14 22:09:26 +00001760 /// \brief Attach body to a C++0x range-based for statement.
1761 ///
1762 /// By default, performs semantic analysis to finish the new statement.
1763 /// Subclasses may override this routine to provide different behavior.
1764 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1765 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001767
David Majnemerfad8f482013-10-15 09:33:02 +00001768 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001769 Stmt *TryBlock, Stmt *Handler) {
1770 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001771 }
1772
David Majnemerfad8f482013-10-15 09:33:02 +00001773 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001774 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001775 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001776 }
1777
David Majnemerfad8f482013-10-15 09:33:02 +00001778 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001779 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001780 }
1781
Alexey Bataevec474782014-10-09 08:45:04 +00001782 /// \brief Build a new predefined expression.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
1786 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1787 PredefinedExpr::IdentType IT) {
1788 return getSema().BuildPredefinedExpr(Loc, IT);
1789 }
1790
Douglas Gregora16548e2009-08-11 05:31:07 +00001791 /// \brief Build a new expression that references a declaration.
1792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001795 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001796 LookupResult &R,
1797 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001798 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1799 }
1800
1801
1802 /// \brief Build a new expression that references a declaration.
1803 ///
1804 /// By default, performs semantic analysis to build the new expression.
1805 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001806 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001807 ValueDecl *VD,
1808 const DeclarationNameInfo &NameInfo,
1809 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001810 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001811 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001812
1813 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001814
1815 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 }
Mike Stump11289f42009-09-09 15:08:12 +00001817
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001819 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001824 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 }
1826
Douglas Gregorad8a3362009-09-04 17:36:40 +00001827 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001828 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001831 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001832 SourceLocation OperatorLoc,
1833 bool isArrow,
1834 CXXScopeSpec &SS,
1835 TypeSourceInfo *ScopeType,
1836 SourceLocation CCLoc,
1837 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001838 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001841 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001845 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001846 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001847 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 }
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregor882211c2010-04-28 22:16:22 +00001850 /// \brief Build a new builtin offsetof expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001854 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001855 TypeSourceInfo *Type,
1856 ArrayRef<Sema::OffsetOfComponent> Components,
1857 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001858 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001859 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001861
1862 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001863 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001864 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001867 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1868 SourceLocation OpLoc,
1869 UnaryExprOrTypeTrait ExprKind,
1870 SourceRange R) {
1871 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 }
1873
Peter Collingbournee190dee2011-03-11 19:24:49 +00001874 /// \brief Build a new sizeof, alignof or vec step expression with an
1875 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001876 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001879 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1880 UnaryExprOrTypeTrait ExprKind,
1881 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001882 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001883 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001885 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001886
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001887 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 }
Mike Stump11289f42009-09-09 15:08:12 +00001889
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001891 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001896 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001898 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001899 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 RBracketLoc);
1901 }
1902
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001903 /// \brief Build a new array section expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
1907 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1908 Expr *LowerBound,
1909 SourceLocation ColonLoc, Expr *Length,
1910 SourceLocation RBracketLoc) {
1911 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1912 ColonLoc, Length, RBracketLoc);
1913 }
1914
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001916 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001921 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001922 Expr *ExecConfig = nullptr) {
1923 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001924 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001925 }
1926
1927 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001928 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001931 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001932 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001933 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001934 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001935 const DeclarationNameInfo &MemberNameInfo,
1936 ValueDecl *Member,
1937 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001938 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001939 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001940 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1941 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001942 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001943 // We have a reference to an unnamed field. This is always the
1944 // base of an anonymous struct/union member access, i.e. the
1945 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001946 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001947 assert(Member->getType()->isRecordType() &&
1948 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001949
Richard Smithcab9a7d2011-10-26 19:06:56 +00001950 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001951 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001952 QualifierLoc.getNestedNameSpecifier(),
1953 FoundDecl, Member);
1954 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001955 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001956 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001957 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001958 MemberExpr *ME = new (getSema().Context)
1959 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1960 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001961 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001962 }
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001964 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001965 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001966
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001967 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001968 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001969
John McCall16df1e52010-03-30 21:47:33 +00001970 // FIXME: this involves duplicating earlier analysis in a lot of
1971 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001972 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001973 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001974 R.resolveKind();
1975
John McCallb268a282010-08-23 23:25:46 +00001976 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001977 SS, TemplateKWLoc,
1978 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00001979 R, ExplicitTemplateArgs,
1980 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001984 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001987 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001988 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001989 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001990 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 }
1992
1993 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001997 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001998 SourceLocation QuestionLoc,
1999 Expr *LHS,
2000 SourceLocation ColonLoc,
2001 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002002 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2003 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 }
2005
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002007 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002010 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002011 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002012 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002014 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002015 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002019 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002023 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002026 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002027 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002031 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 SourceLocation OpLoc,
2036 SourceLocation AccessorLoc,
2037 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002038
John McCall10eae182009-11-30 22:42:35 +00002039 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002040 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002041 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002042 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002043 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002044 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002045 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002046 /* TemplateArgs */ nullptr,
2047 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 }
Mike Stump11289f42009-09-09 15:08:12 +00002049
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002051 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002054 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002055 MultiExprArg Inits,
2056 SourceLocation RBraceLoc,
2057 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002059 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002060 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002061 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002062
Douglas Gregord3d93062009-11-09 17:16:50 +00002063 // Patch in the result type we were given, which may have been computed
2064 // when the initial InitListExpr was built.
2065 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2066 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002067 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 }
Mike Stump11289f42009-09-09 15:08:12 +00002069
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002071 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 MultiExprArg ArrayExprs,
2076 SourceLocation EqualOrColonLoc,
2077 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002078 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002079 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002081 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002084
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002085 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 }
Mike Stump11289f42009-09-09 15:08:12 +00002087
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002089 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002090 /// By default, builds the implicit value initialization without performing
2091 /// any semantic analysis. Subclasses may override this routine to provide
2092 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002094 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 }
Mike Stump11289f42009-09-09 15:08:12 +00002096
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002098 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002101 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002102 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002103 SourceLocation RParenLoc) {
2104 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002105 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002106 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 }
2108
2109 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002110 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002113 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002114 MultiExprArg SubExprs,
2115 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002116 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002120 ///
2121 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 /// rather than attempting to map the label statement itself.
2123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002124 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002125 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002126 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002130 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002133 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002134 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002136 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 }
Mike Stump11289f42009-09-09 15:08:12 +00002138
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 /// \brief Build a new __builtin_choose_expr expression.
2140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002143 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002144 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation RParenLoc) {
2146 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002147 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 RParenLoc);
2149 }
Mike Stump11289f42009-09-09 15:08:12 +00002150
Peter Collingbourne91147592011-04-15 00:35:48 +00002151 /// \brief Build a new generic selection expression.
2152 ///
2153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
2155 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2156 SourceLocation DefaultLoc,
2157 SourceLocation RParenLoc,
2158 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002159 ArrayRef<TypeSourceInfo *> Types,
2160 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002161 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002162 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002163 }
2164
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// \brief Build a new overloaded operator call expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// The semantic analysis provides the behavior of template instantiation,
2169 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002170 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 /// argument-dependent lookup, etc. Subclasses may override this routine to
2172 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002175 Expr *Callee,
2176 Expr *First,
2177 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002178
2179 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 /// reinterpret_cast.
2181 ///
2182 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002183 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002185 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 Stmt::StmtClass Class,
2187 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002188 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SourceLocation RAngleLoc,
2190 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002191 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 SourceLocation RParenLoc) {
2193 switch (Class) {
2194 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002195 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002196 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002197 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198
2199 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002200 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002201 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002202 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002203
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002205 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002206 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002207 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002211 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002212 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002213 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002214
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002216 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 }
Mike Stump11289f42009-09-09 15:08:12 +00002219
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 /// \brief Build a new C++ static_cast expression.
2221 ///
2222 /// By default, performs semantic analysis to build the new expression.
2223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002224 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002226 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 SourceLocation RAngleLoc,
2228 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002229 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002231 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002232 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002233 SourceRange(LAngleLoc, RAngleLoc),
2234 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 }
2236
2237 /// \brief Build a new C++ dynamic_cast expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002241 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002243 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 SourceLocation RAngleLoc,
2245 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002246 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002248 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002249 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002250 SourceRange(LAngleLoc, RAngleLoc),
2251 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 }
2253
2254 /// \brief Build a new C++ reinterpret_cast expression.
2255 ///
2256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002258 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002260 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 SourceLocation RAngleLoc,
2262 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002263 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002265 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002266 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002267 SourceRange(LAngleLoc, RAngleLoc),
2268 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
2270
2271 /// \brief Build a new C++ const_cast expression.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002277 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 SourceLocation RAngleLoc,
2279 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002280 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002282 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002283 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002284 SourceRange(LAngleLoc, RAngleLoc),
2285 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 }
Mike Stump11289f42009-09-09 15:08:12 +00002287
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// \brief Build a new C++ functional-style cast expression.
2289 ///
2290 /// By default, performs semantic analysis to build the new expression.
2291 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002292 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2293 SourceLocation LParenLoc,
2294 Expr *Sub,
2295 SourceLocation RParenLoc) {
2296 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002297 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 RParenLoc);
2299 }
Mike Stump11289f42009-09-09 15:08:12 +00002300
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 /// \brief Build a new C++ typeid(type) expression.
2302 ///
2303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002306 SourceLocation TypeidLoc,
2307 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002309 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002310 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 }
Mike Stump11289f42009-09-09 15:08:12 +00002312
Francois Pichet9f4f2072010-09-08 12:20:18 +00002313
Douglas Gregora16548e2009-08-11 05:31:07 +00002314 /// \brief Build a new C++ typeid(expr) expression.
2315 ///
2316 /// By default, performs semantic analysis to build the new expression.
2317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002318 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002319 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002320 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002322 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002323 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002324 }
2325
Francois Pichet9f4f2072010-09-08 12:20:18 +00002326 /// \brief Build a new C++ __uuidof(type) expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
2330 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2331 SourceLocation TypeidLoc,
2332 TypeSourceInfo *Operand,
2333 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002334 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002335 RParenLoc);
2336 }
2337
2338 /// \brief Build a new C++ __uuidof(expr) expression.
2339 ///
2340 /// By default, performs semantic analysis to build the new expression.
2341 /// Subclasses may override this routine to provide different behavior.
2342 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2343 SourceLocation TypeidLoc,
2344 Expr *Operand,
2345 SourceLocation RParenLoc) {
2346 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2347 RParenLoc);
2348 }
2349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 /// \brief Build a new C++ "this" expression.
2351 ///
2352 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002353 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002355 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002356 QualType ThisType,
2357 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002358 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002359 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 }
2361
2362 /// \brief Build a new C++ throw expression.
2363 ///
2364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002366 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2367 bool IsThrownVariableInScope) {
2368 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 }
2370
2371 /// \brief Build a new C++ default-argument expression.
2372 ///
2373 /// By default, builds a new default-argument expression, which does not
2374 /// require any semantic analysis. Subclasses may override this routine to
2375 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002376 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002377 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002378 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 }
2380
Richard Smith852c9db2013-04-20 22:23:05 +00002381 /// \brief Build a new C++11 default-initialization expression.
2382 ///
2383 /// By default, builds a new default field initialization expression, which
2384 /// does not require any semantic analysis. Subclasses may override this
2385 /// routine to provide different behavior.
2386 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2387 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002388 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002389 }
2390
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 /// \brief Build a new C++ zero-initialization expression.
2392 ///
2393 /// By default, performs semantic analysis to build the new expression.
2394 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002395 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2396 SourceLocation LParenLoc,
2397 SourceLocation RParenLoc) {
2398 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002399 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 }
Mike Stump11289f42009-09-09 15:08:12 +00002401
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 /// \brief Build a new C++ "new" expression.
2403 ///
2404 /// By default, performs semantic analysis to build the new expression.
2405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002406 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002407 bool UseGlobal,
2408 SourceLocation PlacementLParen,
2409 MultiExprArg PlacementArgs,
2410 SourceLocation PlacementRParen,
2411 SourceRange TypeIdParens,
2412 QualType AllocatedType,
2413 TypeSourceInfo *AllocatedTypeInfo,
2414 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002415 SourceRange DirectInitRange,
2416 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002417 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002419 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002421 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002422 AllocatedType,
2423 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002424 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002425 DirectInitRange,
2426 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 }
Mike Stump11289f42009-09-09 15:08:12 +00002428
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 /// \brief Build a new C++ "delete" expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002433 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 bool IsGlobalDelete,
2435 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002436 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002438 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregor29c42f22012-02-24 07:38:34 +00002441 /// \brief Build a new type trait expression.
2442 ///
2443 /// By default, performs semantic analysis to build the new expression.
2444 /// Subclasses may override this routine to provide different behavior.
2445 ExprResult RebuildTypeTrait(TypeTrait Trait,
2446 SourceLocation StartLoc,
2447 ArrayRef<TypeSourceInfo *> Args,
2448 SourceLocation RParenLoc) {
2449 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2450 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002451
John Wiegley6242b6a2011-04-28 00:16:57 +00002452 /// \brief Build a new array type trait expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
2456 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2457 SourceLocation StartLoc,
2458 TypeSourceInfo *TSInfo,
2459 Expr *DimExpr,
2460 SourceLocation RParenLoc) {
2461 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2462 }
2463
John Wiegleyf9f65842011-04-25 06:54:41 +00002464 /// \brief Build a new expression trait expression.
2465 ///
2466 /// By default, performs semantic analysis to build the new expression.
2467 /// Subclasses may override this routine to provide different behavior.
2468 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2469 SourceLocation StartLoc,
2470 Expr *Queried,
2471 SourceLocation RParenLoc) {
2472 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2473 }
2474
Mike Stump11289f42009-09-09 15:08:12 +00002475 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 /// expression.
2477 ///
2478 /// By default, performs semantic analysis to build the new expression.
2479 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002480 ExprResult RebuildDependentScopeDeclRefExpr(
2481 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002482 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002483 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002484 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002485 bool IsAddressOfOperand,
2486 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002488 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002489
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002490 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002491 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2492 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002493
Reid Kleckner32506ed2014-06-12 23:03:48 +00002494 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002495 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 }
2497
2498 /// \brief Build a new template-id expression.
2499 ///
2500 /// By default, performs semantic analysis to build the new expression.
2501 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002502 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002503 SourceLocation TemplateKWLoc,
2504 LookupResult &R,
2505 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002506 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002507 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2508 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002509 }
2510
2511 /// \brief Build a new object-construction expression.
2512 ///
2513 /// By default, performs semantic analysis to build the new expression.
2514 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002515 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002516 SourceLocation Loc,
2517 CXXConstructorDecl *Constructor,
2518 bool IsElidable,
2519 MultiExprArg Args,
2520 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002521 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002522 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002523 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002524 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002525 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002526 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002527 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002528 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002529 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002530
Douglas Gregordb121ba2009-12-14 16:27:04 +00002531 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002532 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002533 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002534 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002535 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002536 RequiresZeroInit, ConstructKind,
2537 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002538 }
2539
2540 /// \brief Build a new object-construction expression.
2541 ///
2542 /// By default, performs semantic analysis to build the new expression.
2543 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002544 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2545 SourceLocation LParenLoc,
2546 MultiExprArg Args,
2547 SourceLocation RParenLoc) {
2548 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002550 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 RParenLoc);
2552 }
2553
2554 /// \brief Build a new object-construction expression.
2555 ///
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002558 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2559 SourceLocation LParenLoc,
2560 MultiExprArg Args,
2561 SourceLocation RParenLoc) {
2562 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002564 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 RParenLoc);
2566 }
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 /// \brief Build a new member reference expression.
2569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002572 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002573 QualType BaseType,
2574 bool IsArrow,
2575 SourceLocation OperatorLoc,
2576 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002577 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002578 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002579 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002580 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002582 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002583
John McCallb268a282010-08-23 23:25:46 +00002584 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002585 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002586 SS, TemplateKWLoc,
2587 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002588 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002589 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 }
2591
John McCall10eae182009-11-30 22:42:35 +00002592 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002593 ///
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002596 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2597 SourceLocation OperatorLoc,
2598 bool IsArrow,
2599 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002600 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002601 NamedDecl *FirstQualifierInScope,
2602 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002603 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002604 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002605 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002606
John McCallb268a282010-08-23 23:25:46 +00002607 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002608 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002609 SS, TemplateKWLoc,
2610 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002611 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002612 }
Mike Stump11289f42009-09-09 15:08:12 +00002613
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002614 /// \brief Build a new noexcept expression.
2615 ///
2616 /// By default, performs semantic analysis to build the new expression.
2617 /// Subclasses may override this routine to provide different behavior.
2618 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2619 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2620 }
2621
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002622 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002623 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2624 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002625 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002626 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002627 Optional<unsigned> Length,
2628 ArrayRef<TemplateArgument> PartialArgs) {
2629 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2630 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002631 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002632
Patrick Beard0caa3942012-04-19 00:25:12 +00002633 /// \brief Build a new Objective-C boxed expression.
2634 ///
2635 /// By default, performs semantic analysis to build the new expression.
2636 /// Subclasses may override this routine to provide different behavior.
2637 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2638 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002640
Ted Kremeneke65b0862012-03-06 20:05:56 +00002641 /// \brief Build a new Objective-C array literal.
2642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
2645 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2646 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002647 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002648 MultiExprArg(Elements, NumElements));
2649 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002650
2651 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002652 Expr *Base, Expr *Key,
2653 ObjCMethodDecl *getterMethod,
2654 ObjCMethodDecl *setterMethod) {
2655 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2656 getterMethod, setterMethod);
2657 }
2658
2659 /// \brief Build a new Objective-C dictionary literal.
2660 ///
2661 /// By default, performs semantic analysis to build the new expression.
2662 /// Subclasses may override this routine to provide different behavior.
2663 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2664 ObjCDictionaryElement *Elements,
2665 unsigned NumElements) {
2666 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2667 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002668
James Dennett2a4d13c2012-06-15 07:13:21 +00002669 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002670 ///
2671 /// By default, performs semantic analysis to build the new expression.
2672 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002673 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002674 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002676 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002677 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002678
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002679 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002680 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002681 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002682 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002683 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002684 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002685 MultiExprArg Args,
2686 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002687 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2688 ReceiverTypeInfo->getType(),
2689 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002690 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002691 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002692 }
2693
2694 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002695 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002696 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002697 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002698 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002699 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002700 MultiExprArg Args,
2701 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002702 return SemaRef.BuildInstanceMessage(Receiver,
2703 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002704 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002705 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002706 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002707 }
2708
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002709 /// \brief Build a new Objective-C instance/class message to 'super'.
2710 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2711 Selector Sel,
2712 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002713 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002714 ObjCMethodDecl *Method,
2715 SourceLocation LBracLoc,
2716 MultiExprArg Args,
2717 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002718 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002719 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002720 SuperLoc,
2721 Sel, Method, LBracLoc, SelectorLocs,
2722 RBracLoc, Args)
2723 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002724 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002725 SuperLoc,
2726 Sel, Method, LBracLoc, SelectorLocs,
2727 RBracLoc, Args);
2728
2729
2730 }
2731
Douglas Gregord51d90d2010-04-26 20:11:03 +00002732 /// \brief Build a new Objective-C ivar reference expression.
2733 ///
2734 /// By default, performs semantic analysis to build the new expression.
2735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002736 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002737 SourceLocation IvarLoc,
2738 bool IsArrow, bool IsFreeIvar) {
2739 // FIXME: We lose track of the IsFreeIvar bit.
2740 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002741 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2742 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002743 /*FIXME:*/IvarLoc, IsArrow,
2744 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002745 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002746 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002747 /*TemplateArgs=*/nullptr,
2748 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002749 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002750
2751 /// \brief Build a new Objective-C property reference expression.
2752 ///
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002755 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002756 ObjCPropertyDecl *Property,
2757 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002758 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002759 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2760 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2761 /*FIXME:*/PropertyLoc,
2762 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002763 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002764 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002765 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002766 /*TemplateArgs=*/nullptr,
2767 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002768 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002769
John McCallb7bd14f2010-12-02 01:19:52 +00002770 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002771 ///
2772 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002773 /// Subclasses may override this routine to provide different behavior.
2774 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2775 ObjCMethodDecl *Getter,
2776 ObjCMethodDecl *Setter,
2777 SourceLocation PropertyLoc) {
2778 // Since these expressions can only be value-dependent, we do not
2779 // need to perform semantic analysis again.
2780 return Owned(
2781 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2782 VK_LValue, OK_ObjCProperty,
2783 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002784 }
2785
Douglas Gregord51d90d2010-04-26 20:11:03 +00002786 /// \brief Build a new Objective-C "isa" expression.
2787 ///
2788 /// By default, performs semantic analysis to build the new expression.
2789 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002790 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002791 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002792 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002793 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2794 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002795 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002796 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002797 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002798 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002799 /*TemplateArgs=*/nullptr,
2800 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002802
Douglas Gregora16548e2009-08-11 05:31:07 +00002803 /// \brief Build a new shuffle vector expression.
2804 ///
2805 /// By default, performs semantic analysis to build the new expression.
2806 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002807 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002808 MultiExprArg SubExprs,
2809 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002810 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002811 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002812 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2813 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2814 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002815 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002816
Douglas Gregora16548e2009-08-11 05:31:07 +00002817 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002818 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002819 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2820 SemaRef.Context.BuiltinFnTy,
2821 VK_RValue, BuiltinLoc);
2822 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2823 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002824 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002825
2826 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002827 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002828 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002829 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002830
Douglas Gregora16548e2009-08-11 05:31:07 +00002831 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002832 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002833 }
John McCall31f82722010-11-12 08:19:04 +00002834
Hal Finkelc4d7c822013-09-18 03:29:45 +00002835 /// \brief Build a new convert vector expression.
2836 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2837 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2838 SourceLocation RParenLoc) {
2839 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2840 BuiltinLoc, RParenLoc);
2841 }
2842
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002843 /// \brief Build a new template argument pack expansion.
2844 ///
2845 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002846 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002847 /// different behavior.
2848 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002849 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002850 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002851 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002852 case TemplateArgument::Expression: {
2853 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002854 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2855 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002856 if (Result.isInvalid())
2857 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002858
Douglas Gregor98318c22011-01-03 21:37:45 +00002859 return TemplateArgumentLoc(Result.get(), Result.get());
2860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002861
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002862 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002863 return TemplateArgumentLoc(TemplateArgument(
2864 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002865 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002866 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002867 Pattern.getTemplateNameLoc(),
2868 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002869
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002870 case TemplateArgument::Null:
2871 case TemplateArgument::Integral:
2872 case TemplateArgument::Declaration:
2873 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002874 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002875 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002876 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002877
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002878 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002879 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002880 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002881 EllipsisLoc,
2882 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002883 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2884 Expansion);
2885 break;
2886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002888 return TemplateArgumentLoc();
2889 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002890
Douglas Gregor968f23a2011-01-03 19:31:53 +00002891 /// \brief Build a new expression pack expansion.
2892 ///
2893 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002894 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002895 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002896 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002897 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002898 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002899 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002900
Richard Smith0f0af192014-11-08 05:07:16 +00002901 /// \brief Build a new C++1z fold-expression.
2902 ///
2903 /// By default, performs semantic analysis in order to build a new fold
2904 /// expression.
2905 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2906 BinaryOperatorKind Operator,
2907 SourceLocation EllipsisLoc, Expr *RHS,
2908 SourceLocation RParenLoc) {
2909 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2910 RHS, RParenLoc);
2911 }
2912
2913 /// \brief Build an empty C++1z fold-expression with the given operator.
2914 ///
2915 /// By default, produces the fallback value for the fold-expression, or
2916 /// produce an error if there is no fallback value.
2917 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2918 BinaryOperatorKind Operator) {
2919 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2920 }
2921
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002922 /// \brief Build a new atomic operation expression.
2923 ///
2924 /// By default, performs semantic analysis to build the new expression.
2925 /// Subclasses may override this routine to provide different behavior.
2926 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2927 MultiExprArg SubExprs,
2928 QualType RetTy,
2929 AtomicExpr::AtomicOp Op,
2930 SourceLocation RParenLoc) {
2931 // Just create the expression; there is not any interesting semantic
2932 // analysis here because we can't actually build an AtomicExpr until
2933 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002934 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002935 RParenLoc);
2936 }
2937
John McCall31f82722010-11-12 08:19:04 +00002938private:
Douglas Gregor14454802011-02-25 02:25:35 +00002939 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2940 QualType ObjectType,
2941 NamedDecl *FirstQualifierInScope,
2942 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002943
2944 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2945 QualType ObjectType,
2946 NamedDecl *FirstQualifierInScope,
2947 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002948
2949 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2950 NamedDecl *FirstQualifierInScope,
2951 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952};
Douglas Gregora16548e2009-08-11 05:31:07 +00002953
Douglas Gregorebe10102009-08-20 07:17:43 +00002954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002955StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002956 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002957 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002958
Douglas Gregorebe10102009-08-20 07:17:43 +00002959 switch (S->getStmtClass()) {
2960 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002961
Douglas Gregorebe10102009-08-20 07:17:43 +00002962 // Transform individual statement nodes
2963#define STMT(Node, Parent) \
2964 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002965#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002966#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002967#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002968
Douglas Gregorebe10102009-08-20 07:17:43 +00002969 // Transform expressions by calling TransformExpr.
2970#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002971#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002972#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002973#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002974 {
John McCalldadc5752010-08-24 06:29:42 +00002975 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002976 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002977 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002978
Richard Smith945f8d32013-01-14 22:39:08 +00002979 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002980 }
Mike Stump11289f42009-09-09 15:08:12 +00002981 }
2982
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002983 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002984}
Mike Stump11289f42009-09-09 15:08:12 +00002985
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002986template<typename Derived>
2987OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2988 if (!S)
2989 return S;
2990
2991 switch (S->getClauseKind()) {
2992 default: break;
2993 // Transform individual clause nodes
2994#define OPENMP_CLAUSE(Name, Class) \
2995 case OMPC_ ## Name : \
2996 return getDerived().Transform ## Class(cast<Class>(S));
2997#include "clang/Basic/OpenMPKinds.def"
2998 }
2999
3000 return S;
3001}
3002
Mike Stump11289f42009-09-09 15:08:12 +00003003
Douglas Gregore922c772009-08-04 22:27:00 +00003004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003005ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003006 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003007 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003008
3009 switch (E->getStmtClass()) {
3010 case Stmt::NoStmtClass: break;
3011#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003012#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003013#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003014 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003015#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003016 }
3017
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003018 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003019}
3020
3021template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003022ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003023 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003024 // Initializers are instantiated like expressions, except that various outer
3025 // layers are stripped.
3026 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003027 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003028
3029 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3030 Init = ExprTemp->getSubExpr();
3031
Richard Smithe6ca4752013-05-30 22:40:16 +00003032 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3033 Init = MTE->GetTemporaryExpr();
3034
Richard Smithd59b8322012-12-19 01:39:02 +00003035 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3036 Init = Binder->getSubExpr();
3037
3038 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3039 Init = ICE->getSubExprAsWritten();
3040
Richard Smithcc1b96d2013-06-12 22:31:48 +00003041 if (CXXStdInitializerListExpr *ILE =
3042 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003043 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003044
Richard Smithc6abd962014-07-25 01:12:44 +00003045 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003046 // InitListExprs. Other forms of copy-initialization will be a no-op if
3047 // the initializer is already the right type.
3048 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003049 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003050 return getDerived().TransformExpr(Init);
3051
3052 // Revert value-initialization back to empty parens.
3053 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3054 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003055 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003056 Parens.getEnd());
3057 }
3058
3059 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3060 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003061 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003062 SourceLocation());
3063
3064 // Revert initialization by constructor back to a parenthesized or braced list
3065 // of expressions. Any other form of initializer can just be reused directly.
3066 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003067 return getDerived().TransformExpr(Init);
3068
Richard Smithf8adcdc2014-07-17 05:12:35 +00003069 // If the initialization implicitly converted an initializer list to a
3070 // std::initializer_list object, unwrap the std::initializer_list too.
3071 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003072 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003073
Richard Smithd59b8322012-12-19 01:39:02 +00003074 SmallVector<Expr*, 8> NewArgs;
3075 bool ArgChanged = false;
3076 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003077 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003078 return ExprError();
3079
3080 // If this was list initialization, revert to list form.
3081 if (Construct->isListInitialization())
3082 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3083 Construct->getLocEnd(),
3084 Construct->getType());
3085
Richard Smithd59b8322012-12-19 01:39:02 +00003086 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003087 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003088 if (Parens.isInvalid()) {
3089 // This was a variable declaration's initialization for which no initializer
3090 // was specified.
3091 assert(NewArgs.empty() &&
3092 "no parens or braces but have direct init with arguments?");
3093 return ExprEmpty();
3094 }
Richard Smithd59b8322012-12-19 01:39:02 +00003095 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3096 Parens.getEnd());
3097}
3098
3099template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003100bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3101 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003102 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003103 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003104 bool *ArgChanged) {
3105 for (unsigned I = 0; I != NumInputs; ++I) {
3106 // If requested, drop call arguments that need to be dropped.
3107 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3108 if (ArgChanged)
3109 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003110
Douglas Gregora3efea12011-01-03 19:04:46 +00003111 break;
3112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003113
Douglas Gregor968f23a2011-01-03 19:31:53 +00003114 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3115 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Chris Lattner01cf8db2011-07-20 06:58:45 +00003117 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003118 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3119 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003120
Douglas Gregor968f23a2011-01-03 19:31:53 +00003121 // Determine whether the set of unexpanded parameter packs can and should
3122 // be expanded.
3123 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003124 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003125 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3126 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003127 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3128 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003129 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003130 Expand, RetainExpansion,
3131 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003132 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003133
Douglas Gregor968f23a2011-01-03 19:31:53 +00003134 if (!Expand) {
3135 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003136 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003137 // expansion.
3138 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3139 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3140 if (OutPattern.isInvalid())
3141 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003142
3143 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003144 Expansion->getEllipsisLoc(),
3145 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003146 if (Out.isInvalid())
3147 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003148
Douglas Gregor968f23a2011-01-03 19:31:53 +00003149 if (ArgChanged)
3150 *ArgChanged = true;
3151 Outputs.push_back(Out.get());
3152 continue;
3153 }
John McCall542e7c62011-07-06 07:30:07 +00003154
3155 // Record right away that the argument was changed. This needs
3156 // to happen even if the array expands to nothing.
3157 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003158
Douglas Gregor968f23a2011-01-03 19:31:53 +00003159 // The transform has determined that we should perform an elementwise
3160 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003161 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003162 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3163 ExprResult Out = getDerived().TransformExpr(Pattern);
3164 if (Out.isInvalid())
3165 return true;
3166
Richard Smith9467be42014-06-06 17:33:35 +00003167 // FIXME: Can this happen? We should not try to expand the pack
3168 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003169 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003170 Out = getDerived().RebuildPackExpansion(
3171 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003172 if (Out.isInvalid())
3173 return true;
3174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor968f23a2011-01-03 19:31:53 +00003176 Outputs.push_back(Out.get());
3177 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003178
Richard Smith9467be42014-06-06 17:33:35 +00003179 // If we're supposed to retain a pack expansion, do so by temporarily
3180 // forgetting the partially-substituted parameter pack.
3181 if (RetainExpansion) {
3182 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3183
3184 ExprResult Out = getDerived().TransformExpr(Pattern);
3185 if (Out.isInvalid())
3186 return true;
3187
3188 Out = getDerived().RebuildPackExpansion(
3189 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3190 if (Out.isInvalid())
3191 return true;
3192
3193 Outputs.push_back(Out.get());
3194 }
3195
Douglas Gregor968f23a2011-01-03 19:31:53 +00003196 continue;
3197 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003198
Richard Smithd59b8322012-12-19 01:39:02 +00003199 ExprResult Result =
3200 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3201 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003202 if (Result.isInvalid())
3203 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Douglas Gregora3efea12011-01-03 19:04:46 +00003205 if (Result.get() != Inputs[I] && ArgChanged)
3206 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003207
3208 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003209 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003210
Douglas Gregora3efea12011-01-03 19:04:46 +00003211 return false;
3212}
3213
3214template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003215NestedNameSpecifierLoc
3216TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3217 NestedNameSpecifierLoc NNS,
3218 QualType ObjectType,
3219 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003220 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003221 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003222 Qualifier = Qualifier.getPrefix())
3223 Qualifiers.push_back(Qualifier);
3224
3225 CXXScopeSpec SS;
3226 while (!Qualifiers.empty()) {
3227 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3228 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor14454802011-02-25 02:25:35 +00003230 switch (QNNS->getKind()) {
3231 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003232 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003233 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003234 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003235 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003236 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003237 FirstQualifierInScope, false))
3238 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor14454802011-02-25 02:25:35 +00003240 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003241
Douglas Gregor14454802011-02-25 02:25:35 +00003242 case NestedNameSpecifier::Namespace: {
3243 NamespaceDecl *NS
3244 = cast_or_null<NamespaceDecl>(
3245 getDerived().TransformDecl(
3246 Q.getLocalBeginLoc(),
3247 QNNS->getAsNamespace()));
3248 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3249 break;
3250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003251
Douglas Gregor14454802011-02-25 02:25:35 +00003252 case NestedNameSpecifier::NamespaceAlias: {
3253 NamespaceAliasDecl *Alias
3254 = cast_or_null<NamespaceAliasDecl>(
3255 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3256 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003257 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003258 Q.getLocalEndLoc());
3259 break;
3260 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003261
Douglas Gregor14454802011-02-25 02:25:35 +00003262 case NestedNameSpecifier::Global:
3263 // There is no meaningful transformation that one could perform on the
3264 // global scope.
3265 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3266 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003267
Nikola Smiljanic67860242014-09-26 00:28:20 +00003268 case NestedNameSpecifier::Super: {
3269 CXXRecordDecl *RD =
3270 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3271 SourceLocation(), QNNS->getAsRecordDecl()));
3272 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3273 break;
3274 }
3275
Douglas Gregor14454802011-02-25 02:25:35 +00003276 case NestedNameSpecifier::TypeSpecWithTemplate:
3277 case NestedNameSpecifier::TypeSpec: {
3278 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3279 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003280
Douglas Gregor14454802011-02-25 02:25:35 +00003281 if (!TL)
3282 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003283
Douglas Gregor14454802011-02-25 02:25:35 +00003284 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003285 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003286 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003287 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003288 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003289 if (TL.getType()->isEnumeralType())
3290 SemaRef.Diag(TL.getBeginLoc(),
3291 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003292 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3293 Q.getLocalEndLoc());
3294 break;
3295 }
Richard Trieude756fb2011-05-07 01:36:37 +00003296 // If the nested-name-specifier is an invalid type def, don't emit an
3297 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003298 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3299 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003300 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003301 << TL.getType() << SS.getRange();
3302 }
Douglas Gregor14454802011-02-25 02:25:35 +00003303 return NestedNameSpecifierLoc();
3304 }
Douglas Gregore16af532011-02-28 18:50:33 +00003305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003306
Douglas Gregore16af532011-02-28 18:50:33 +00003307 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003308 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003309 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003310 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Douglas Gregor14454802011-02-25 02:25:35 +00003312 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003313 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003314 !getDerived().AlwaysRebuild())
3315 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003316
3317 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003318 // nested-name-specifier, do so.
3319 if (SS.location_size() == NNS.getDataLength() &&
3320 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3321 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3322
3323 // Allocate new nested-name-specifier location information.
3324 return SS.getWithLocInContext(SemaRef.Context);
3325}
3326
3327template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003328DeclarationNameInfo
3329TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003330::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003331 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003332 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003333 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003334
3335 switch (Name.getNameKind()) {
3336 case DeclarationName::Identifier:
3337 case DeclarationName::ObjCZeroArgSelector:
3338 case DeclarationName::ObjCOneArgSelector:
3339 case DeclarationName::ObjCMultiArgSelector:
3340 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003341 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003342 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003343 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003344
Douglas Gregorf816bd72009-09-03 22:13:48 +00003345 case DeclarationName::CXXConstructorName:
3346 case DeclarationName::CXXDestructorName:
3347 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003348 TypeSourceInfo *NewTInfo;
3349 CanQualType NewCanTy;
3350 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003351 NewTInfo = getDerived().TransformType(OldTInfo);
3352 if (!NewTInfo)
3353 return DeclarationNameInfo();
3354 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003355 }
3356 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003357 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003358 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003359 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003360 if (NewT.isNull())
3361 return DeclarationNameInfo();
3362 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3363 }
Mike Stump11289f42009-09-09 15:08:12 +00003364
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003365 DeclarationName NewName
3366 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3367 NewCanTy);
3368 DeclarationNameInfo NewNameInfo(NameInfo);
3369 NewNameInfo.setName(NewName);
3370 NewNameInfo.setNamedTypeInfo(NewTInfo);
3371 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003372 }
Mike Stump11289f42009-09-09 15:08:12 +00003373 }
3374
David Blaikie83d382b2011-09-23 05:06:16 +00003375 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003376}
3377
3378template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003379TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003380TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3381 TemplateName Name,
3382 SourceLocation NameLoc,
3383 QualType ObjectType,
3384 NamedDecl *FirstQualifierInScope) {
3385 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3386 TemplateDecl *Template = QTN->getTemplateDecl();
3387 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003388
Douglas Gregor9db53502011-03-02 18:07:45 +00003389 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003390 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003391 Template));
3392 if (!TransTemplate)
3393 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003394
Douglas Gregor9db53502011-03-02 18:07:45 +00003395 if (!getDerived().AlwaysRebuild() &&
3396 SS.getScopeRep() == QTN->getQualifier() &&
3397 TransTemplate == Template)
3398 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregor9db53502011-03-02 18:07:45 +00003400 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3401 TransTemplate);
3402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregor9db53502011-03-02 18:07:45 +00003404 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3405 if (SS.getScopeRep()) {
3406 // These apply to the scope specifier, not the template.
3407 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003408 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003409 }
3410
Douglas Gregor9db53502011-03-02 18:07:45 +00003411 if (!getDerived().AlwaysRebuild() &&
3412 SS.getScopeRep() == DTN->getQualifier() &&
3413 ObjectType.isNull())
3414 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregor9db53502011-03-02 18:07:45 +00003416 if (DTN->isIdentifier()) {
3417 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003418 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003419 NameLoc,
3420 ObjectType,
3421 FirstQualifierInScope);
3422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003423
Douglas Gregor9db53502011-03-02 18:07:45 +00003424 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3425 ObjectType);
3426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor9db53502011-03-02 18:07:45 +00003428 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3429 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003430 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003431 Template));
3432 if (!TransTemplate)
3433 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003434
Douglas Gregor9db53502011-03-02 18:07:45 +00003435 if (!getDerived().AlwaysRebuild() &&
3436 TransTemplate == Template)
3437 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor9db53502011-03-02 18:07:45 +00003439 return TemplateName(TransTemplate);
3440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003441
Douglas Gregor9db53502011-03-02 18:07:45 +00003442 if (SubstTemplateTemplateParmPackStorage *SubstPack
3443 = Name.getAsSubstTemplateTemplateParmPack()) {
3444 TemplateTemplateParmDecl *TransParam
3445 = cast_or_null<TemplateTemplateParmDecl>(
3446 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3447 if (!TransParam)
3448 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003449
Douglas Gregor9db53502011-03-02 18:07:45 +00003450 if (!getDerived().AlwaysRebuild() &&
3451 TransParam == SubstPack->getParameterPack())
3452 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
3454 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003455 SubstPack->getArgumentPack());
3456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor9db53502011-03-02 18:07:45 +00003458 // These should be getting filtered out before they reach the AST.
3459 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003460}
3461
3462template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003463void TreeTransform<Derived>::InventTemplateArgumentLoc(
3464 const TemplateArgument &Arg,
3465 TemplateArgumentLoc &Output) {
3466 SourceLocation Loc = getDerived().getBaseLocation();
3467 switch (Arg.getKind()) {
3468 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003469 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003470 break;
3471
3472 case TemplateArgument::Type:
3473 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003474 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003475
John McCall0ad16662009-10-29 08:12:44 +00003476 break;
3477
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003478 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003479 case TemplateArgument::TemplateExpansion: {
3480 NestedNameSpecifierLocBuilder Builder;
3481 TemplateName Template = Arg.getAsTemplate();
3482 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3483 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3484 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3485 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003486
Douglas Gregor9d802122011-03-02 17:09:35 +00003487 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003488 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003489 Builder.getWithLocInContext(SemaRef.Context),
3490 Loc);
3491 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003492 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003493 Builder.getWithLocInContext(SemaRef.Context),
3494 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003495
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003496 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003497 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003498
John McCall0ad16662009-10-29 08:12:44 +00003499 case TemplateArgument::Expression:
3500 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3501 break;
3502
3503 case TemplateArgument::Declaration:
3504 case TemplateArgument::Integral:
3505 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003506 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003507 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003508 break;
3509 }
3510}
3511
3512template<typename Derived>
3513bool TreeTransform<Derived>::TransformTemplateArgument(
3514 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003515 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003516 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003517 switch (Arg.getKind()) {
3518 case TemplateArgument::Null:
3519 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003520 case TemplateArgument::Pack:
3521 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003522 case TemplateArgument::NullPtr:
3523 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregore922c772009-08-04 22:27:00 +00003525 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003526 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003527 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003528 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003529
3530 DI = getDerived().TransformType(DI);
3531 if (!DI) return true;
3532
3533 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3534 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003535 }
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003537 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003538 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3539 if (QualifierLoc) {
3540 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3541 if (!QualifierLoc)
3542 return true;
3543 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003544
Douglas Gregordf846d12011-03-02 18:46:51 +00003545 CXXScopeSpec SS;
3546 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003547 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003548 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3549 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003550 if (Template.isNull())
3551 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003552
Douglas Gregor9d802122011-03-02 17:09:35 +00003553 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003554 Input.getTemplateNameLoc());
3555 return false;
3556 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003557
3558 case TemplateArgument::TemplateExpansion:
3559 llvm_unreachable("Caller should expand pack expansions");
3560
Douglas Gregore922c772009-08-04 22:27:00 +00003561 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003562 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003563 EnterExpressionEvaluationContext Unevaluated(
3564 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003565
John McCall0ad16662009-10-29 08:12:44 +00003566 Expr *InputExpr = Input.getSourceExpression();
3567 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3568
Chris Lattnercdb591a2011-04-25 20:37:58 +00003569 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003570 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003571 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003572 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003573 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003574 }
Douglas Gregore922c772009-08-04 22:27:00 +00003575 }
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregore922c772009-08-04 22:27:00 +00003577 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003578 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003579}
3580
Douglas Gregorfe921a72010-12-20 23:36:19 +00003581/// \brief Iterator adaptor that invents template argument location information
3582/// for each of the template arguments in its underlying iterator.
3583template<typename Derived, typename InputIterator>
3584class TemplateArgumentLocInventIterator {
3585 TreeTransform<Derived> &Self;
3586 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregorfe921a72010-12-20 23:36:19 +00003588public:
3589 typedef TemplateArgumentLoc value_type;
3590 typedef TemplateArgumentLoc reference;
3591 typedef typename std::iterator_traits<InputIterator>::difference_type
3592 difference_type;
3593 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregorfe921a72010-12-20 23:36:19 +00003595 class pointer {
3596 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
Douglas Gregorfe921a72010-12-20 23:36:19 +00003598 public:
3599 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregorfe921a72010-12-20 23:36:19 +00003601 const TemplateArgumentLoc *operator->() const { return &Arg; }
3602 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003604 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregorfe921a72010-12-20 23:36:19 +00003606 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3607 InputIterator Iter)
3608 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregorfe921a72010-12-20 23:36:19 +00003610 TemplateArgumentLocInventIterator &operator++() {
3611 ++Iter;
3612 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003613 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003614
Douglas Gregorfe921a72010-12-20 23:36:19 +00003615 TemplateArgumentLocInventIterator operator++(int) {
3616 TemplateArgumentLocInventIterator Old(*this);
3617 ++(*this);
3618 return Old;
3619 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003620
Douglas Gregorfe921a72010-12-20 23:36:19 +00003621 reference operator*() const {
3622 TemplateArgumentLoc Result;
3623 Self.InventTemplateArgumentLoc(*Iter, Result);
3624 return Result;
3625 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregorfe921a72010-12-20 23:36:19 +00003627 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003628
Douglas Gregorfe921a72010-12-20 23:36:19 +00003629 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3630 const TemplateArgumentLocInventIterator &Y) {
3631 return X.Iter == Y.Iter;
3632 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003633
Douglas Gregorfe921a72010-12-20 23:36:19 +00003634 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3635 const TemplateArgumentLocInventIterator &Y) {
3636 return X.Iter != Y.Iter;
3637 }
3638};
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor42cafa82010-12-20 17:42:22 +00003640template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003641template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003642bool TreeTransform<Derived>::TransformTemplateArguments(
3643 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3644 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003645 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003646 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003647 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003648
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003649 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3650 // Unpack argument packs, which we translate them into separate
3651 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003652 // FIXME: We could do much better if we could guarantee that the
3653 // TemplateArgumentLocInfo for the pack expansion would be usable for
3654 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003655 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003656 TemplateArgument::pack_iterator>
3657 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003658 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003659 In.getArgument().pack_begin()),
3660 PackLocIterator(*this,
3661 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003662 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003663 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003664
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003665 continue;
3666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003668 if (In.getArgument().isPackExpansion()) {
3669 // We have a pack expansion, for which we will be substituting into
3670 // the pattern.
3671 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003672 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003673 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003674 = getSema().getTemplateArgumentPackExpansionPattern(
3675 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
Chris Lattner01cf8db2011-07-20 06:58:45 +00003677 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003678 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3679 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003680
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003681 // Determine whether the set of unexpanded parameter packs can and should
3682 // be expanded.
3683 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003684 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003685 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003686 if (getDerived().TryExpandParameterPacks(Ellipsis,
3687 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003688 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003689 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003690 RetainExpansion,
3691 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003693
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003694 if (!Expand) {
3695 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003696 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003697 // expansion.
3698 TemplateArgumentLoc OutPattern;
3699 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003700 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003701 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003703 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3704 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003705 if (Out.getArgument().isNull())
3706 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003707
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003708 Outputs.addArgument(Out);
3709 continue;
3710 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003712 // The transform has determined that we should perform an elementwise
3713 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003714 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003715 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3716
Richard Smithd784e682015-09-23 21:41:42 +00003717 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003718 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003719
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003720 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003721 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3722 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003723 if (Out.getArgument().isNull())
3724 return true;
3725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003726
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003727 Outputs.addArgument(Out);
3728 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003729
Douglas Gregor48d24112011-01-10 20:53:55 +00003730 // If we're supposed to retain a pack expansion, do so by temporarily
3731 // forgetting the partially-substituted parameter pack.
3732 if (RetainExpansion) {
3733 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003734
Richard Smithd784e682015-09-23 21:41:42 +00003735 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003736 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003737
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003738 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3739 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003740 if (Out.getArgument().isNull())
3741 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003742
Douglas Gregor48d24112011-01-10 20:53:55 +00003743 Outputs.addArgument(Out);
3744 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003745
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003746 continue;
3747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
3749 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003750 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003751 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor42cafa82010-12-20 17:42:22 +00003753 Outputs.addArgument(Out);
3754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregor42cafa82010-12-20 17:42:22 +00003756 return false;
3757
3758}
3759
Douglas Gregord6ff3322009-08-04 16:50:30 +00003760//===----------------------------------------------------------------------===//
3761// Type transformation
3762//===----------------------------------------------------------------------===//
3763
3764template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003765QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003766 if (getDerived().AlreadyTransformed(T))
3767 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003768
John McCall550e0c22009-10-21 00:40:46 +00003769 // Temporary workaround. All of these transformations should
3770 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003771 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3772 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003773
John McCall31f82722010-11-12 08:19:04 +00003774 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003775
John McCall550e0c22009-10-21 00:40:46 +00003776 if (!NewDI)
3777 return QualType();
3778
3779 return NewDI->getType();
3780}
3781
3782template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003783TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003784 // Refine the base location to the type's location.
3785 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3786 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003787 if (getDerived().AlreadyTransformed(DI->getType()))
3788 return DI;
3789
3790 TypeLocBuilder TLB;
3791
3792 TypeLoc TL = DI->getTypeLoc();
3793 TLB.reserve(TL.getFullDataSize());
3794
John McCall31f82722010-11-12 08:19:04 +00003795 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003796 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003797 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003798
John McCallbcd03502009-12-07 02:54:59 +00003799 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003800}
3801
3802template<typename Derived>
3803QualType
John McCall31f82722010-11-12 08:19:04 +00003804TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003805 switch (T.getTypeLocClass()) {
3806#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003807#define TYPELOC(CLASS, PARENT) \
3808 case TypeLoc::CLASS: \
3809 return getDerived().Transform##CLASS##Type(TLB, \
3810 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003811#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812 }
Mike Stump11289f42009-09-09 15:08:12 +00003813
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003814 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003815}
3816
3817/// FIXME: By default, this routine adds type qualifiers only to types
3818/// that can have qualifiers, and silently suppresses those qualifiers
3819/// that are not permitted (e.g., qualifiers on reference or function
3820/// types). This is the right thing for template instantiation, but
3821/// probably not for other clients.
3822template<typename Derived>
3823QualType
3824TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003825 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003826 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003827
John McCall31f82722010-11-12 08:19:04 +00003828 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003829 if (Result.isNull())
3830 return QualType();
3831
3832 // Silently suppress qualifiers if the result type can't be qualified.
3833 // FIXME: this is the right thing for template instantiation, but
3834 // probably not for other clients.
3835 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003836 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003837
John McCall31168b02011-06-15 23:02:42 +00003838 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003839 // resulting type.
3840 if (Quals.hasObjCLifetime()) {
3841 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3842 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003843 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003844 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003845 // A lifetime qualifier applied to a substituted template parameter
3846 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003847 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003848 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003849 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3850 QualType Replacement = SubstTypeParam->getReplacementType();
3851 Qualifiers Qs = Replacement.getQualifiers();
3852 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003853 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003854 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3855 Qs);
3856 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003857 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003858 Replacement);
3859 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003860 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3861 // 'auto' types behave the same way as template parameters.
3862 QualType Deduced = AutoTy->getDeducedType();
3863 Qualifiers Qs = Deduced.getQualifiers();
3864 Qs.removeObjCLifetime();
3865 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3866 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003867 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3868 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003869 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003870 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003871 // Otherwise, complain about the addition of a qualifier to an
3872 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003873 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003874 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003875 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
Douglas Gregore46db902011-06-17 22:11:49 +00003877 Quals.removeObjCLifetime();
3878 }
3879 }
3880 }
John McCallcb0f89a2010-06-05 06:41:15 +00003881 if (!Quals.empty()) {
3882 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003883 // BuildQualifiedType might not add qualifiers if they are invalid.
3884 if (Result.hasLocalQualifiers())
3885 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003886 // No location information to preserve.
3887 }
John McCall550e0c22009-10-21 00:40:46 +00003888
3889 return Result;
3890}
3891
Douglas Gregor14454802011-02-25 02:25:35 +00003892template<typename Derived>
3893TypeLoc
3894TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3895 QualType ObjectType,
3896 NamedDecl *UnqualLookup,
3897 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003898 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003899 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003900
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003901 TypeSourceInfo *TSI =
3902 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3903 if (TSI)
3904 return TSI->getTypeLoc();
3905 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003906}
3907
Douglas Gregor579c15f2011-03-02 18:32:08 +00003908template<typename Derived>
3909TypeSourceInfo *
3910TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3911 QualType ObjectType,
3912 NamedDecl *UnqualLookup,
3913 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003914 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003915 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003916
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003917 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3918 UnqualLookup, SS);
3919}
3920
3921template <typename Derived>
3922TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3923 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3924 CXXScopeSpec &SS) {
3925 QualType T = TL.getType();
3926 assert(!getDerived().AlreadyTransformed(T));
3927
Douglas Gregor579c15f2011-03-02 18:32:08 +00003928 TypeLocBuilder TLB;
3929 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
Douglas Gregor579c15f2011-03-02 18:32:08 +00003931 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003932 TemplateSpecializationTypeLoc SpecTL =
3933 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003934
Douglas Gregor579c15f2011-03-02 18:32:08 +00003935 TemplateName Template
3936 = getDerived().TransformTemplateName(SS,
3937 SpecTL.getTypePtr()->getTemplateName(),
3938 SpecTL.getTemplateNameLoc(),
3939 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003940 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003941 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003942
3943 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003944 Template);
3945 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003946 DependentTemplateSpecializationTypeLoc SpecTL =
3947 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregor579c15f2011-03-02 18:32:08 +00003949 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003950 = getDerived().RebuildTemplateName(SS,
3951 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003952 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003953 ObjectType, UnqualLookup);
3954 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003955 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003956
3957 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003958 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003959 Template,
3960 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003961 } else {
3962 // Nothing special needs to be done for these.
3963 Result = getDerived().TransformType(TLB, TL);
3964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003965
3966 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003967 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003968
Douglas Gregor579c15f2011-03-02 18:32:08 +00003969 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3970}
3971
John McCall550e0c22009-10-21 00:40:46 +00003972template <class TyLoc> static inline
3973QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3974 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3975 NewT.setNameLoc(T.getNameLoc());
3976 return T.getType();
3977}
3978
John McCall550e0c22009-10-21 00:40:46 +00003979template<typename Derived>
3980QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003981 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003982 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3983 NewT.setBuiltinLoc(T.getBuiltinLoc());
3984 if (T.needsExtraLocalData())
3985 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3986 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987}
Mike Stump11289f42009-09-09 15:08:12 +00003988
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003990QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003991 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003992 // FIXME: recurse?
3993 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994}
Mike Stump11289f42009-09-09 15:08:12 +00003995
Reid Kleckner0503a872013-12-05 01:23:43 +00003996template <typename Derived>
3997QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3998 AdjustedTypeLoc TL) {
3999 // Adjustments applied during transformation are handled elsewhere.
4000 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4001}
4002
Douglas Gregord6ff3322009-08-04 16:50:30 +00004003template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004004QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4005 DecayedTypeLoc TL) {
4006 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4007 if (OriginalType.isNull())
4008 return QualType();
4009
4010 QualType Result = TL.getType();
4011 if (getDerived().AlwaysRebuild() ||
4012 OriginalType != TL.getOriginalLoc().getType())
4013 Result = SemaRef.Context.getDecayedType(OriginalType);
4014 TLB.push<DecayedTypeLoc>(Result);
4015 // Nothing to set for DecayedTypeLoc.
4016 return Result;
4017}
4018
4019template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004020QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004021 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004022 QualType PointeeType
4023 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004024 if (PointeeType.isNull())
4025 return QualType();
4026
4027 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004028 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004029 // A dependent pointer type 'T *' has is being transformed such
4030 // that an Objective-C class type is being replaced for 'T'. The
4031 // resulting pointer type is an ObjCObjectPointerType, not a
4032 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004033 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004034
John McCall8b07ec22010-05-15 11:32:37 +00004035 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4036 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004037 return Result;
4038 }
John McCall31f82722010-11-12 08:19:04 +00004039
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004040 if (getDerived().AlwaysRebuild() ||
4041 PointeeType != TL.getPointeeLoc().getType()) {
4042 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4043 if (Result.isNull())
4044 return QualType();
4045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
John McCall31168b02011-06-15 23:02:42 +00004047 // Objective-C ARC can add lifetime qualifiers to the type that we're
4048 // pointing to.
4049 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004050
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004051 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4052 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004053 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054}
Mike Stump11289f42009-09-09 15:08:12 +00004055
4056template<typename Derived>
4057QualType
John McCall550e0c22009-10-21 00:40:46 +00004058TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004059 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004060 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004061 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4062 if (PointeeType.isNull())
4063 return QualType();
4064
4065 QualType Result = TL.getType();
4066 if (getDerived().AlwaysRebuild() ||
4067 PointeeType != TL.getPointeeLoc().getType()) {
4068 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004069 TL.getSigilLoc());
4070 if (Result.isNull())
4071 return QualType();
4072 }
4073
Douglas Gregor049211a2010-04-22 16:50:51 +00004074 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004075 NewT.setSigilLoc(TL.getSigilLoc());
4076 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004077}
4078
John McCall70dd5f62009-10-30 00:06:24 +00004079/// Transforms a reference type. Note that somewhat paradoxically we
4080/// don't care whether the type itself is an l-value type or an r-value
4081/// type; we only care if the type was *written* as an l-value type
4082/// or an r-value type.
4083template<typename Derived>
4084QualType
4085TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004086 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004087 const ReferenceType *T = TL.getTypePtr();
4088
4089 // Note that this works with the pointee-as-written.
4090 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4091 if (PointeeType.isNull())
4092 return QualType();
4093
4094 QualType Result = TL.getType();
4095 if (getDerived().AlwaysRebuild() ||
4096 PointeeType != T->getPointeeTypeAsWritten()) {
4097 Result = getDerived().RebuildReferenceType(PointeeType,
4098 T->isSpelledAsLValue(),
4099 TL.getSigilLoc());
4100 if (Result.isNull())
4101 return QualType();
4102 }
4103
John McCall31168b02011-06-15 23:02:42 +00004104 // Objective-C ARC can add lifetime qualifiers to the type that we're
4105 // referring to.
4106 TLB.TypeWasModifiedSafely(
4107 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4108
John McCall70dd5f62009-10-30 00:06:24 +00004109 // r-value references can be rebuilt as l-value references.
4110 ReferenceTypeLoc NewTL;
4111 if (isa<LValueReferenceType>(Result))
4112 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4113 else
4114 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4115 NewTL.setSigilLoc(TL.getSigilLoc());
4116
4117 return Result;
4118}
4119
Mike Stump11289f42009-09-09 15:08:12 +00004120template<typename Derived>
4121QualType
John McCall550e0c22009-10-21 00:40:46 +00004122TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004123 LValueReferenceTypeLoc TL) {
4124 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125}
4126
Mike Stump11289f42009-09-09 15:08:12 +00004127template<typename Derived>
4128QualType
John McCall550e0c22009-10-21 00:40:46 +00004129TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004130 RValueReferenceTypeLoc TL) {
4131 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregord6ff3322009-08-04 16:50:30 +00004134template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004135QualType
John McCall550e0c22009-10-21 00:40:46 +00004136TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004137 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004138 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139 if (PointeeType.isNull())
4140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004141
Abramo Bagnara509357842011-03-05 14:42:21 +00004142 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004143 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004144 if (OldClsTInfo) {
4145 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4146 if (!NewClsTInfo)
4147 return QualType();
4148 }
4149
4150 const MemberPointerType *T = TL.getTypePtr();
4151 QualType OldClsType = QualType(T->getClass(), 0);
4152 QualType NewClsType;
4153 if (NewClsTInfo)
4154 NewClsType = NewClsTInfo->getType();
4155 else {
4156 NewClsType = getDerived().TransformType(OldClsType);
4157 if (NewClsType.isNull())
4158 return QualType();
4159 }
Mike Stump11289f42009-09-09 15:08:12 +00004160
John McCall550e0c22009-10-21 00:40:46 +00004161 QualType Result = TL.getType();
4162 if (getDerived().AlwaysRebuild() ||
4163 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004164 NewClsType != OldClsType) {
4165 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004166 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004167 if (Result.isNull())
4168 return QualType();
4169 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004170
Reid Kleckner0503a872013-12-05 01:23:43 +00004171 // If we had to adjust the pointee type when building a member pointer, make
4172 // sure to push TypeLoc info for it.
4173 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4174 if (MPT && PointeeType != MPT->getPointeeType()) {
4175 assert(isa<AdjustedType>(MPT->getPointeeType()));
4176 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4177 }
4178
John McCall550e0c22009-10-21 00:40:46 +00004179 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4180 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004181 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004182
4183 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004184}
4185
Mike Stump11289f42009-09-09 15:08:12 +00004186template<typename Derived>
4187QualType
John McCall550e0c22009-10-21 00:40:46 +00004188TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004189 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004190 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004191 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004192 if (ElementType.isNull())
4193 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004194
John McCall550e0c22009-10-21 00:40:46 +00004195 QualType Result = TL.getType();
4196 if (getDerived().AlwaysRebuild() ||
4197 ElementType != T->getElementType()) {
4198 Result = getDerived().RebuildConstantArrayType(ElementType,
4199 T->getSizeModifier(),
4200 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004201 T->getIndexTypeCVRQualifiers(),
4202 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004203 if (Result.isNull())
4204 return QualType();
4205 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004206
4207 // We might have either a ConstantArrayType or a VariableArrayType now:
4208 // a ConstantArrayType is allowed to have an element type which is a
4209 // VariableArrayType if the type is dependent. Fortunately, all array
4210 // types have the same location layout.
4211 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004212 NewTL.setLBracketLoc(TL.getLBracketLoc());
4213 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 Expr *Size = TL.getSizeExpr();
4216 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004217 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4218 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004219 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4220 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004221 }
4222 NewTL.setSizeExpr(Size);
4223
4224 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004225}
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregord6ff3322009-08-04 16:50:30 +00004227template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004229 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004230 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004231 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004232 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233 if (ElementType.isNull())
4234 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004235
John McCall550e0c22009-10-21 00:40:46 +00004236 QualType Result = TL.getType();
4237 if (getDerived().AlwaysRebuild() ||
4238 ElementType != T->getElementType()) {
4239 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004240 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004241 T->getIndexTypeCVRQualifiers(),
4242 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004243 if (Result.isNull())
4244 return QualType();
4245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004246
John McCall550e0c22009-10-21 00:40:46 +00004247 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4248 NewTL.setLBracketLoc(TL.getLBracketLoc());
4249 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004250 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004251
4252 return Result;
4253}
4254
4255template<typename Derived>
4256QualType
4257TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004258 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004259 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004260 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4261 if (ElementType.isNull())
4262 return QualType();
4263
John McCalldadc5752010-08-24 06:29:42 +00004264 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004265 = getDerived().TransformExpr(T->getSizeExpr());
4266 if (SizeResult.isInvalid())
4267 return QualType();
4268
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004269 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004270
4271 QualType Result = TL.getType();
4272 if (getDerived().AlwaysRebuild() ||
4273 ElementType != T->getElementType() ||
4274 Size != T->getSizeExpr()) {
4275 Result = getDerived().RebuildVariableArrayType(ElementType,
4276 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004277 Size,
John McCall550e0c22009-10-21 00:40:46 +00004278 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004279 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004280 if (Result.isNull())
4281 return QualType();
4282 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004283
Serge Pavlov774c6d02014-02-06 03:49:11 +00004284 // We might have constant size array now, but fortunately it has the same
4285 // location layout.
4286 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004287 NewTL.setLBracketLoc(TL.getLBracketLoc());
4288 NewTL.setRBracketLoc(TL.getRBracketLoc());
4289 NewTL.setSizeExpr(Size);
4290
4291 return Result;
4292}
4293
4294template<typename Derived>
4295QualType
4296TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004297 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004298 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004299 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4300 if (ElementType.isNull())
4301 return QualType();
4302
Richard Smith764d2fe2011-12-20 02:08:33 +00004303 // Array bounds are constant expressions.
4304 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4305 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004306
John McCall33ddac02011-01-19 10:06:00 +00004307 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4308 Expr *origSize = TL.getSizeExpr();
4309 if (!origSize) origSize = T->getSizeExpr();
4310
4311 ExprResult sizeResult
4312 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004313 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004314 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004315 return QualType();
4316
John McCall33ddac02011-01-19 10:06:00 +00004317 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004318
4319 QualType Result = TL.getType();
4320 if (getDerived().AlwaysRebuild() ||
4321 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004322 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004323 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4324 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004325 size,
John McCall550e0c22009-10-21 00:40:46 +00004326 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004327 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004328 if (Result.isNull())
4329 return QualType();
4330 }
John McCall550e0c22009-10-21 00:40:46 +00004331
4332 // We might have any sort of array type now, but fortunately they
4333 // all have the same location layout.
4334 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4335 NewTL.setLBracketLoc(TL.getLBracketLoc());
4336 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004337 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004338
4339 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004340}
Mike Stump11289f42009-09-09 15:08:12 +00004341
4342template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004343QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004344 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004345 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004346 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004347
4348 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004349 QualType ElementType = getDerived().TransformType(T->getElementType());
4350 if (ElementType.isNull())
4351 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004352
Richard Smith764d2fe2011-12-20 02:08:33 +00004353 // Vector sizes are constant expressions.
4354 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4355 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004356
John McCalldadc5752010-08-24 06:29:42 +00004357 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004358 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004359 if (Size.isInvalid())
4360 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004361
John McCall550e0c22009-10-21 00:40:46 +00004362 QualType Result = TL.getType();
4363 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004364 ElementType != T->getElementType() ||
4365 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004366 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004367 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004368 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004369 if (Result.isNull())
4370 return QualType();
4371 }
John McCall550e0c22009-10-21 00:40:46 +00004372
4373 // Result might be dependent or not.
4374 if (isa<DependentSizedExtVectorType>(Result)) {
4375 DependentSizedExtVectorTypeLoc NewTL
4376 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4377 NewTL.setNameLoc(TL.getNameLoc());
4378 } else {
4379 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4380 NewTL.setNameLoc(TL.getNameLoc());
4381 }
4382
4383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004384}
Mike Stump11289f42009-09-09 15:08:12 +00004385
4386template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004387QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004388 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004389 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004390 QualType ElementType = getDerived().TransformType(T->getElementType());
4391 if (ElementType.isNull())
4392 return QualType();
4393
John McCall550e0c22009-10-21 00:40:46 +00004394 QualType Result = TL.getType();
4395 if (getDerived().AlwaysRebuild() ||
4396 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004397 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004398 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004399 if (Result.isNull())
4400 return QualType();
4401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004402
John McCall550e0c22009-10-21 00:40:46 +00004403 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4404 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004405
John McCall550e0c22009-10-21 00:40:46 +00004406 return Result;
4407}
4408
4409template<typename Derived>
4410QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004411 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004412 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004413 QualType ElementType = getDerived().TransformType(T->getElementType());
4414 if (ElementType.isNull())
4415 return QualType();
4416
4417 QualType Result = TL.getType();
4418 if (getDerived().AlwaysRebuild() ||
4419 ElementType != T->getElementType()) {
4420 Result = getDerived().RebuildExtVectorType(ElementType,
4421 T->getNumElements(),
4422 /*FIXME*/ SourceLocation());
4423 if (Result.isNull())
4424 return QualType();
4425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
John McCall550e0c22009-10-21 00:40:46 +00004427 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4428 NewTL.setNameLoc(TL.getNameLoc());
4429
4430 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004431}
Mike Stump11289f42009-09-09 15:08:12 +00004432
David Blaikie05785d12013-02-20 22:23:23 +00004433template <typename Derived>
4434ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4435 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4436 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004437 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004438 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
Douglas Gregor715e4612011-01-14 22:40:04 +00004440 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004441 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004442 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004443 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004444 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004445
Douglas Gregor715e4612011-01-14 22:40:04 +00004446 TypeLocBuilder TLB;
4447 TypeLoc NewTL = OldDI->getTypeLoc();
4448 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004449
4450 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004451 OldExpansionTL.getPatternLoc());
4452 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004453 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
4455 Result = RebuildPackExpansionType(Result,
4456 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004457 OldExpansionTL.getEllipsisLoc(),
4458 NumExpansions);
4459 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004460 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004461
Douglas Gregor715e4612011-01-14 22:40:04 +00004462 PackExpansionTypeLoc NewExpansionTL
4463 = TLB.push<PackExpansionTypeLoc>(Result);
4464 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4465 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4466 } else
4467 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004468 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004469 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004470
John McCall8fb0d9d2011-05-01 22:35:37 +00004471 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004472 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004473
4474 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4475 OldParm->getDeclContext(),
4476 OldParm->getInnerLocStart(),
4477 OldParm->getLocation(),
4478 OldParm->getIdentifier(),
4479 NewDI->getType(),
4480 NewDI,
4481 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004482 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004483 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4484 OldParm->getFunctionScopeIndex() + indexAdjustment);
4485 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004486}
4487
4488template<typename Derived>
4489bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004490 TransformFunctionTypeParams(SourceLocation Loc,
4491 ParmVarDecl **Params, unsigned NumParams,
4492 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004493 SmallVectorImpl<QualType> &OutParamTypes,
4494 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004495 int indexAdjustment = 0;
4496
Douglas Gregordd472162011-01-07 00:20:55 +00004497 for (unsigned i = 0; i != NumParams; ++i) {
4498 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004499 assert(OldParm->getFunctionScopeIndex() == i);
4500
David Blaikie05785d12013-02-20 22:23:23 +00004501 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004502 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004503 if (OldParm->isParameterPack()) {
4504 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004505 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004506
Douglas Gregor5499af42011-01-05 23:12:31 +00004507 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004508 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004509 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004510 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4511 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004512 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4513
Douglas Gregor5499af42011-01-05 23:12:31 +00004514 // Determine whether we should expand the parameter packs.
4515 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004516 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004517 Optional<unsigned> OrigNumExpansions =
4518 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004519 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004520 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4521 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004522 Unexpanded,
4523 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004524 RetainExpansion,
4525 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004526 return true;
4527 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004528
Douglas Gregor5499af42011-01-05 23:12:31 +00004529 if (ShouldExpand) {
4530 // Expand the function parameter pack into multiple, separate
4531 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004532 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004533 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004535 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004536 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004537 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004538 OrigNumExpansions,
4539 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004540 if (!NewParm)
4541 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004542
Douglas Gregordd472162011-01-07 00:20:55 +00004543 OutParamTypes.push_back(NewParm->getType());
4544 if (PVars)
4545 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004546 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004547
4548 // If we're supposed to retain a pack expansion, do so by temporarily
4549 // forgetting the partially-substituted parameter pack.
4550 if (RetainExpansion) {
4551 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004552 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004553 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004554 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004555 OrigNumExpansions,
4556 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004557 if (!NewParm)
4558 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004559
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004560 OutParamTypes.push_back(NewParm->getType());
4561 if (PVars)
4562 PVars->push_back(NewParm);
4563 }
4564
John McCall8fb0d9d2011-05-01 22:35:37 +00004565 // The next parameter should have the same adjustment as the
4566 // last thing we pushed, but we post-incremented indexAdjustment
4567 // on every push. Also, if we push nothing, the adjustment should
4568 // go down by one.
4569 indexAdjustment--;
4570
Douglas Gregor5499af42011-01-05 23:12:31 +00004571 // We're done with the pack expansion.
4572 continue;
4573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004574
4575 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004576 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004577 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4578 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004579 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004580 NumExpansions,
4581 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004582 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004583 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004584 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004585 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004586
John McCall58f10c32010-03-11 09:03:00 +00004587 if (!NewParm)
4588 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004589
Douglas Gregordd472162011-01-07 00:20:55 +00004590 OutParamTypes.push_back(NewParm->getType());
4591 if (PVars)
4592 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004593 continue;
4594 }
John McCall58f10c32010-03-11 09:03:00 +00004595
4596 // Deal with the possibility that we don't have a parameter
4597 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004598 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004599 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004600 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004601 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004602 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004603 = dyn_cast<PackExpansionType>(OldType)) {
4604 // We have a function parameter pack that may need to be expanded.
4605 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004606 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004607 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004608
Douglas Gregor5499af42011-01-05 23:12:31 +00004609 // Determine whether we should expand the parameter packs.
4610 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004611 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004612 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004613 Unexpanded,
4614 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004615 RetainExpansion,
4616 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004617 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004619
Douglas Gregor5499af42011-01-05 23:12:31 +00004620 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004621 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004622 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004623 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4625 QualType NewType = getDerived().TransformType(Pattern);
4626 if (NewType.isNull())
4627 return true;
John McCall58f10c32010-03-11 09:03:00 +00004628
Douglas Gregordd472162011-01-07 00:20:55 +00004629 OutParamTypes.push_back(NewType);
4630 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004631 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004633
Douglas Gregor5499af42011-01-05 23:12:31 +00004634 // We're done with the pack expansion.
4635 continue;
4636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004637
Douglas Gregor48d24112011-01-10 20:53:55 +00004638 // If we're supposed to retain a pack expansion, do so by temporarily
4639 // forgetting the partially-substituted parameter pack.
4640 if (RetainExpansion) {
4641 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4642 QualType NewType = getDerived().TransformType(Pattern);
4643 if (NewType.isNull())
4644 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004645
Douglas Gregor48d24112011-01-10 20:53:55 +00004646 OutParamTypes.push_back(NewType);
4647 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004648 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004649 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004650
Chad Rosier1dcde962012-08-08 18:46:20 +00004651 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004652 // expansion.
4653 OldType = Expansion->getPattern();
4654 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004655 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4656 NewType = getDerived().TransformType(OldType);
4657 } else {
4658 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004659 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004660
Douglas Gregor5499af42011-01-05 23:12:31 +00004661 if (NewType.isNull())
4662 return true;
4663
4664 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004665 NewType = getSema().Context.getPackExpansionType(NewType,
4666 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004667
Douglas Gregordd472162011-01-07 00:20:55 +00004668 OutParamTypes.push_back(NewType);
4669 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004670 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004671 }
4672
John McCall8fb0d9d2011-05-01 22:35:37 +00004673#ifndef NDEBUG
4674 if (PVars) {
4675 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4676 if (ParmVarDecl *parm = (*PVars)[i])
4677 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004678 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004679#endif
4680
4681 return false;
4682}
John McCall58f10c32010-03-11 09:03:00 +00004683
4684template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004685QualType
John McCall550e0c22009-10-21 00:40:46 +00004686TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004687 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004688 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004689 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004690 return getDerived().TransformFunctionProtoType(
4691 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004692 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4693 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4694 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004695 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004696}
4697
Richard Smith2e321552014-11-12 02:00:47 +00004698template<typename Derived> template<typename Fn>
4699QualType TreeTransform<Derived>::TransformFunctionProtoType(
4700 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4701 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004702 // Transform the parameters and return type.
4703 //
Richard Smithf623c962012-04-17 00:58:00 +00004704 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004705 // When the function has a trailing return type, we instantiate the
4706 // parameters before the return type, since the return type can then refer
4707 // to the parameters themselves (via decltype, sizeof, etc.).
4708 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004709 SmallVector<QualType, 4> ParamTypes;
4710 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004711 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004712
Douglas Gregor7fb25412010-10-01 18:44:50 +00004713 QualType ResultType;
4714
Richard Smith1226c602012-08-14 22:51:13 +00004715 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004716 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004717 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004718 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004719 return QualType();
4720
Douglas Gregor3024f072012-04-16 07:05:22 +00004721 {
4722 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004723 // If a declaration declares a member function or member function
4724 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004725 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004726 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004727 // declarator.
4728 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004729
Alp Toker42a16a62014-01-25 23:51:36 +00004730 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004731 if (ResultType.isNull())
4732 return QualType();
4733 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004734 }
4735 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004736 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004737 if (ResultType.isNull())
4738 return QualType();
4739
Alp Toker9cacbab2014-01-20 20:26:09 +00004740 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004741 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004742 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004743 return QualType();
4744 }
4745
Richard Smith2e321552014-11-12 02:00:47 +00004746 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4747
4748 bool EPIChanged = false;
4749 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4750 return QualType();
4751
4752 // FIXME: Need to transform ConsumedParameters for variadic template
4753 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004754
John McCall550e0c22009-10-21 00:40:46 +00004755 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004756 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004757 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004758 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004759 if (Result.isNull())
4760 return QualType();
4761 }
Mike Stump11289f42009-09-09 15:08:12 +00004762
John McCall550e0c22009-10-21 00:40:46 +00004763 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004764 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004765 NewTL.setLParenLoc(TL.getLParenLoc());
4766 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004767 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004768 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4769 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004770
4771 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772}
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregord6ff3322009-08-04 16:50:30 +00004774template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004775bool TreeTransform<Derived>::TransformExceptionSpec(
4776 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4777 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4778 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4779
4780 // Instantiate a dynamic noexcept expression, if any.
4781 if (ESI.Type == EST_ComputedNoexcept) {
4782 EnterExpressionEvaluationContext Unevaluated(getSema(),
4783 Sema::ConstantEvaluated);
4784 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4785 if (NoexceptExpr.isInvalid())
4786 return true;
4787
4788 NoexceptExpr = getSema().CheckBooleanCondition(
4789 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4790 if (NoexceptExpr.isInvalid())
4791 return true;
4792
4793 if (!NoexceptExpr.get()->isValueDependent()) {
4794 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4795 NoexceptExpr.get(), nullptr,
4796 diag::err_noexcept_needs_constant_expression,
4797 /*AllowFold*/false);
4798 if (NoexceptExpr.isInvalid())
4799 return true;
4800 }
4801
4802 if (ESI.NoexceptExpr != NoexceptExpr.get())
4803 Changed = true;
4804 ESI.NoexceptExpr = NoexceptExpr.get();
4805 }
4806
4807 if (ESI.Type != EST_Dynamic)
4808 return false;
4809
4810 // Instantiate a dynamic exception specification's type.
4811 for (QualType T : ESI.Exceptions) {
4812 if (const PackExpansionType *PackExpansion =
4813 T->getAs<PackExpansionType>()) {
4814 Changed = true;
4815
4816 // We have a pack expansion. Instantiate it.
4817 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4818 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4819 Unexpanded);
4820 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4821
4822 // Determine whether the set of unexpanded parameter packs can and
4823 // should
4824 // be expanded.
4825 bool Expand = false;
4826 bool RetainExpansion = false;
4827 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4828 // FIXME: Track the location of the ellipsis (and track source location
4829 // information for the types in the exception specification in general).
4830 if (getDerived().TryExpandParameterPacks(
4831 Loc, SourceRange(), Unexpanded, Expand,
4832 RetainExpansion, NumExpansions))
4833 return true;
4834
4835 if (!Expand) {
4836 // We can't expand this pack expansion into separate arguments yet;
4837 // just substitute into the pattern and create a new pack expansion
4838 // type.
4839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4840 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4841 if (U.isNull())
4842 return true;
4843
4844 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4845 Exceptions.push_back(U);
4846 continue;
4847 }
4848
4849 // Substitute into the pack expansion pattern for each slice of the
4850 // pack.
4851 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4852 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4853
4854 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4855 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4856 return true;
4857
4858 Exceptions.push_back(U);
4859 }
4860 } else {
4861 QualType U = getDerived().TransformType(T);
4862 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4863 return true;
4864 if (T != U)
4865 Changed = true;
4866
4867 Exceptions.push_back(U);
4868 }
4869 }
4870
4871 ESI.Exceptions = Exceptions;
4872 return false;
4873}
4874
4875template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004876QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004877 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004878 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004879 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004880 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004881 if (ResultType.isNull())
4882 return QualType();
4883
4884 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004885 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004886 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4887
4888 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004889 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004890 NewTL.setLParenLoc(TL.getLParenLoc());
4891 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004892 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004893
4894 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004895}
Mike Stump11289f42009-09-09 15:08:12 +00004896
John McCallb96ec562009-12-04 22:46:56 +00004897template<typename Derived> QualType
4898TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004899 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004900 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004901 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004902 if (!D)
4903 return QualType();
4904
4905 QualType Result = TL.getType();
4906 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4907 Result = getDerived().RebuildUnresolvedUsingType(D);
4908 if (Result.isNull())
4909 return QualType();
4910 }
4911
4912 // We might get an arbitrary type spec type back. We should at
4913 // least always get a type spec type, though.
4914 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4915 NewTL.setNameLoc(TL.getNameLoc());
4916
4917 return Result;
4918}
4919
Douglas Gregord6ff3322009-08-04 16:50:30 +00004920template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004921QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004922 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004923 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004924 TypedefNameDecl *Typedef
4925 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4926 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004927 if (!Typedef)
4928 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004929
John McCall550e0c22009-10-21 00:40:46 +00004930 QualType Result = TL.getType();
4931 if (getDerived().AlwaysRebuild() ||
4932 Typedef != T->getDecl()) {
4933 Result = getDerived().RebuildTypedefType(Typedef);
4934 if (Result.isNull())
4935 return QualType();
4936 }
Mike Stump11289f42009-09-09 15:08:12 +00004937
John McCall550e0c22009-10-21 00:40:46 +00004938 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4939 NewTL.setNameLoc(TL.getNameLoc());
4940
4941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004942}
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregord6ff3322009-08-04 16:50:30 +00004944template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004945QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004946 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004947 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004948 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4949 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004950
John McCalldadc5752010-08-24 06:29:42 +00004951 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004952 if (E.isInvalid())
4953 return QualType();
4954
Eli Friedmane4f22df2012-02-29 04:03:55 +00004955 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4956 if (E.isInvalid())
4957 return QualType();
4958
John McCall550e0c22009-10-21 00:40:46 +00004959 QualType Result = TL.getType();
4960 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004961 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004962 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004963 if (Result.isNull())
4964 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004965 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004966 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004967
John McCall550e0c22009-10-21 00:40:46 +00004968 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004969 NewTL.setTypeofLoc(TL.getTypeofLoc());
4970 NewTL.setLParenLoc(TL.getLParenLoc());
4971 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004972
4973 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
4976template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004977QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004978 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004979 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4980 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4981 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004982 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004983
John McCall550e0c22009-10-21 00:40:46 +00004984 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004985 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4986 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004987 if (Result.isNull())
4988 return QualType();
4989 }
Mike Stump11289f42009-09-09 15:08:12 +00004990
John McCall550e0c22009-10-21 00:40:46 +00004991 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004992 NewTL.setTypeofLoc(TL.getTypeofLoc());
4993 NewTL.setLParenLoc(TL.getLParenLoc());
4994 NewTL.setRParenLoc(TL.getRParenLoc());
4995 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004996
4997 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004998}
Mike Stump11289f42009-09-09 15:08:12 +00004999
5000template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005001QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005002 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005003 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005004
Douglas Gregore922c772009-08-04 22:27:00 +00005005 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005006 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5007 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005008
John McCalldadc5752010-08-24 06:29:42 +00005009 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005010 if (E.isInvalid())
5011 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005012
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005013 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005014 if (E.isInvalid())
5015 return QualType();
5016
John McCall550e0c22009-10-21 00:40:46 +00005017 QualType Result = TL.getType();
5018 if (getDerived().AlwaysRebuild() ||
5019 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005020 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005021 if (Result.isNull())
5022 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005023 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005024 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005025
John McCall550e0c22009-10-21 00:40:46 +00005026 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5027 NewTL.setNameLoc(TL.getNameLoc());
5028
5029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005030}
5031
5032template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005033QualType TreeTransform<Derived>::TransformUnaryTransformType(
5034 TypeLocBuilder &TLB,
5035 UnaryTransformTypeLoc TL) {
5036 QualType Result = TL.getType();
5037 if (Result->isDependentType()) {
5038 const UnaryTransformType *T = TL.getTypePtr();
5039 QualType NewBase =
5040 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5041 Result = getDerived().RebuildUnaryTransformType(NewBase,
5042 T->getUTTKind(),
5043 TL.getKWLoc());
5044 if (Result.isNull())
5045 return QualType();
5046 }
5047
5048 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5049 NewTL.setKWLoc(TL.getKWLoc());
5050 NewTL.setParensRange(TL.getParensRange());
5051 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5052 return Result;
5053}
5054
5055template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005056QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5057 AutoTypeLoc TL) {
5058 const AutoType *T = TL.getTypePtr();
5059 QualType OldDeduced = T->getDeducedType();
5060 QualType NewDeduced;
5061 if (!OldDeduced.isNull()) {
5062 NewDeduced = getDerived().TransformType(OldDeduced);
5063 if (NewDeduced.isNull())
5064 return QualType();
5065 }
5066
5067 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005068 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5069 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005070 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005071 if (Result.isNull())
5072 return QualType();
5073 }
5074
5075 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5076 NewTL.setNameLoc(TL.getNameLoc());
5077
5078 return Result;
5079}
5080
5081template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005082QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005083 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005084 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005085 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005086 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5087 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005088 if (!Record)
5089 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005090
John McCall550e0c22009-10-21 00:40:46 +00005091 QualType Result = TL.getType();
5092 if (getDerived().AlwaysRebuild() ||
5093 Record != T->getDecl()) {
5094 Result = getDerived().RebuildRecordType(Record);
5095 if (Result.isNull())
5096 return QualType();
5097 }
Mike Stump11289f42009-09-09 15:08:12 +00005098
John McCall550e0c22009-10-21 00:40:46 +00005099 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5100 NewTL.setNameLoc(TL.getNameLoc());
5101
5102 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
5105template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005106QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005107 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005108 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005110 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5111 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005112 if (!Enum)
5113 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005114
John McCall550e0c22009-10-21 00:40:46 +00005115 QualType Result = TL.getType();
5116 if (getDerived().AlwaysRebuild() ||
5117 Enum != T->getDecl()) {
5118 Result = getDerived().RebuildEnumType(Enum);
5119 if (Result.isNull())
5120 return QualType();
5121 }
Mike Stump11289f42009-09-09 15:08:12 +00005122
John McCall550e0c22009-10-21 00:40:46 +00005123 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5124 NewTL.setNameLoc(TL.getNameLoc());
5125
5126 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005127}
John McCallfcc33b02009-09-05 00:15:47 +00005128
John McCalle78aac42010-03-10 03:28:59 +00005129template<typename Derived>
5130QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5131 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005132 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005133 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5134 TL.getTypePtr()->getDecl());
5135 if (!D) return QualType();
5136
5137 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5138 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5139 return T;
5140}
5141
Douglas Gregord6ff3322009-08-04 16:50:30 +00005142template<typename Derived>
5143QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005144 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005145 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005146 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005147}
5148
Mike Stump11289f42009-09-09 15:08:12 +00005149template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005150QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005151 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005152 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005153 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005154
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005155 // Substitute into the replacement type, which itself might involve something
5156 // that needs to be transformed. This only tends to occur with default
5157 // template arguments of template template parameters.
5158 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5159 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5160 if (Replacement.isNull())
5161 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005162
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005163 // Always canonicalize the replacement type.
5164 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5165 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005166 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005167 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005168
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005169 // Propagate type-source information.
5170 SubstTemplateTypeParmTypeLoc NewTL
5171 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5172 NewTL.setNameLoc(TL.getNameLoc());
5173 return Result;
5174
John McCallcebee162009-10-18 09:09:24 +00005175}
5176
5177template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005178QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5179 TypeLocBuilder &TLB,
5180 SubstTemplateTypeParmPackTypeLoc TL) {
5181 return TransformTypeSpecType(TLB, TL);
5182}
5183
5184template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005185QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005186 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005187 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005188 const TemplateSpecializationType *T = TL.getTypePtr();
5189
Douglas Gregordf846d12011-03-02 18:46:51 +00005190 // The nested-name-specifier never matters in a TemplateSpecializationType,
5191 // because we can't have a dependent nested-name-specifier anyway.
5192 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005193 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005194 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5195 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005196 if (Template.isNull())
5197 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005198
John McCall31f82722010-11-12 08:19:04 +00005199 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5200}
5201
Eli Friedman0dfb8892011-10-06 23:00:33 +00005202template<typename Derived>
5203QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5204 AtomicTypeLoc TL) {
5205 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5206 if (ValueType.isNull())
5207 return QualType();
5208
5209 QualType Result = TL.getType();
5210 if (getDerived().AlwaysRebuild() ||
5211 ValueType != TL.getValueLoc().getType()) {
5212 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5213 if (Result.isNull())
5214 return QualType();
5215 }
5216
5217 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5218 NewTL.setKWLoc(TL.getKWLoc());
5219 NewTL.setLParenLoc(TL.getLParenLoc());
5220 NewTL.setRParenLoc(TL.getRParenLoc());
5221
5222 return Result;
5223}
5224
Chad Rosier1dcde962012-08-08 18:46:20 +00005225 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005226 /// container that provides a \c getArgLoc() member function.
5227 ///
5228 /// This iterator is intended to be used with the iterator form of
5229 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5230 template<typename ArgLocContainer>
5231 class TemplateArgumentLocContainerIterator {
5232 ArgLocContainer *Container;
5233 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005234
Douglas Gregorfe921a72010-12-20 23:36:19 +00005235 public:
5236 typedef TemplateArgumentLoc value_type;
5237 typedef TemplateArgumentLoc reference;
5238 typedef int difference_type;
5239 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005240
Douglas Gregorfe921a72010-12-20 23:36:19 +00005241 class pointer {
5242 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005243
Douglas Gregorfe921a72010-12-20 23:36:19 +00005244 public:
5245 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005246
Douglas Gregorfe921a72010-12-20 23:36:19 +00005247 const TemplateArgumentLoc *operator->() const {
5248 return &Arg;
5249 }
5250 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005251
5252
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005253 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005254
Douglas Gregorfe921a72010-12-20 23:36:19 +00005255 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5256 unsigned Index)
5257 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005258
Douglas Gregorfe921a72010-12-20 23:36:19 +00005259 TemplateArgumentLocContainerIterator &operator++() {
5260 ++Index;
5261 return *this;
5262 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005263
Douglas Gregorfe921a72010-12-20 23:36:19 +00005264 TemplateArgumentLocContainerIterator operator++(int) {
5265 TemplateArgumentLocContainerIterator Old(*this);
5266 ++(*this);
5267 return Old;
5268 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005269
Douglas Gregorfe921a72010-12-20 23:36:19 +00005270 TemplateArgumentLoc operator*() const {
5271 return Container->getArgLoc(Index);
5272 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005273
Douglas Gregorfe921a72010-12-20 23:36:19 +00005274 pointer operator->() const {
5275 return pointer(Container->getArgLoc(Index));
5276 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005277
Douglas Gregorfe921a72010-12-20 23:36:19 +00005278 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005279 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005280 return X.Container == Y.Container && X.Index == Y.Index;
5281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005282
Douglas Gregorfe921a72010-12-20 23:36:19 +00005283 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005284 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005285 return !(X == Y);
5286 }
5287 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005288
5289
John McCall31f82722010-11-12 08:19:04 +00005290template <typename Derived>
5291QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5292 TypeLocBuilder &TLB,
5293 TemplateSpecializationTypeLoc TL,
5294 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005295 TemplateArgumentListInfo NewTemplateArgs;
5296 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5297 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005298 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5299 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005300 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005301 ArgIterator(TL, TL.getNumArgs()),
5302 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005303 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005304
John McCall0ad16662009-10-29 08:12:44 +00005305 // FIXME: maybe don't rebuild if all the template arguments are the same.
5306
5307 QualType Result =
5308 getDerived().RebuildTemplateSpecializationType(Template,
5309 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005310 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005311
5312 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005313 // Specializations of template template parameters are represented as
5314 // TemplateSpecializationTypes, and substitution of type alias templates
5315 // within a dependent context can transform them into
5316 // DependentTemplateSpecializationTypes.
5317 if (isa<DependentTemplateSpecializationType>(Result)) {
5318 DependentTemplateSpecializationTypeLoc NewTL
5319 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005320 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005321 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005322 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005323 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005324 NewTL.setLAngleLoc(TL.getLAngleLoc());
5325 NewTL.setRAngleLoc(TL.getRAngleLoc());
5326 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5327 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5328 return Result;
5329 }
5330
John McCall0ad16662009-10-29 08:12:44 +00005331 TemplateSpecializationTypeLoc NewTL
5332 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005333 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005334 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5335 NewTL.setLAngleLoc(TL.getLAngleLoc());
5336 NewTL.setRAngleLoc(TL.getRAngleLoc());
5337 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5338 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005339 }
Mike Stump11289f42009-09-09 15:08:12 +00005340
John McCall0ad16662009-10-29 08:12:44 +00005341 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005342}
Mike Stump11289f42009-09-09 15:08:12 +00005343
Douglas Gregor5a064722011-02-28 17:23:35 +00005344template <typename Derived>
5345QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5346 TypeLocBuilder &TLB,
5347 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005348 TemplateName Template,
5349 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005350 TemplateArgumentListInfo NewTemplateArgs;
5351 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5352 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5353 typedef TemplateArgumentLocContainerIterator<
5354 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005355 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005356 ArgIterator(TL, TL.getNumArgs()),
5357 NewTemplateArgs))
5358 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005359
Douglas Gregor5a064722011-02-28 17:23:35 +00005360 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005361
Douglas Gregor5a064722011-02-28 17:23:35 +00005362 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5363 QualType Result
5364 = getSema().Context.getDependentTemplateSpecializationType(
5365 TL.getTypePtr()->getKeyword(),
5366 DTN->getQualifier(),
5367 DTN->getIdentifier(),
5368 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005369
Douglas Gregor5a064722011-02-28 17:23:35 +00005370 DependentTemplateSpecializationTypeLoc NewTL
5371 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005372 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005373 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005374 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005375 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005376 NewTL.setLAngleLoc(TL.getLAngleLoc());
5377 NewTL.setRAngleLoc(TL.getRAngleLoc());
5378 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5379 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5380 return Result;
5381 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005382
5383 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005384 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005385 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005386 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005387
Douglas Gregor5a064722011-02-28 17:23:35 +00005388 if (!Result.isNull()) {
5389 /// FIXME: Wrap this in an elaborated-type-specifier?
5390 TemplateSpecializationTypeLoc NewTL
5391 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005392 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005393 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005394 NewTL.setLAngleLoc(TL.getLAngleLoc());
5395 NewTL.setRAngleLoc(TL.getRAngleLoc());
5396 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5397 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5398 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005399
Douglas Gregor5a064722011-02-28 17:23:35 +00005400 return Result;
5401}
5402
Mike Stump11289f42009-09-09 15:08:12 +00005403template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005404QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005405TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005406 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005407 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005408
Douglas Gregor844cb502011-03-01 18:12:44 +00005409 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005410 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005411 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005412 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005413 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5414 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005415 return QualType();
5416 }
Mike Stump11289f42009-09-09 15:08:12 +00005417
John McCall31f82722010-11-12 08:19:04 +00005418 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5419 if (NamedT.isNull())
5420 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005421
Richard Smith3f1b5d02011-05-05 21:57:07 +00005422 // C++0x [dcl.type.elab]p2:
5423 // If the identifier resolves to a typedef-name or the simple-template-id
5424 // resolves to an alias template specialization, the
5425 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005426 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5427 if (const TemplateSpecializationType *TST =
5428 NamedT->getAs<TemplateSpecializationType>()) {
5429 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005430 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5431 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005432 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5433 diag::err_tag_reference_non_tag) << 4;
5434 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5435 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005436 }
5437 }
5438
John McCall550e0c22009-10-21 00:40:46 +00005439 QualType Result = TL.getType();
5440 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005441 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005442 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005443 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005444 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005445 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005446 if (Result.isNull())
5447 return QualType();
5448 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005449
Abramo Bagnara6150c882010-05-11 21:36:43 +00005450 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005451 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005452 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005453 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
5456template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005457QualType TreeTransform<Derived>::TransformAttributedType(
5458 TypeLocBuilder &TLB,
5459 AttributedTypeLoc TL) {
5460 const AttributedType *oldType = TL.getTypePtr();
5461 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5462 if (modifiedType.isNull())
5463 return QualType();
5464
5465 QualType result = TL.getType();
5466
5467 // FIXME: dependent operand expressions?
5468 if (getDerived().AlwaysRebuild() ||
5469 modifiedType != oldType->getModifiedType()) {
5470 // TODO: this is really lame; we should really be rebuilding the
5471 // equivalent type from first principles.
5472 QualType equivalentType
5473 = getDerived().TransformType(oldType->getEquivalentType());
5474 if (equivalentType.isNull())
5475 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005476
5477 // Check whether we can add nullability; it is only represented as
5478 // type sugar, and therefore cannot be diagnosed in any other way.
5479 if (auto nullability = oldType->getImmediateNullability()) {
5480 if (!modifiedType->canHaveNullability()) {
5481 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005482 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005483 return QualType();
5484 }
5485 }
5486
John McCall81904512011-01-06 01:58:22 +00005487 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5488 modifiedType,
5489 equivalentType);
5490 }
5491
5492 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5493 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5494 if (TL.hasAttrOperand())
5495 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5496 if (TL.hasAttrExprOperand())
5497 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5498 else if (TL.hasAttrEnumOperand())
5499 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5500
5501 return result;
5502}
5503
5504template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005505QualType
5506TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5507 ParenTypeLoc TL) {
5508 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5509 if (Inner.isNull())
5510 return QualType();
5511
5512 QualType Result = TL.getType();
5513 if (getDerived().AlwaysRebuild() ||
5514 Inner != TL.getInnerLoc().getType()) {
5515 Result = getDerived().RebuildParenType(Inner);
5516 if (Result.isNull())
5517 return QualType();
5518 }
5519
5520 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5521 NewTL.setLParenLoc(TL.getLParenLoc());
5522 NewTL.setRParenLoc(TL.getRParenLoc());
5523 return Result;
5524}
5525
5526template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005527QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005528 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005529 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005530
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005531 NestedNameSpecifierLoc QualifierLoc
5532 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5533 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005534 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005535
John McCallc392f372010-06-11 00:33:02 +00005536 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005537 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005538 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005539 QualifierLoc,
5540 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005541 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005542 if (Result.isNull())
5543 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005544
Abramo Bagnarad7548482010-05-19 21:37:53 +00005545 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5546 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005547 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5548
Abramo Bagnarad7548482010-05-19 21:37:53 +00005549 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005550 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005551 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005552 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005553 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005554 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005555 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005556 NewTL.setNameLoc(TL.getNameLoc());
5557 }
John McCall550e0c22009-10-21 00:40:46 +00005558 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregord6ff3322009-08-04 16:50:30 +00005561template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005562QualType TreeTransform<Derived>::
5563 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005564 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005565 NestedNameSpecifierLoc QualifierLoc;
5566 if (TL.getQualifierLoc()) {
5567 QualifierLoc
5568 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5569 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005570 return QualType();
5571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005572
John McCall31f82722010-11-12 08:19:04 +00005573 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005574 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005575}
5576
5577template<typename Derived>
5578QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005579TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5580 DependentTemplateSpecializationTypeLoc TL,
5581 NestedNameSpecifierLoc QualifierLoc) {
5582 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005583
Douglas Gregora7a795b2011-03-01 20:11:18 +00005584 TemplateArgumentListInfo NewTemplateArgs;
5585 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5586 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005587
Douglas Gregora7a795b2011-03-01 20:11:18 +00005588 typedef TemplateArgumentLocContainerIterator<
5589 DependentTemplateSpecializationTypeLoc> ArgIterator;
5590 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5591 ArgIterator(TL, TL.getNumArgs()),
5592 NewTemplateArgs))
5593 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005594
Douglas Gregora7a795b2011-03-01 20:11:18 +00005595 QualType Result
5596 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5597 QualifierLoc,
5598 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005599 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005600 NewTemplateArgs);
5601 if (Result.isNull())
5602 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005603
Douglas Gregora7a795b2011-03-01 20:11:18 +00005604 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5605 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005606
Douglas Gregora7a795b2011-03-01 20:11:18 +00005607 // Copy information relevant to the template specialization.
5608 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005609 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005610 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005611 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005612 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5613 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005614 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005615 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005616
Douglas Gregora7a795b2011-03-01 20:11:18 +00005617 // Copy information relevant to the elaborated type.
5618 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005619 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005620 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005621 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5622 DependentTemplateSpecializationTypeLoc SpecTL
5623 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005624 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005625 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005626 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005627 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005628 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5629 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005630 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005631 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005632 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005633 TemplateSpecializationTypeLoc SpecTL
5634 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005635 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005636 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005637 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5638 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005639 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005640 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005641 }
5642 return Result;
5643}
5644
5645template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005646QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5647 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005648 QualType Pattern
5649 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005650 if (Pattern.isNull())
5651 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005652
5653 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005654 if (getDerived().AlwaysRebuild() ||
5655 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005656 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005657 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005658 TL.getEllipsisLoc(),
5659 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005660 if (Result.isNull())
5661 return QualType();
5662 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005663
Douglas Gregor822d0302011-01-12 17:07:58 +00005664 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5665 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5666 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005667}
5668
5669template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005670QualType
5671TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005672 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005673 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005674 TLB.pushFullCopy(TL);
5675 return TL.getType();
5676}
5677
5678template<typename Derived>
5679QualType
5680TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005681 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005682 // Transform base type.
5683 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5684 if (BaseType.isNull())
5685 return QualType();
5686
5687 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5688
5689 // Transform type arguments.
5690 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5691 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5692 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5693 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5694 QualType TypeArg = TypeArgInfo->getType();
5695 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5696 AnyChanged = true;
5697
5698 // We have a pack expansion. Instantiate it.
5699 const auto *PackExpansion = PackExpansionLoc.getType()
5700 ->castAs<PackExpansionType>();
5701 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5702 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5703 Unexpanded);
5704 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5705
5706 // Determine whether the set of unexpanded parameter packs can
5707 // and should be expanded.
5708 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5709 bool Expand = false;
5710 bool RetainExpansion = false;
5711 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5712 if (getDerived().TryExpandParameterPacks(
5713 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5714 Unexpanded, Expand, RetainExpansion, NumExpansions))
5715 return QualType();
5716
5717 if (!Expand) {
5718 // We can't expand this pack expansion into separate arguments yet;
5719 // just substitute into the pattern and create a new pack expansion
5720 // type.
5721 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5722
5723 TypeLocBuilder TypeArgBuilder;
5724 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5725 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5726 PatternLoc);
5727 if (NewPatternType.isNull())
5728 return QualType();
5729
5730 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5731 NewPatternType, NumExpansions);
5732 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5733 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5734 NewTypeArgInfos.push_back(
5735 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5736 continue;
5737 }
5738
5739 // Substitute into the pack expansion pattern for each slice of the
5740 // pack.
5741 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5742 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5743
5744 TypeLocBuilder TypeArgBuilder;
5745 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5746
5747 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5748 PatternLoc);
5749 if (NewTypeArg.isNull())
5750 return QualType();
5751
5752 NewTypeArgInfos.push_back(
5753 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5754 }
5755
5756 continue;
5757 }
5758
5759 TypeLocBuilder TypeArgBuilder;
5760 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5761 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5762 if (NewTypeArg.isNull())
5763 return QualType();
5764
5765 // If nothing changed, just keep the old TypeSourceInfo.
5766 if (NewTypeArg == TypeArg) {
5767 NewTypeArgInfos.push_back(TypeArgInfo);
5768 continue;
5769 }
5770
5771 NewTypeArgInfos.push_back(
5772 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5773 AnyChanged = true;
5774 }
5775
5776 QualType Result = TL.getType();
5777 if (getDerived().AlwaysRebuild() || AnyChanged) {
5778 // Rebuild the type.
5779 Result = getDerived().RebuildObjCObjectType(
5780 BaseType,
5781 TL.getLocStart(),
5782 TL.getTypeArgsLAngleLoc(),
5783 NewTypeArgInfos,
5784 TL.getTypeArgsRAngleLoc(),
5785 TL.getProtocolLAngleLoc(),
5786 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5787 TL.getNumProtocols()),
5788 TL.getProtocolLocs(),
5789 TL.getProtocolRAngleLoc());
5790
5791 if (Result.isNull())
5792 return QualType();
5793 }
5794
5795 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5796 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5797 NewT.setHasBaseTypeAsWritten(true);
5798 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5799 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5800 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5801 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5802 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5803 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5804 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5805 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5806 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005807}
Mike Stump11289f42009-09-09 15:08:12 +00005808
5809template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005810QualType
5811TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005812 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005813 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5814 if (PointeeType.isNull())
5815 return QualType();
5816
5817 QualType Result = TL.getType();
5818 if (getDerived().AlwaysRebuild() ||
5819 PointeeType != TL.getPointeeLoc().getType()) {
5820 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5821 TL.getStarLoc());
5822 if (Result.isNull())
5823 return QualType();
5824 }
5825
5826 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5827 NewT.setStarLoc(TL.getStarLoc());
5828 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005829}
5830
Douglas Gregord6ff3322009-08-04 16:50:30 +00005831//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005832// Statement transformation
5833//===----------------------------------------------------------------------===//
5834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005837 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005838}
5839
5840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005841StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005842TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5843 return getDerived().TransformCompoundStmt(S, false);
5844}
5845
5846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005848TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005849 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005850 Sema::CompoundScopeRAII CompoundScope(getSema());
5851
John McCall1ababa62010-08-27 19:56:05 +00005852 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005853 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005854 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005855 for (auto *B : S->body()) {
5856 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005857 if (Result.isInvalid()) {
5858 // Immediately fail if this was a DeclStmt, since it's very
5859 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005860 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005861 return StmtError();
5862
5863 // Otherwise, just keep processing substatements and fail later.
5864 SubStmtInvalid = true;
5865 continue;
5866 }
Mike Stump11289f42009-09-09 15:08:12 +00005867
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005868 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005869 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005870 }
Mike Stump11289f42009-09-09 15:08:12 +00005871
John McCall1ababa62010-08-27 19:56:05 +00005872 if (SubStmtInvalid)
5873 return StmtError();
5874
Douglas Gregorebe10102009-08-20 07:17:43 +00005875 if (!getDerived().AlwaysRebuild() &&
5876 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005877 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005878
5879 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005880 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005881 S->getRBracLoc(),
5882 IsStmtExpr);
5883}
Mike Stump11289f42009-09-09 15:08:12 +00005884
Douglas Gregorebe10102009-08-20 07:17:43 +00005885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005886StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005887TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005888 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005889 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005890 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5891 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005892
Eli Friedman06577382009-11-19 03:14:00 +00005893 // Transform the left-hand case value.
5894 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005895 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005896 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005897 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005898
Eli Friedman06577382009-11-19 03:14:00 +00005899 // Transform the right-hand case value (for the GNU case-range extension).
5900 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005901 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005902 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005904 }
Mike Stump11289f42009-09-09 15:08:12 +00005905
Douglas Gregorebe10102009-08-20 07:17:43 +00005906 // Build the case statement.
5907 // Case statements are always rebuilt so that they will attached to their
5908 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005909 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005910 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005911 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005912 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005913 S->getColonLoc());
5914 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregorebe10102009-08-20 07:17:43 +00005917 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005918 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005919 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005920 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregorebe10102009-08-20 07:17:43 +00005922 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005923 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005924}
5925
5926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005927StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005928TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005929 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005930 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005931 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005932 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregorebe10102009-08-20 07:17:43 +00005934 // Default statements are always rebuilt
5935 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005936 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregorebe10102009-08-20 07:17:43 +00005939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005941TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005942 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005943 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005944 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005945
Chris Lattnercab02a62011-02-17 20:34:02 +00005946 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5947 S->getDecl());
5948 if (!LD)
5949 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005950
5951
Douglas Gregorebe10102009-08-20 07:17:43 +00005952 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005953 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005954 cast<LabelDecl>(LD), SourceLocation(),
5955 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005958template <typename Derived>
5959const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5960 if (!R)
5961 return R;
5962
5963 switch (R->getKind()) {
5964// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5965#define ATTR(X)
5966#define PRAGMA_SPELLING_ATTR(X) \
5967 case attr::X: \
5968 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5969#include "clang/Basic/AttrList.inc"
5970 default:
5971 return R;
5972 }
5973}
5974
5975template <typename Derived>
5976StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5977 bool AttrsChanged = false;
5978 SmallVector<const Attr *, 1> Attrs;
5979
5980 // Visit attributes and keep track if any are transformed.
5981 for (const auto *I : S->getAttrs()) {
5982 const Attr *R = getDerived().TransformAttr(I);
5983 AttrsChanged |= (I != R);
5984 Attrs.push_back(R);
5985 }
5986
Richard Smithc202b282012-04-14 00:33:13 +00005987 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5988 if (SubStmt.isInvalid())
5989 return StmtError();
5990
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005991 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005992 return S;
5993
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005994 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005995 SubStmt.get());
5996}
5997
5998template<typename Derived>
5999StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006000TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006001 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006002 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006003 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006004 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006005 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006006 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006007 getDerived().TransformDefinition(
6008 S->getConditionVariable()->getLocation(),
6009 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006010 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006012 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006013 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006014
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006015 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006017
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006018 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006019 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006020 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006021 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006022 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006023 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006024
John McCallb268a282010-08-23 23:25:46 +00006025 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006026 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006027 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006028
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006029 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006030 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006031 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006032
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006034 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006035 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregorebe10102009-08-20 07:17:43 +00006038 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006039 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006040 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006041 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006042
Douglas Gregorebe10102009-08-20 07:17:43 +00006043 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006044 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006045 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006046 Then.get() == S->getThen() &&
6047 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006048 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006049
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006050 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006051 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006052 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006053}
6054
6055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006056StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006057TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006058 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006059 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006060 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006061 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006062 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006063 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006064 getDerived().TransformDefinition(
6065 S->getConditionVariable()->getLocation(),
6066 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006067 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006068 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006069 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006070 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006071
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006072 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006073 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006074 }
Mike Stump11289f42009-09-09 15:08:12 +00006075
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006077 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006078 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006079 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006080 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006081 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006082
Douglas Gregorebe10102009-08-20 07:17:43 +00006083 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006084 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006085 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregorebe10102009-08-20 07:17:43 +00006088 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006089 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6090 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006091}
Mike Stump11289f42009-09-09 15:08:12 +00006092
Douglas Gregorebe10102009-08-20 07:17:43 +00006093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006094StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006095TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006096 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006097 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006098 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006099 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006100 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006101 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006102 getDerived().TransformDefinition(
6103 S->getConditionVariable()->getLocation(),
6104 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006105 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006106 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006107 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006108 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006109
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006110 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006111 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006112
6113 if (S->getCond()) {
6114 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006115 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6116 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006117 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006118 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006119 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006120 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006121 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006122 }
Mike Stump11289f42009-09-09 15:08:12 +00006123
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006124 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006125 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006126 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006127
Douglas Gregorebe10102009-08-20 07:17:43 +00006128 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006129 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006130 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006131 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregorebe10102009-08-20 07:17:43 +00006133 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006134 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006135 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006136 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006137 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006139 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006140 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006141}
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregorebe10102009-08-20 07:17:43 +00006143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006144StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006145TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006146 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006147 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006148 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006149 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006150
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006151 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006152 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006153 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006154 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006155
Douglas Gregorebe10102009-08-20 07:17:43 +00006156 if (!getDerived().AlwaysRebuild() &&
6157 Cond.get() == S->getCond() &&
6158 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006159 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006160
John McCallb268a282010-08-23 23:25:46 +00006161 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6162 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006163 S->getRParenLoc());
6164}
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregorebe10102009-08-20 07:17:43 +00006166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006167StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006168TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006169 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006170 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006171 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006172 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006173
Douglas Gregorebe10102009-08-20 07:17:43 +00006174 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006175 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006176 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006177 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006178 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006179 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006180 getDerived().TransformDefinition(
6181 S->getConditionVariable()->getLocation(),
6182 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006183 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006184 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006185 } else {
6186 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006187
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006188 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006189 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006190
6191 if (S->getCond()) {
6192 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006193 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6194 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006195 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006196 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006197 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006198
John McCallb268a282010-08-23 23:25:46 +00006199 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006200 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006201 }
Mike Stump11289f42009-09-09 15:08:12 +00006202
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006203 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006204 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006206
Douglas Gregorebe10102009-08-20 07:17:43 +00006207 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006208 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006209 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006211
Richard Smith945f8d32013-01-14 22:39:08 +00006212 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006213 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006214 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006215
Douglas Gregorebe10102009-08-20 07:17:43 +00006216 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006217 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006218 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006220
Douglas Gregorebe10102009-08-20 07:17:43 +00006221 if (!getDerived().AlwaysRebuild() &&
6222 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006223 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006224 Inc.get() == S->getInc() &&
6225 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006226 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregorebe10102009-08-20 07:17:43 +00006228 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006229 Init.get(), FullCond, ConditionVar,
6230 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006231}
6232
6233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006234StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006235TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006236 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6237 S->getLabel());
6238 if (!LD)
6239 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006240
Douglas Gregorebe10102009-08-20 07:17:43 +00006241 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006242 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006243 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006244}
6245
6246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006247StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006248TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006249 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006250 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006252 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregorebe10102009-08-20 07:17:43 +00006254 if (!getDerived().AlwaysRebuild() &&
6255 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006256 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006257
6258 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006259 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006260}
6261
6262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006263StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006264TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006265 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006266}
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregorebe10102009-08-20 07:17:43 +00006268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006269StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006270TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006271 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006272}
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregorebe10102009-08-20 07:17:43 +00006274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006275StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006276TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006277 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6278 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006279 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006280 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006281
Mike Stump11289f42009-09-09 15:08:12 +00006282 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006283 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006284 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006285}
Mike Stump11289f42009-09-09 15:08:12 +00006286
Douglas Gregorebe10102009-08-20 07:17:43 +00006287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006288StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006289TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006290 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006291 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006292 for (auto *D : S->decls()) {
6293 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006294 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006295 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006296
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006297 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregorebe10102009-08-20 07:17:43 +00006300 Decls.push_back(Transformed);
6301 }
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregorebe10102009-08-20 07:17:43 +00006303 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006304 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006305
Rafael Espindolaab417692013-07-09 12:05:01 +00006306 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregorebe10102009-08-20 07:17:43 +00006309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006310StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006311TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006312
Benjamin Kramerf0623432012-08-23 22:51:59 +00006313 SmallVector<Expr*, 8> Constraints;
6314 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006315 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006316
John McCalldadc5752010-08-24 06:29:42 +00006317 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006318 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006319
6320 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Anders Carlssonaaeef072010-01-24 05:50:09 +00006322 // Go through the outputs.
6323 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006324 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006325
Anders Carlssonaaeef072010-01-24 05:50:09 +00006326 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006327 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Anders Carlssonaaeef072010-01-24 05:50:09 +00006329 // Transform the output expr.
6330 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006331 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006332 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006334
Anders Carlssonaaeef072010-01-24 05:50:09 +00006335 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006336
John McCallb268a282010-08-23 23:25:46 +00006337 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006339
Anders Carlssonaaeef072010-01-24 05:50:09 +00006340 // Go through the inputs.
6341 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006342 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006343
Anders Carlssonaaeef072010-01-24 05:50:09 +00006344 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006345 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006346
Anders Carlssonaaeef072010-01-24 05:50:09 +00006347 // Transform the input expr.
6348 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006350 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006352
Anders Carlssonaaeef072010-01-24 05:50:09 +00006353 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006354
John McCallb268a282010-08-23 23:25:46 +00006355 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006356 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006357
Anders Carlssonaaeef072010-01-24 05:50:09 +00006358 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006359 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006360
6361 // Go through the clobbers.
6362 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006363 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006364
6365 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006366 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006367 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6368 S->isVolatile(), S->getNumOutputs(),
6369 S->getNumInputs(), Names.data(),
6370 Constraints, Exprs, AsmString.get(),
6371 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006372}
6373
Chad Rosier32503022012-06-11 20:47:18 +00006374template<typename Derived>
6375StmtResult
6376TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006377 ArrayRef<Token> AsmToks =
6378 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006379
John McCallf413f5e2013-05-03 00:10:13 +00006380 bool HadError = false, HadChange = false;
6381
6382 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6383 SmallVector<Expr*, 8> TransformedExprs;
6384 TransformedExprs.reserve(SrcExprs.size());
6385 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6386 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6387 if (!Result.isUsable()) {
6388 HadError = true;
6389 } else {
6390 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006391 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006392 }
6393 }
6394
6395 if (HadError) return StmtError();
6396 if (!HadChange && !getDerived().AlwaysRebuild())
6397 return Owned(S);
6398
Chad Rosierb6f46c12012-08-15 16:53:30 +00006399 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006400 AsmToks, S->getAsmString(),
6401 S->getNumOutputs(), S->getNumInputs(),
6402 S->getAllConstraints(), S->getClobbers(),
6403 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006404}
Douglas Gregorebe10102009-08-20 07:17:43 +00006405
6406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006407StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006408TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006409 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006410 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006411 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006412 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006413
Douglas Gregor96c79492010-04-23 22:50:49 +00006414 // Transform the @catch statements (if present).
6415 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006416 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006417 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006418 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006419 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006421 if (Catch.get() != S->getCatchStmt(I))
6422 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006423 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006425
Douglas Gregor306de2f2010-04-22 23:59:56 +00006426 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006427 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006428 if (S->getFinallyStmt()) {
6429 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6430 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006431 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006432 }
6433
6434 // If nothing changed, just retain this statement.
6435 if (!getDerived().AlwaysRebuild() &&
6436 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006437 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006438 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006439 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006440
Douglas Gregor306de2f2010-04-22 23:59:56 +00006441 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006442 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006443 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006444}
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregorebe10102009-08-20 07:17:43 +00006446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006447StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006448TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006449 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006450 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006451 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006452 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006453 if (FromVar->getTypeSourceInfo()) {
6454 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6455 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006456 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006458
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006459 QualType T;
6460 if (TSInfo)
6461 T = TSInfo->getType();
6462 else {
6463 T = getDerived().TransformType(FromVar->getType());
6464 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006465 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006467
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006468 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6469 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006470 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006471 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006472
John McCalldadc5752010-08-24 06:29:42 +00006473 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006474 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006476
6477 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006478 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006479 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006480}
Mike Stump11289f42009-09-09 15:08:12 +00006481
Douglas Gregorebe10102009-08-20 07:17:43 +00006482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006483StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006484TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006485 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006486 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006487 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006488 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006489
Douglas Gregor306de2f2010-04-22 23:59:56 +00006490 // If nothing changed, just retain this statement.
6491 if (!getDerived().AlwaysRebuild() &&
6492 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006493 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006494
6495 // Build a new statement.
6496 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006497 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006498}
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregorebe10102009-08-20 07:17:43 +00006500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006501StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006502TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006503 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006504 if (S->getThrowExpr()) {
6505 Operand = getDerived().TransformExpr(S->getThrowExpr());
6506 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006509
Douglas Gregor2900c162010-04-22 21:44:01 +00006510 if (!getDerived().AlwaysRebuild() &&
6511 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006512 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006513
John McCallb268a282010-08-23 23:25:46 +00006514 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006515}
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregorebe10102009-08-20 07:17:43 +00006517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006519TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006520 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006521 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006522 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006523 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006524 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006525 Object =
6526 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6527 Object.get());
6528 if (Object.isInvalid())
6529 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006530
Douglas Gregor6148de72010-04-22 22:01:21 +00006531 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006532 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006533 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Douglas Gregor6148de72010-04-22 22:01:21 +00006536 // If nothing change, just retain the current statement.
6537 if (!getDerived().AlwaysRebuild() &&
6538 Object.get() == S->getSynchExpr() &&
6539 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006540 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006541
6542 // Build a new statement.
6543 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006544 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006545}
6546
6547template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006548StmtResult
John McCall31168b02011-06-15 23:02:42 +00006549TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6550 ObjCAutoreleasePoolStmt *S) {
6551 // Transform the body.
6552 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6553 if (Body.isInvalid())
6554 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006555
John McCall31168b02011-06-15 23:02:42 +00006556 // If nothing changed, just retain this statement.
6557 if (!getDerived().AlwaysRebuild() &&
6558 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006559 return S;
John McCall31168b02011-06-15 23:02:42 +00006560
6561 // Build a new statement.
6562 return getDerived().RebuildObjCAutoreleasePoolStmt(
6563 S->getAtLoc(), Body.get());
6564}
6565
6566template<typename Derived>
6567StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006568TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006569 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006570 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006571 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006572 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006573 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006574
Douglas Gregorf68a5082010-04-22 23:10:45 +00006575 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006576 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006577 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006579
Douglas Gregorf68a5082010-04-22 23:10:45 +00006580 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006581 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006582 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006583 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006584
Douglas Gregorf68a5082010-04-22 23:10:45 +00006585 // If nothing changed, just retain this statement.
6586 if (!getDerived().AlwaysRebuild() &&
6587 Element.get() == S->getElement() &&
6588 Collection.get() == S->getCollection() &&
6589 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006590 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006591
Douglas Gregorf68a5082010-04-22 23:10:45 +00006592 // Build a new statement.
6593 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006594 Element.get(),
6595 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006596 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006597 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006598}
6599
David Majnemer5f7efef2013-10-15 09:50:08 +00006600template <typename Derived>
6601StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006602 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006603 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006604 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6605 TypeSourceInfo *T =
6606 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006607 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006608 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006609
David Majnemer5f7efef2013-10-15 09:50:08 +00006610 Var = getDerived().RebuildExceptionDecl(
6611 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6612 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006613 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006614 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006615 }
Mike Stump11289f42009-09-09 15:08:12 +00006616
Douglas Gregorebe10102009-08-20 07:17:43 +00006617 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006618 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006619 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006620 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006621
David Majnemer5f7efef2013-10-15 09:50:08 +00006622 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006623 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006624 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006625
David Majnemer5f7efef2013-10-15 09:50:08 +00006626 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006627}
Mike Stump11289f42009-09-09 15:08:12 +00006628
David Majnemer5f7efef2013-10-15 09:50:08 +00006629template <typename Derived>
6630StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006631 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006632 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006633 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006634 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006635
Douglas Gregorebe10102009-08-20 07:17:43 +00006636 // Transform the handlers.
6637 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006638 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006640 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006641 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006642 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006645 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006646 }
Mike Stump11289f42009-09-09 15:08:12 +00006647
David Majnemer5f7efef2013-10-15 09:50:08 +00006648 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006649 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006650 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006651
John McCallb268a282010-08-23 23:25:46 +00006652 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006653 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006654}
Mike Stump11289f42009-09-09 15:08:12 +00006655
Richard Smith02e85f32011-04-14 22:09:26 +00006656template<typename Derived>
6657StmtResult
6658TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6659 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6660 if (Range.isInvalid())
6661 return StmtError();
6662
6663 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6664 if (BeginEnd.isInvalid())
6665 return StmtError();
6666
6667 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6668 if (Cond.isInvalid())
6669 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006670 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006671 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006672 if (Cond.isInvalid())
6673 return StmtError();
6674 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006675 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006676
6677 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6678 if (Inc.isInvalid())
6679 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006680 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006681 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006682
6683 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6684 if (LoopVar.isInvalid())
6685 return StmtError();
6686
6687 StmtResult NewStmt = S;
6688 if (getDerived().AlwaysRebuild() ||
6689 Range.get() != S->getRangeStmt() ||
6690 BeginEnd.get() != S->getBeginEndStmt() ||
6691 Cond.get() != S->getCond() ||
6692 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006693 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006694 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6695 S->getColonLoc(), Range.get(),
6696 BeginEnd.get(), Cond.get(),
6697 Inc.get(), LoopVar.get(),
6698 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006699 if (NewStmt.isInvalid())
6700 return StmtError();
6701 }
Richard Smith02e85f32011-04-14 22:09:26 +00006702
6703 StmtResult Body = getDerived().TransformStmt(S->getBody());
6704 if (Body.isInvalid())
6705 return StmtError();
6706
6707 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6708 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006709 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006710 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6711 S->getColonLoc(), Range.get(),
6712 BeginEnd.get(), Cond.get(),
6713 Inc.get(), LoopVar.get(),
6714 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006715 if (NewStmt.isInvalid())
6716 return StmtError();
6717 }
Richard Smith02e85f32011-04-14 22:09:26 +00006718
6719 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006720 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006721
6722 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6723}
6724
John Wiegley1c0675e2011-04-28 01:08:34 +00006725template<typename Derived>
6726StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006727TreeTransform<Derived>::TransformMSDependentExistsStmt(
6728 MSDependentExistsStmt *S) {
6729 // Transform the nested-name-specifier, if any.
6730 NestedNameSpecifierLoc QualifierLoc;
6731 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006732 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006733 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6734 if (!QualifierLoc)
6735 return StmtError();
6736 }
6737
6738 // Transform the declaration name.
6739 DeclarationNameInfo NameInfo = S->getNameInfo();
6740 if (NameInfo.getName()) {
6741 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6742 if (!NameInfo.getName())
6743 return StmtError();
6744 }
6745
6746 // Check whether anything changed.
6747 if (!getDerived().AlwaysRebuild() &&
6748 QualifierLoc == S->getQualifierLoc() &&
6749 NameInfo.getName() == S->getNameInfo().getName())
6750 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006751
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006752 // Determine whether this name exists, if we can.
6753 CXXScopeSpec SS;
6754 SS.Adopt(QualifierLoc);
6755 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006756 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006757 case Sema::IER_Exists:
6758 if (S->isIfExists())
6759 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006760
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006761 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6762
6763 case Sema::IER_DoesNotExist:
6764 if (S->isIfNotExists())
6765 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006767 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006768
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006769 case Sema::IER_Dependent:
6770 Dependent = true;
6771 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006772
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006773 case Sema::IER_Error:
6774 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006776
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006777 // We need to continue with the instantiation, so do so now.
6778 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6779 if (SubStmt.isInvalid())
6780 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006781
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006782 // If we have resolved the name, just transform to the substatement.
6783 if (!Dependent)
6784 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006785
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006786 // The name is still dependent, so build a dependent expression again.
6787 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6788 S->isIfExists(),
6789 QualifierLoc,
6790 NameInfo,
6791 SubStmt.get());
6792}
6793
6794template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006795ExprResult
6796TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6797 NestedNameSpecifierLoc QualifierLoc;
6798 if (E->getQualifierLoc()) {
6799 QualifierLoc
6800 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6801 if (!QualifierLoc)
6802 return ExprError();
6803 }
6804
6805 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6806 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6807 if (!PD)
6808 return ExprError();
6809
6810 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6811 if (Base.isInvalid())
6812 return ExprError();
6813
6814 return new (SemaRef.getASTContext())
6815 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6816 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6817 QualifierLoc, E->getMemberLoc());
6818}
6819
David Majnemerfad8f482013-10-15 09:33:02 +00006820template <typename Derived>
6821StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006822 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006823 if (TryBlock.isInvalid())
6824 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006825
6826 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006827 if (Handler.isInvalid())
6828 return StmtError();
6829
David Majnemerfad8f482013-10-15 09:33:02 +00006830 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6831 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006832 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006833
Warren Huntf6be4cb2014-07-25 20:52:51 +00006834 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6835 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006836}
6837
David Majnemerfad8f482013-10-15 09:33:02 +00006838template <typename Derived>
6839StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006840 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006841 if (Block.isInvalid())
6842 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006843
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006844 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006845}
6846
David Majnemerfad8f482013-10-15 09:33:02 +00006847template <typename Derived>
6848StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006849 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006850 if (FilterExpr.isInvalid())
6851 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006852
David Majnemer7e755502013-10-15 09:30:14 +00006853 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006854 if (Block.isInvalid())
6855 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006856
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006857 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6858 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006859}
6860
David Majnemerfad8f482013-10-15 09:33:02 +00006861template <typename Derived>
6862StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6863 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006864 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6865 else
6866 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6867}
6868
Nico Weber9b982072014-07-07 00:12:30 +00006869template<typename Derived>
6870StmtResult
6871TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6872 return S;
6873}
6874
Alexander Musman64d33f12014-06-04 07:53:32 +00006875//===----------------------------------------------------------------------===//
6876// OpenMP directive transformation
6877//===----------------------------------------------------------------------===//
6878template <typename Derived>
6879StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6880 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006881
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006882 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006883 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006884 ArrayRef<OMPClause *> Clauses = D->clauses();
6885 TClauses.reserve(Clauses.size());
6886 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6887 I != E; ++I) {
6888 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006889 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006890 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006891 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006892 if (Clause)
6893 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006894 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006895 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006896 }
6897 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006898 StmtResult AssociatedStmt;
6899 if (D->hasAssociatedStmt()) {
6900 if (!D->getAssociatedStmt()) {
6901 return StmtError();
6902 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006903 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6904 /*CurScope=*/nullptr);
6905 StmtResult Body;
6906 {
6907 Sema::CompoundScopeRAII CompoundScope(getSema());
6908 Body = getDerived().TransformStmt(
6909 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6910 }
6911 AssociatedStmt =
6912 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006913 if (AssociatedStmt.isInvalid()) {
6914 return StmtError();
6915 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006916 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006917 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006918 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006919 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006920
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006921 // Transform directive name for 'omp critical' directive.
6922 DeclarationNameInfo DirName;
6923 if (D->getDirectiveKind() == OMPD_critical) {
6924 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6925 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6926 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006927 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6928 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6929 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006930 } else if (D->getDirectiveKind() == OMPD_cancel) {
6931 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006932 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006933
Alexander Musman64d33f12014-06-04 07:53:32 +00006934 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006935 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6936 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006937}
6938
Alexander Musman64d33f12014-06-04 07:53:32 +00006939template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006940StmtResult
6941TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6942 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006943 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6944 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6947 return Res;
6948}
6949
Alexander Musman64d33f12014-06-04 07:53:32 +00006950template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006951StmtResult
6952TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6953 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006954 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6955 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6957 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006958 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006959}
6960
Alexey Bataevf29276e2014-06-18 04:14:57 +00006961template <typename Derived>
6962StmtResult
6963TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6964 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006965 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6966 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6969 return Res;
6970}
6971
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006972template <typename Derived>
6973StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006974TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6975 DeclarationNameInfo DirName;
6976 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6977 D->getLocStart());
6978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6980 return Res;
6981}
6982
6983template <typename Derived>
6984StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006985TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6986 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006987 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6988 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6991 return Res;
6992}
6993
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006994template <typename Derived>
6995StmtResult
6996TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6997 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006998 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6999 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7001 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7002 return Res;
7003}
7004
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007005template <typename Derived>
7006StmtResult
7007TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7008 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007009 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7010 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7013 return Res;
7014}
7015
Alexey Bataev4acb8592014-07-07 13:01:15 +00007016template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007017StmtResult
7018TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7019 DeclarationNameInfo DirName;
7020 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7021 D->getLocStart());
7022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7024 return Res;
7025}
7026
7027template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007028StmtResult
7029TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7030 getDerived().getSema().StartOpenMPDSABlock(
7031 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7034 return Res;
7035}
7036
7037template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007038StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7039 OMPParallelForDirective *D) {
7040 DeclarationNameInfo DirName;
7041 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7042 nullptr, D->getLocStart());
7043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7045 return Res;
7046}
7047
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007048template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007049StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7050 OMPParallelForSimdDirective *D) {
7051 DeclarationNameInfo DirName;
7052 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7053 nullptr, D->getLocStart());
7054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7056 return Res;
7057}
7058
7059template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007060StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7061 OMPParallelSectionsDirective *D) {
7062 DeclarationNameInfo DirName;
7063 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7064 nullptr, D->getLocStart());
7065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7067 return Res;
7068}
7069
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007070template <typename Derived>
7071StmtResult
7072TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7073 DeclarationNameInfo DirName;
7074 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7075 D->getLocStart());
7076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7078 return Res;
7079}
7080
Alexey Bataev68446b72014-07-18 07:47:19 +00007081template <typename Derived>
7082StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7083 OMPTaskyieldDirective *D) {
7084 DeclarationNameInfo DirName;
7085 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7086 D->getLocStart());
7087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7089 return Res;
7090}
7091
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007092template <typename Derived>
7093StmtResult
7094TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7095 DeclarationNameInfo DirName;
7096 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7097 D->getLocStart());
7098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7100 return Res;
7101}
7102
Alexey Bataev2df347a2014-07-18 10:17:07 +00007103template <typename Derived>
7104StmtResult
7105TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7106 DeclarationNameInfo DirName;
7107 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7108 D->getLocStart());
7109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7111 return Res;
7112}
7113
Alexey Bataev6125da92014-07-21 11:26:11 +00007114template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007115StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7116 OMPTaskgroupDirective *D) {
7117 DeclarationNameInfo DirName;
7118 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7119 D->getLocStart());
7120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7122 return Res;
7123}
7124
7125template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007126StmtResult
7127TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7128 DeclarationNameInfo DirName;
7129 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7130 D->getLocStart());
7131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7133 return Res;
7134}
7135
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007136template <typename Derived>
7137StmtResult
7138TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7139 DeclarationNameInfo DirName;
7140 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7141 D->getLocStart());
7142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7144 return Res;
7145}
7146
Alexey Bataev0162e452014-07-22 10:10:35 +00007147template <typename Derived>
7148StmtResult
7149TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7150 DeclarationNameInfo DirName;
7151 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7152 D->getLocStart());
7153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7155 return Res;
7156}
7157
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007158template <typename Derived>
7159StmtResult
7160TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7161 DeclarationNameInfo DirName;
7162 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7163 D->getLocStart());
7164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7166 return Res;
7167}
7168
Alexey Bataev13314bf2014-10-09 04:18:56 +00007169template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007170StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7171 OMPTargetDataDirective *D) {
7172 DeclarationNameInfo DirName;
7173 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7174 D->getLocStart());
7175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7177 return Res;
7178}
7179
7180template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007181StmtResult
7182TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7183 DeclarationNameInfo DirName;
7184 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7185 D->getLocStart());
7186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7188 return Res;
7189}
7190
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007191template <typename Derived>
7192StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7193 OMPCancellationPointDirective *D) {
7194 DeclarationNameInfo DirName;
7195 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7196 nullptr, D->getLocStart());
7197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7199 return Res;
7200}
7201
Alexey Bataev80909872015-07-02 11:25:17 +00007202template <typename Derived>
7203StmtResult
7204TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7205 DeclarationNameInfo DirName;
7206 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7207 D->getLocStart());
7208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7210 return Res;
7211}
7212
Alexander Musman64d33f12014-06-04 07:53:32 +00007213//===----------------------------------------------------------------------===//
7214// OpenMP clause transformation
7215//===----------------------------------------------------------------------===//
7216template <typename Derived>
7217OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007218 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7219 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007220 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007221 return getDerived().RebuildOMPIfClause(
7222 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7223 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007224}
7225
Alexander Musman64d33f12014-06-04 07:53:32 +00007226template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007227OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7228 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7229 if (Cond.isInvalid())
7230 return nullptr;
7231 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7232 C->getLParenLoc(), C->getLocEnd());
7233}
7234
7235template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007236OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007237TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7238 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7239 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007240 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007241 return getDerived().RebuildOMPNumThreadsClause(
7242 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007243}
7244
Alexey Bataev62c87d22014-03-21 04:51:18 +00007245template <typename Derived>
7246OMPClause *
7247TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7248 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7249 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007250 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007251 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007252 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007253}
7254
Alexander Musman8bd31e62014-05-27 15:12:19 +00007255template <typename Derived>
7256OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007257TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7258 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7259 if (E.isInvalid())
7260 return nullptr;
7261 return getDerived().RebuildOMPSimdlenClause(
7262 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7263}
7264
7265template <typename Derived>
7266OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007267TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7268 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7269 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007270 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007271 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007272 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007273}
7274
Alexander Musman64d33f12014-06-04 07:53:32 +00007275template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007276OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007277TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007278 return getDerived().RebuildOMPDefaultClause(
7279 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7280 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007281}
7282
Alexander Musman64d33f12014-06-04 07:53:32 +00007283template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007284OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007285TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007286 return getDerived().RebuildOMPProcBindClause(
7287 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7288 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007289}
7290
Alexander Musman64d33f12014-06-04 07:53:32 +00007291template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007292OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007293TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7294 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7295 if (E.isInvalid())
7296 return nullptr;
7297 return getDerived().RebuildOMPScheduleClause(
7298 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7299 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7300}
7301
7302template <typename Derived>
7303OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007304TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007305 ExprResult E;
7306 if (auto *Num = C->getNumForLoops()) {
7307 E = getDerived().TransformExpr(Num);
7308 if (E.isInvalid())
7309 return nullptr;
7310 }
7311 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7312 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007313}
7314
7315template <typename Derived>
7316OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007317TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7318 // No need to rebuild this clause, no template-dependent parameters.
7319 return C;
7320}
7321
7322template <typename Derived>
7323OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007324TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7325 // No need to rebuild this clause, no template-dependent parameters.
7326 return C;
7327}
7328
7329template <typename Derived>
7330OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007331TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7332 // No need to rebuild this clause, no template-dependent parameters.
7333 return C;
7334}
7335
7336template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007337OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7338 // No need to rebuild this clause, no template-dependent parameters.
7339 return C;
7340}
7341
7342template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007343OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7344 // No need to rebuild this clause, no template-dependent parameters.
7345 return C;
7346}
7347
7348template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007349OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007350TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7351 // No need to rebuild this clause, no template-dependent parameters.
7352 return C;
7353}
7354
7355template <typename Derived>
7356OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007357TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7358 // No need to rebuild this clause, no template-dependent parameters.
7359 return C;
7360}
7361
7362template <typename Derived>
7363OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007364TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7365 // No need to rebuild this clause, no template-dependent parameters.
7366 return C;
7367}
7368
7369template <typename Derived>
7370OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007371TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7372 // No need to rebuild this clause, no template-dependent parameters.
7373 return C;
7374}
7375
7376template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007377OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7378 // No need to rebuild this clause, no template-dependent parameters.
7379 return C;
7380}
7381
7382template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007383OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007384TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007385 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007386 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007387 for (auto *VE : C->varlists()) {
7388 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007389 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007390 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007391 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007392 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007393 return getDerived().RebuildOMPPrivateClause(
7394 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007395}
7396
Alexander Musman64d33f12014-06-04 07:53:32 +00007397template <typename Derived>
7398OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7399 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007400 llvm::SmallVector<Expr *, 16> Vars;
7401 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007402 for (auto *VE : C->varlists()) {
7403 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007404 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007405 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007406 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007407 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007408 return getDerived().RebuildOMPFirstprivateClause(
7409 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007410}
7411
Alexander Musman64d33f12014-06-04 07:53:32 +00007412template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007413OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007414TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7415 llvm::SmallVector<Expr *, 16> Vars;
7416 Vars.reserve(C->varlist_size());
7417 for (auto *VE : C->varlists()) {
7418 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7419 if (EVar.isInvalid())
7420 return nullptr;
7421 Vars.push_back(EVar.get());
7422 }
7423 return getDerived().RebuildOMPLastprivateClause(
7424 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7425}
7426
7427template <typename Derived>
7428OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007429TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7430 llvm::SmallVector<Expr *, 16> Vars;
7431 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007432 for (auto *VE : C->varlists()) {
7433 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007434 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007435 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007436 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007437 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007438 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7439 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007440}
7441
Alexander Musman64d33f12014-06-04 07:53:32 +00007442template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007443OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007444TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7445 llvm::SmallVector<Expr *, 16> Vars;
7446 Vars.reserve(C->varlist_size());
7447 for (auto *VE : C->varlists()) {
7448 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7449 if (EVar.isInvalid())
7450 return nullptr;
7451 Vars.push_back(EVar.get());
7452 }
7453 CXXScopeSpec ReductionIdScopeSpec;
7454 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7455
7456 DeclarationNameInfo NameInfo = C->getNameInfo();
7457 if (NameInfo.getName()) {
7458 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7459 if (!NameInfo.getName())
7460 return nullptr;
7461 }
7462 return getDerived().RebuildOMPReductionClause(
7463 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7464 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7465}
7466
7467template <typename Derived>
7468OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007469TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7470 llvm::SmallVector<Expr *, 16> Vars;
7471 Vars.reserve(C->varlist_size());
7472 for (auto *VE : C->varlists()) {
7473 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7474 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007475 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007476 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007477 }
7478 ExprResult Step = getDerived().TransformExpr(C->getStep());
7479 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007480 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007481 return getDerived().RebuildOMPLinearClause(
7482 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7483 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007484}
7485
Alexander Musman64d33f12014-06-04 07:53:32 +00007486template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007487OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007488TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7489 llvm::SmallVector<Expr *, 16> Vars;
7490 Vars.reserve(C->varlist_size());
7491 for (auto *VE : C->varlists()) {
7492 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7493 if (EVar.isInvalid())
7494 return nullptr;
7495 Vars.push_back(EVar.get());
7496 }
7497 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7498 if (Alignment.isInvalid())
7499 return nullptr;
7500 return getDerived().RebuildOMPAlignedClause(
7501 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7502 C->getColonLoc(), C->getLocEnd());
7503}
7504
Alexander Musman64d33f12014-06-04 07:53:32 +00007505template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007506OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007507TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7508 llvm::SmallVector<Expr *, 16> Vars;
7509 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007510 for (auto *VE : C->varlists()) {
7511 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007512 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007513 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007514 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007515 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007516 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7517 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007518}
7519
Alexey Bataevbae9a792014-06-27 10:37:06 +00007520template <typename Derived>
7521OMPClause *
7522TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7523 llvm::SmallVector<Expr *, 16> Vars;
7524 Vars.reserve(C->varlist_size());
7525 for (auto *VE : C->varlists()) {
7526 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7527 if (EVar.isInvalid())
7528 return nullptr;
7529 Vars.push_back(EVar.get());
7530 }
7531 return getDerived().RebuildOMPCopyprivateClause(
7532 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7533}
7534
Alexey Bataev6125da92014-07-21 11:26:11 +00007535template <typename Derived>
7536OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7537 llvm::SmallVector<Expr *, 16> Vars;
7538 Vars.reserve(C->varlist_size());
7539 for (auto *VE : C->varlists()) {
7540 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7541 if (EVar.isInvalid())
7542 return nullptr;
7543 Vars.push_back(EVar.get());
7544 }
7545 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7546 C->getLParenLoc(), C->getLocEnd());
7547}
7548
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007549template <typename Derived>
7550OMPClause *
7551TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7552 llvm::SmallVector<Expr *, 16> Vars;
7553 Vars.reserve(C->varlist_size());
7554 for (auto *VE : C->varlists()) {
7555 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7556 if (EVar.isInvalid())
7557 return nullptr;
7558 Vars.push_back(EVar.get());
7559 }
7560 return getDerived().RebuildOMPDependClause(
7561 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7562 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7563}
7564
Michael Wonge710d542015-08-07 16:16:36 +00007565template <typename Derived>
7566OMPClause *
7567TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7568 ExprResult E = getDerived().TransformExpr(C->getDevice());
7569 if (E.isInvalid())
7570 return nullptr;
7571 return getDerived().RebuildOMPDeviceClause(
7572 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7573}
7574
Douglas Gregorebe10102009-08-20 07:17:43 +00007575//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007576// Expression transformation
7577//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007578template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007579ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007580TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007581 if (!E->isTypeDependent())
7582 return E;
7583
7584 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7585 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007586}
Mike Stump11289f42009-09-09 15:08:12 +00007587
7588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007590TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007591 NestedNameSpecifierLoc QualifierLoc;
7592 if (E->getQualifierLoc()) {
7593 QualifierLoc
7594 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7595 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007596 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007597 }
John McCallce546572009-12-08 09:08:17 +00007598
7599 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007600 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7601 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007604
John McCall815039a2010-08-17 21:27:17 +00007605 DeclarationNameInfo NameInfo = E->getNameInfo();
7606 if (NameInfo.getName()) {
7607 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7608 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007609 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007610 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007611
7612 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007613 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007614 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007615 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007616 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007617
7618 // Mark it referenced in the new context regardless.
7619 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007620 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007621
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007622 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007623 }
John McCallce546572009-12-08 09:08:17 +00007624
Craig Topperc3ec1492014-05-26 06:22:03 +00007625 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007626 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007627 TemplateArgs = &TransArgs;
7628 TransArgs.setLAngleLoc(E->getLAngleLoc());
7629 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007630 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7631 E->getNumTemplateArgs(),
7632 TransArgs))
7633 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007634 }
7635
Chad Rosier1dcde962012-08-08 18:46:20 +00007636 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007637 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregora16548e2009-08-11 05:31:07 +00007640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007641ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007642TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007643 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007644}
Mike Stump11289f42009-09-09 15:08:12 +00007645
Douglas Gregora16548e2009-08-11 05:31:07 +00007646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007648TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007649 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007650}
Mike Stump11289f42009-09-09 15:08:12 +00007651
Douglas Gregora16548e2009-08-11 05:31:07 +00007652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007654TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007655 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007656}
Mike Stump11289f42009-09-09 15:08:12 +00007657
Douglas Gregora16548e2009-08-11 05:31:07 +00007658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007660TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007661 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007662}
Mike Stump11289f42009-09-09 15:08:12 +00007663
Douglas Gregora16548e2009-08-11 05:31:07 +00007664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007667 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007668}
7669
7670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007671ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007672TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007673 if (FunctionDecl *FD = E->getDirectCallee())
7674 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007675 return SemaRef.MaybeBindToTemporary(E);
7676}
7677
7678template<typename Derived>
7679ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007680TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7681 ExprResult ControllingExpr =
7682 getDerived().TransformExpr(E->getControllingExpr());
7683 if (ControllingExpr.isInvalid())
7684 return ExprError();
7685
Chris Lattner01cf8db2011-07-20 06:58:45 +00007686 SmallVector<Expr *, 4> AssocExprs;
7687 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007688 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7689 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7690 if (TS) {
7691 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7692 if (!AssocType)
7693 return ExprError();
7694 AssocTypes.push_back(AssocType);
7695 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007696 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007697 }
7698
7699 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7700 if (AssocExpr.isInvalid())
7701 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007702 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007703 }
7704
7705 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7706 E->getDefaultLoc(),
7707 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007708 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007709 AssocTypes,
7710 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007711}
7712
7713template<typename Derived>
7714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007715TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007716 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007717 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007719
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007721 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007722
John McCallb268a282010-08-23 23:25:46 +00007723 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 E->getRParen());
7725}
7726
Richard Smithdb2630f2012-10-21 03:28:35 +00007727/// \brief The operand of a unary address-of operator has special rules: it's
7728/// allowed to refer to a non-static member of a class even if there's no 'this'
7729/// object available.
7730template<typename Derived>
7731ExprResult
7732TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7733 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007734 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007735 else
7736 return getDerived().TransformExpr(E);
7737}
7738
Mike Stump11289f42009-09-09 15:08:12 +00007739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007741TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007742 ExprResult SubExpr;
7743 if (E->getOpcode() == UO_AddrOf)
7744 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7745 else
7746 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007747 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007749
Douglas Gregora16548e2009-08-11 05:31:07 +00007750 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007751 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007752
Douglas Gregora16548e2009-08-11 05:31:07 +00007753 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7754 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007755 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007756}
Mike Stump11289f42009-09-09 15:08:12 +00007757
Douglas Gregora16548e2009-08-11 05:31:07 +00007758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007759ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007760TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7761 // Transform the type.
7762 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7763 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007765
Douglas Gregor882211c2010-04-28 22:16:22 +00007766 // Transform all of the components into components similar to what the
7767 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007768 // FIXME: It would be slightly more efficient in the non-dependent case to
7769 // just map FieldDecls, rather than requiring the rebuilder to look for
7770 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007771 // template code that we don't care.
7772 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007773 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007774 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007775 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007776 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7777 const Node &ON = E->getComponent(I);
7778 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007779 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007780 Comp.LocStart = ON.getSourceRange().getBegin();
7781 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007782 switch (ON.getKind()) {
7783 case Node::Array: {
7784 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007785 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007786 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007787 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007788
Douglas Gregor882211c2010-04-28 22:16:22 +00007789 ExprChanged = ExprChanged || Index.get() != FromIndex;
7790 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007791 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007792 break;
7793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007794
Douglas Gregor882211c2010-04-28 22:16:22 +00007795 case Node::Field:
7796 case Node::Identifier:
7797 Comp.isBrackets = false;
7798 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007799 if (!Comp.U.IdentInfo)
7800 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007801
Douglas Gregor882211c2010-04-28 22:16:22 +00007802 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007803
Douglas Gregord1702062010-04-29 00:18:15 +00007804 case Node::Base:
7805 // Will be recomputed during the rebuild.
7806 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007808
Douglas Gregor882211c2010-04-28 22:16:22 +00007809 Components.push_back(Comp);
7810 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007811
Douglas Gregor882211c2010-04-28 22:16:22 +00007812 // If nothing changed, retain the existing expression.
7813 if (!getDerived().AlwaysRebuild() &&
7814 Type == E->getTypeSourceInfo() &&
7815 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007816 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007817
Douglas Gregor882211c2010-04-28 22:16:22 +00007818 // Build a new offsetof expression.
7819 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00007820 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00007821}
7822
7823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007824ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007825TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00007826 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00007827 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007828 return E;
John McCall8d69a212010-11-15 23:31:06 +00007829}
7830
7831template<typename Derived>
7832ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007833TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7834 return E;
7835}
7836
7837template<typename Derived>
7838ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007839TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007840 // Rebuild the syntactic form. The original syntactic form has
7841 // opaque-value expressions in it, so strip those away and rebuild
7842 // the result. This is a really awful way of doing this, but the
7843 // better solution (rebuilding the semantic expressions and
7844 // rebinding OVEs as necessary) doesn't work; we'd need
7845 // TreeTransform to not strip away implicit conversions.
7846 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7847 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007848 if (result.isInvalid()) return ExprError();
7849
7850 // If that gives us a pseudo-object result back, the pseudo-object
7851 // expression must have been an lvalue-to-rvalue conversion which we
7852 // should reapply.
7853 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007854 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007855
7856 return result;
7857}
7858
7859template<typename Derived>
7860ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007861TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7862 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007864 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007865
John McCallbcd03502009-12-07 02:54:59 +00007866 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007867 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007869
John McCall4c98fd82009-11-04 07:28:41 +00007870 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007871 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007872
Peter Collingbournee190dee2011-03-11 19:24:49 +00007873 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7874 E->getKind(),
7875 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 }
Mike Stump11289f42009-09-09 15:08:12 +00007877
Eli Friedmane4f22df2012-02-29 04:03:55 +00007878 // C++0x [expr.sizeof]p1:
7879 // The operand is either an expression, which is an unevaluated operand
7880 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007881 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7882 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007883
Reid Kleckner32506ed2014-06-12 23:03:48 +00007884 // Try to recover if we have something like sizeof(T::X) where X is a type.
7885 // Notably, there must be *exactly* one set of parens if X is a type.
7886 TypeSourceInfo *RecoveryTSI = nullptr;
7887 ExprResult SubExpr;
7888 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7889 if (auto *DRE =
7890 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7891 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7892 PE, DRE, false, &RecoveryTSI);
7893 else
7894 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7895
7896 if (RecoveryTSI) {
7897 return getDerived().RebuildUnaryExprOrTypeTrait(
7898 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7899 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007901
Eli Friedmane4f22df2012-02-29 04:03:55 +00007902 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007903 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007904
Peter Collingbournee190dee2011-03-11 19:24:49 +00007905 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7906 E->getOperatorLoc(),
7907 E->getKind(),
7908 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007909}
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007914 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007917
John McCalldadc5752010-08-24 06:29:42 +00007918 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007920 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007921
7922
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 if (!getDerived().AlwaysRebuild() &&
7924 LHS.get() == E->getLHS() &&
7925 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007926 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007927
John McCallb268a282010-08-23 23:25:46 +00007928 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007930 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 E->getRBracketLoc());
7932}
Mike Stump11289f42009-09-09 15:08:12 +00007933
Alexey Bataev1a3320e2015-08-25 14:24:04 +00007934template <typename Derived>
7935ExprResult
7936TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
7937 ExprResult Base = getDerived().TransformExpr(E->getBase());
7938 if (Base.isInvalid())
7939 return ExprError();
7940
7941 ExprResult LowerBound;
7942 if (E->getLowerBound()) {
7943 LowerBound = getDerived().TransformExpr(E->getLowerBound());
7944 if (LowerBound.isInvalid())
7945 return ExprError();
7946 }
7947
7948 ExprResult Length;
7949 if (E->getLength()) {
7950 Length = getDerived().TransformExpr(E->getLength());
7951 if (Length.isInvalid())
7952 return ExprError();
7953 }
7954
7955 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
7956 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
7957 return E;
7958
7959 return getDerived().RebuildOMPArraySectionExpr(
7960 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
7961 Length.get(), E->getRBracketLoc());
7962}
7963
Mike Stump11289f42009-09-09 15:08:12 +00007964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007966TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007968 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007971
7972 // Transform arguments.
7973 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007974 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007975 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007976 &ArgChanged))
7977 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007978
Douglas Gregora16548e2009-08-11 05:31:07 +00007979 if (!getDerived().AlwaysRebuild() &&
7980 Callee.get() == E->getCallee() &&
7981 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007982 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007983
Douglas Gregora16548e2009-08-11 05:31:07 +00007984 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007985 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007986 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007987 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007988 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007989 E->getRParenLoc());
7990}
Mike Stump11289f42009-09-09 15:08:12 +00007991
7992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007994TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007995 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007996 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007998
Douglas Gregorea972d32011-02-28 21:54:11 +00007999 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008000 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008001 QualifierLoc
8002 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008003
Douglas Gregorea972d32011-02-28 21:54:11 +00008004 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008005 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008006 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008007 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008008
Eli Friedman2cfcef62009-12-04 06:40:45 +00008009 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008010 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8011 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008012 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008014
John McCall16df1e52010-03-30 21:47:33 +00008015 NamedDecl *FoundDecl = E->getFoundDecl();
8016 if (FoundDecl == E->getMemberDecl()) {
8017 FoundDecl = Member;
8018 } else {
8019 FoundDecl = cast_or_null<NamedDecl>(
8020 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8021 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008022 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008023 }
8024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 if (!getDerived().AlwaysRebuild() &&
8026 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008027 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008028 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008029 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008030 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008031
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008032 // Mark it referenced in the new context regardless.
8033 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008034 SemaRef.MarkMemberReferenced(E);
8035
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008036 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008037 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008038
John McCall6b51f282009-11-23 01:53:49 +00008039 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008040 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008041 TransArgs.setLAngleLoc(E->getLAngleLoc());
8042 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008043 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8044 E->getNumTemplateArgs(),
8045 TransArgs))
8046 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008050 SourceLocation FakeOperatorLoc =
8051 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008052
John McCall38836f02010-01-15 08:34:02 +00008053 // FIXME: to do this check properly, we will need to preserve the
8054 // first-qualifier-in-scope here, just in case we had a dependent
8055 // base (and therefore couldn't do the check) and a
8056 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008057 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008058
John McCallb268a282010-08-23 23:25:46 +00008059 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008060 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008061 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008062 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008063 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008064 Member,
John McCall16df1e52010-03-30 21:47:33 +00008065 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008066 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008067 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008068 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008069}
Mike Stump11289f42009-09-09 15:08:12 +00008070
Douglas Gregora16548e2009-08-11 05:31:07 +00008071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008073TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008074 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008075 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008077
John McCalldadc5752010-08-24 06:29:42 +00008078 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008079 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008080 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008081
Douglas Gregora16548e2009-08-11 05:31:07 +00008082 if (!getDerived().AlwaysRebuild() &&
8083 LHS.get() == E->getLHS() &&
8084 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008085 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008086
Lang Hames5de91cc2012-10-02 04:45:10 +00008087 Sema::FPContractStateRAII FPContractState(getSema());
8088 getSema().FPFeatures.fp_contract = E->isFPContractable();
8089
Douglas Gregora16548e2009-08-11 05:31:07 +00008090 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008091 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008092}
8093
Mike Stump11289f42009-09-09 15:08:12 +00008094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008096TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008097 CompoundAssignOperator *E) {
8098 return getDerived().TransformBinaryOperator(E);
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 McCallc07a0c72011-02-17 10:25:35 +00008102ExprResult TreeTransform<Derived>::
8103TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8104 // Just rebuild the common and RHS expressions and see whether we
8105 // get any changes.
8106
8107 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8108 if (commonExpr.isInvalid())
8109 return ExprError();
8110
8111 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8112 if (rhs.isInvalid())
8113 return ExprError();
8114
8115 if (!getDerived().AlwaysRebuild() &&
8116 commonExpr.get() == e->getCommon() &&
8117 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008118 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008119
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008120 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008121 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008122 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008123 e->getColonLoc(),
8124 rhs.get());
8125}
8126
8127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008129TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008130 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008133
John McCalldadc5752010-08-24 06:29:42 +00008134 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008137
John McCalldadc5752010-08-24 06:29:42 +00008138 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008140 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 if (!getDerived().AlwaysRebuild() &&
8143 Cond.get() == E->getCond() &&
8144 LHS.get() == E->getLHS() &&
8145 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008146 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008147
John McCallb268a282010-08-23 23:25:46 +00008148 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008149 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008150 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008151 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008152 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008153}
Mike Stump11289f42009-09-09 15:08:12 +00008154
8155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008157TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008158 // Implicit casts are eliminated during transformation, since they
8159 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008160 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008161}
Mike Stump11289f42009-09-09 15:08:12 +00008162
Douglas Gregora16548e2009-08-11 05:31:07 +00008163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008165TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008166 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8167 if (!Type)
8168 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008169
John McCalldadc5752010-08-24 06:29:42 +00008170 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008171 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008174
Douglas Gregora16548e2009-08-11 05:31:07 +00008175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008176 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008178 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008179
John McCall97513962010-01-15 18:39:57 +00008180 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008181 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008182 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008183 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008184}
Mike Stump11289f42009-09-09 15:08:12 +00008185
Douglas Gregora16548e2009-08-11 05:31:07 +00008186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008188TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008189 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8190 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8191 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008193
John McCalldadc5752010-08-24 06:29:42 +00008194 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008197
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008199 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008201 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008202
John McCall5d7aa7f2010-01-19 22:33:45 +00008203 // Note: the expression type doesn't necessarily match the
8204 // type-as-written, but that's okay, because it should always be
8205 // derivable from the initializer.
8206
John McCalle15bbff2010-01-18 19:35:47 +00008207 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008208 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008209 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008210}
Mike Stump11289f42009-09-09 15:08:12 +00008211
Douglas Gregora16548e2009-08-11 05:31:07 +00008212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008214TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008215 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008216 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 if (!getDerived().AlwaysRebuild() &&
8220 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008221 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008222
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008224 SourceLocation FakeOperatorLoc =
8225 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008226 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 E->getAccessorLoc(),
8228 E->getAccessor());
8229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
Douglas Gregora16548e2009-08-11 05:31:07 +00008231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008233TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008234 if (InitListExpr *Syntactic = E->getSyntacticForm())
8235 E = Syntactic;
8236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008238
Benjamin Kramerf0623432012-08-23 22:51:59 +00008239 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008240 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008241 Inits, &InitChanged))
8242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008243
Richard Smith520449d2015-02-05 06:15:50 +00008244 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8245 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8246 // in some cases. We can't reuse it in general, because the syntactic and
8247 // semantic forms are linked, and we can't know that semantic form will
8248 // match even if the syntactic form does.
8249 }
Mike Stump11289f42009-09-09 15:08:12 +00008250
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008251 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008252 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008257TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008258 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregorebe10102009-08-20 07:17:43 +00008260 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008261 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008264
Douglas Gregorebe10102009-08-20 07:17:43 +00008265 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008266 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008267 bool ExprChanged = false;
8268 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8269 DEnd = E->designators_end();
8270 D != DEnd; ++D) {
8271 if (D->isFieldDesignator()) {
8272 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8273 D->getDotLoc(),
8274 D->getFieldLoc()));
8275 continue;
8276 }
Mike Stump11289f42009-09-09 15:08:12 +00008277
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008279 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008282
8283 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008287 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 continue;
8289 }
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008292 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8294 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008296
John McCalldadc5752010-08-24 06:29:42 +00008297 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008298 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008300
8301 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 End.get(),
8303 D->getLBracketLoc(),
8304 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008305
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8307 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008308
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008309 ArrayExprs.push_back(Start.get());
8310 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 }
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 if (!getDerived().AlwaysRebuild() &&
8314 Init.get() == E->getInit() &&
8315 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008316 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008317
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008318 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008319 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008320 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008321}
Mike Stump11289f42009-09-09 15:08:12 +00008322
Yunzhong Gaocb779302015-06-10 00:27:52 +00008323// Seems that if TransformInitListExpr() only works on the syntactic form of an
8324// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8325template<typename Derived>
8326ExprResult
8327TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8328 DesignatedInitUpdateExpr *E) {
8329 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8330 "initializer");
8331 return ExprError();
8332}
8333
8334template<typename Derived>
8335ExprResult
8336TreeTransform<Derived>::TransformNoInitExpr(
8337 NoInitExpr *E) {
8338 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8339 return ExprError();
8340}
8341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008343ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008344TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008345 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008346 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008347
Douglas Gregor3da3c062009-10-28 00:29:27 +00008348 // FIXME: Will we ever have proper type location here? Will we actually
8349 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 QualType T = getDerived().TransformType(E->getType());
8351 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (!getDerived().AlwaysRebuild() &&
8355 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008356 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008357
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 return getDerived().RebuildImplicitValueInitExpr(T);
8359}
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008363TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008364 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8365 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008367
John McCalldadc5752010-08-24 06:29:42 +00008368 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008371
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008373 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008376
John McCallb268a282010-08-23 23:25:46 +00008377 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008378 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008379}
8380
8381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008383TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008385 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008386 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8387 &ArgumentChanged))
8388 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008389
Douglas Gregora16548e2009-08-11 05:31:07 +00008390 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008391 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 E->getRParenLoc());
8393}
Mike Stump11289f42009-09-09 15:08:12 +00008394
Douglas Gregora16548e2009-08-11 05:31:07 +00008395/// \brief Transform an address-of-label expression.
8396///
8397/// By default, the transformation of an address-of-label expression always
8398/// rebuilds the expression, so that the label identifier can be resolved to
8399/// the corresponding label statement by semantic analysis.
8400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008402TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008403 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8404 E->getLabel());
8405 if (!LD)
8406 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008407
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008409 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008410}
Mike Stump11289f42009-09-09 15:08:12 +00008411
8412template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008414TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008415 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008416 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008417 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008418 if (SubStmt.isInvalid()) {
8419 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008420 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008421 }
Mike Stump11289f42009-09-09 15:08:12 +00008422
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008424 SubStmt.get() == E->getSubStmt()) {
8425 // Calling this an 'error' is unintuitive, but it does the right thing.
8426 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008427 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008428 }
Mike Stump11289f42009-09-09 15:08:12 +00008429
8430 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008431 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008432 E->getRParenLoc());
8433}
Mike Stump11289f42009-09-09 15:08:12 +00008434
Douglas Gregora16548e2009-08-11 05:31:07 +00008435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008437TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008438 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008439 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008441
John McCalldadc5752010-08-24 06:29:42 +00008442 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008445
John McCalldadc5752010-08-24 06:29:42 +00008446 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008447 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008449
Douglas Gregora16548e2009-08-11 05:31:07 +00008450 if (!getDerived().AlwaysRebuild() &&
8451 Cond.get() == E->getCond() &&
8452 LHS.get() == E->getLHS() &&
8453 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008454 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008455
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008457 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008458 E->getRParenLoc());
8459}
Mike Stump11289f42009-09-09 15:08:12 +00008460
Douglas Gregora16548e2009-08-11 05:31:07 +00008461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008463TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008464 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008465}
8466
8467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008469TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008470 switch (E->getOperator()) {
8471 case OO_New:
8472 case OO_Delete:
8473 case OO_Array_New:
8474 case OO_Array_Delete:
8475 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008477 case OO_Call: {
8478 // This is a call to an object's operator().
8479 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8480
8481 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008482 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008483 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008484 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008485
8486 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008487 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8488 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008489
8490 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008491 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008492 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008493 Args))
8494 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008495
John McCallb268a282010-08-23 23:25:46 +00008496 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008497 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008498 E->getLocEnd());
8499 }
8500
8501#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8502 case OO_##Name:
8503#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8504#include "clang/Basic/OperatorKinds.def"
8505 case OO_Subscript:
8506 // Handled below.
8507 break;
8508
8509 case OO_Conditional:
8510 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008511
8512 case OO_None:
8513 case NUM_OVERLOADED_OPERATORS:
8514 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008515 }
8516
John McCalldadc5752010-08-24 06:29:42 +00008517 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008520
Richard Smithdb2630f2012-10-21 03:28:35 +00008521 ExprResult First;
8522 if (E->getOperator() == OO_Amp)
8523 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8524 else
8525 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008527 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008528
John McCalldadc5752010-08-24 06:29:42 +00008529 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 if (E->getNumArgs() == 2) {
8531 Second = getDerived().TransformExpr(E->getArg(1));
8532 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008533 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 }
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 if (!getDerived().AlwaysRebuild() &&
8537 Callee.get() == E->getCallee() &&
8538 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008539 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008540 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008541
Lang Hames5de91cc2012-10-02 04:45:10 +00008542 Sema::FPContractStateRAII FPContractState(getSema());
8543 getSema().FPFeatures.fp_contract = E->isFPContractable();
8544
Douglas Gregora16548e2009-08-11 05:31:07 +00008545 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8546 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008547 Callee.get(),
8548 First.get(),
8549 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008550}
Mike Stump11289f42009-09-09 15:08:12 +00008551
Douglas Gregora16548e2009-08-11 05:31:07 +00008552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008554TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8555 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008556}
Mike Stump11289f42009-09-09 15:08:12 +00008557
Douglas Gregora16548e2009-08-11 05:31:07 +00008558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008559ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008560TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8561 // Transform the callee.
8562 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8563 if (Callee.isInvalid())
8564 return ExprError();
8565
8566 // Transform exec config.
8567 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8568 if (EC.isInvalid())
8569 return ExprError();
8570
8571 // Transform arguments.
8572 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008573 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008574 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008575 &ArgChanged))
8576 return ExprError();
8577
8578 if (!getDerived().AlwaysRebuild() &&
8579 Callee.get() == E->getCallee() &&
8580 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008581 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008582
8583 // FIXME: Wrong source location information for the '('.
8584 SourceLocation FakeLParenLoc
8585 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8586 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008587 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008588 E->getRParenLoc(), EC.get());
8589}
8590
8591template<typename Derived>
8592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008594 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8595 if (!Type)
8596 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008597
John McCalldadc5752010-08-24 06:29:42 +00008598 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008599 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008600 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008602
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008604 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008606 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008607 return getDerived().RebuildCXXNamedCastExpr(
8608 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8609 Type, E->getAngleBrackets().getEnd(),
8610 // FIXME. this should be '(' location
8611 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008612}
Mike Stump11289f42009-09-09 15:08:12 +00008613
Douglas Gregora16548e2009-08-11 05:31:07 +00008614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008616TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8617 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008618}
Mike Stump11289f42009-09-09 15:08:12 +00008619
8620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008621ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008622TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8623 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008624}
8625
Douglas Gregora16548e2009-08-11 05:31:07 +00008626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008627ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008628TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008629 CXXReinterpretCastExpr *E) {
8630 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008631}
Mike Stump11289f42009-09-09 15:08:12 +00008632
Douglas Gregora16548e2009-08-11 05:31:07 +00008633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008635TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8636 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008637}
Mike Stump11289f42009-09-09 15:08:12 +00008638
Douglas Gregora16548e2009-08-11 05:31:07 +00008639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008640ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008641TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008642 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008643 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8644 if (!Type)
8645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008646
John McCalldadc5752010-08-24 06:29:42 +00008647 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008648 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008651
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008653 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008656
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008657 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008658 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008659 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 E->getRParenLoc());
8661}
Mike Stump11289f42009-09-09 15:08:12 +00008662
Douglas Gregora16548e2009-08-11 05:31:07 +00008663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008666 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008667 TypeSourceInfo *TInfo
8668 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8669 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008671
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008673 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008674 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008675
Douglas Gregor9da64192010-04-26 22:37:10 +00008676 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8677 E->getLocStart(),
8678 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 E->getLocEnd());
8680 }
Mike Stump11289f42009-09-09 15:08:12 +00008681
Eli Friedman456f0182012-01-20 01:26:23 +00008682 // We don't know whether the subexpression is potentially evaluated until
8683 // after we perform semantic analysis. We speculatively assume it is
8684 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008685 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8687 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008688
John McCalldadc5752010-08-24 06:29:42 +00008689 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008692
Douglas Gregora16548e2009-08-11 05:31:07 +00008693 if (!getDerived().AlwaysRebuild() &&
8694 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008695 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008696
Douglas Gregor9da64192010-04-26 22:37:10 +00008697 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8698 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008699 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 E->getLocEnd());
8701}
8702
8703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008704ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008705TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8706 if (E->isTypeOperand()) {
8707 TypeSourceInfo *TInfo
8708 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8709 if (!TInfo)
8710 return ExprError();
8711
8712 if (!getDerived().AlwaysRebuild() &&
8713 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008714 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008715
Douglas Gregor69735112011-03-06 17:40:41 +00008716 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008717 E->getLocStart(),
8718 TInfo,
8719 E->getLocEnd());
8720 }
8721
Francois Pichet9f4f2072010-09-08 12:20:18 +00008722 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8723
8724 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8725 if (SubExpr.isInvalid())
8726 return ExprError();
8727
8728 if (!getDerived().AlwaysRebuild() &&
8729 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008730 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008731
8732 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8733 E->getLocStart(),
8734 SubExpr.get(),
8735 E->getLocEnd());
8736}
8737
8738template<typename Derived>
8739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008740TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008741 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008742}
Mike Stump11289f42009-09-09 15:08:12 +00008743
Douglas Gregora16548e2009-08-11 05:31:07 +00008744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008745ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008746TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008747 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008748 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008749}
Mike Stump11289f42009-09-09 15:08:12 +00008750
Douglas Gregora16548e2009-08-11 05:31:07 +00008751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008753TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008754 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008755
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008756 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8757 // Make sure that we capture 'this'.
8758 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008759 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008761
Douglas Gregorb15af892010-01-07 23:12:05 +00008762 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008763}
Mike Stump11289f42009-09-09 15:08:12 +00008764
Douglas Gregora16548e2009-08-11 05:31:07 +00008765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008768 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008771
Douglas Gregora16548e2009-08-11 05:31:07 +00008772 if (!getDerived().AlwaysRebuild() &&
8773 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008774 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008775
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008776 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8777 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008778}
Mike Stump11289f42009-09-09 15:08:12 +00008779
Douglas Gregora16548e2009-08-11 05:31:07 +00008780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008782TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008783 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008784 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8785 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008786 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008788
Chandler Carruth794da4c2010-02-08 06:42:49 +00008789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008790 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008791 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008792
Douglas Gregor033f6752009-12-23 23:03:06 +00008793 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008794}
Mike Stump11289f42009-09-09 15:08:12 +00008795
Douglas Gregora16548e2009-08-11 05:31:07 +00008796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008797ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008798TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8799 FieldDecl *Field
8800 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8801 E->getField()));
8802 if (!Field)
8803 return ExprError();
8804
8805 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008807
8808 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8809}
8810
8811template<typename Derived>
8812ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008813TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8814 CXXScalarValueInitExpr *E) {
8815 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8816 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008818
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008820 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008822
Chad Rosier1dcde962012-08-08 18:46:20 +00008823 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008824 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008825 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008826}
Mike Stump11289f42009-09-09 15:08:12 +00008827
Douglas Gregora16548e2009-08-11 05:31:07 +00008828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008830TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008831 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008832 TypeSourceInfo *AllocTypeInfo
8833 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8834 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008836
Douglas Gregora16548e2009-08-11 05:31:07 +00008837 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008838 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008839 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 // Transform the placement arguments (if any).
8843 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008844 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008845 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008846 E->getNumPlacementArgs(), true,
8847 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008849
Sebastian Redl6047f072012-02-16 12:22:20 +00008850 // Transform the initializer (if any).
8851 Expr *OldInit = E->getInitializer();
8852 ExprResult NewInit;
8853 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008854 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008855 if (NewInit.isInvalid())
8856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008857
Sebastian Redl6047f072012-02-16 12:22:20 +00008858 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008859 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008860 if (E->getOperatorNew()) {
8861 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008862 getDerived().TransformDecl(E->getLocStart(),
8863 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008865 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008866 }
8867
Craig Topperc3ec1492014-05-26 06:22:03 +00008868 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008869 if (E->getOperatorDelete()) {
8870 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008871 getDerived().TransformDecl(E->getLocStart(),
8872 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008873 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008874 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008876
Douglas Gregora16548e2009-08-11 05:31:07 +00008877 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008878 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008879 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008880 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008881 OperatorNew == E->getOperatorNew() &&
8882 OperatorDelete == E->getOperatorDelete() &&
8883 !ArgumentChanged) {
8884 // Mark any declarations we need as referenced.
8885 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008886 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008887 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008888 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008889 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008890
Sebastian Redl6047f072012-02-16 12:22:20 +00008891 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008892 QualType ElementType
8893 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8894 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8895 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8896 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008897 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008898 }
8899 }
8900 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008901
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008902 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008903 }
Mike Stump11289f42009-09-09 15:08:12 +00008904
Douglas Gregor0744ef62010-09-07 21:49:58 +00008905 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008906 if (!ArraySize.get()) {
8907 // If no array size was specified, but the new expression was
8908 // instantiated with an array type (e.g., "new T" where T is
8909 // instantiated with "int[4]"), extract the outer bound from the
8910 // array type as our array size. We do this with constant and
8911 // dependently-sized array types.
8912 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8913 if (!ArrayT) {
8914 // Do nothing
8915 } else if (const ConstantArrayType *ConsArrayT
8916 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008917 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8918 SemaRef.Context.getSizeType(),
8919 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008920 AllocType = ConsArrayT->getElementType();
8921 } else if (const DependentSizedArrayType *DepArrayT
8922 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8923 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008924 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008925 AllocType = DepArrayT->getElementType();
8926 }
8927 }
8928 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008929
Douglas Gregora16548e2009-08-11 05:31:07 +00008930 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8931 E->isGlobalNew(),
8932 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008933 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008934 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008935 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008937 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008938 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008939 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008940 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008941}
Mike Stump11289f42009-09-09 15:08:12 +00008942
Douglas Gregora16548e2009-08-11 05:31:07 +00008943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008945TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008946 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008949
Douglas Gregord2d9da02010-02-26 00:38:10 +00008950 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008951 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008952 if (E->getOperatorDelete()) {
8953 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008954 getDerived().TransformDecl(E->getLocStart(),
8955 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008956 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008957 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008959
Douglas Gregora16548e2009-08-11 05:31:07 +00008960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008961 Operand.get() == E->getArgument() &&
8962 OperatorDelete == E->getOperatorDelete()) {
8963 // Mark any declarations we need as referenced.
8964 // FIXME: instantiation-specific.
8965 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008966 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008967
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008968 if (!E->getArgument()->isTypeDependent()) {
8969 QualType Destroyed = SemaRef.Context.getBaseElementType(
8970 E->getDestroyedType());
8971 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8972 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008973 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008974 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008975 }
8976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008978 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008979 }
Mike Stump11289f42009-09-09 15:08:12 +00008980
Douglas Gregora16548e2009-08-11 05:31:07 +00008981 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8982 E->isGlobalDelete(),
8983 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008984 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008985}
Mike Stump11289f42009-09-09 15:08:12 +00008986
Douglas Gregora16548e2009-08-11 05:31:07 +00008987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008988ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008989TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008990 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008991 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008992 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008994
John McCallba7bf592010-08-24 05:47:05 +00008995 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008996 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008997 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008998 E->getOperatorLoc(),
8999 E->isArrow()? tok::arrow : tok::period,
9000 ObjectTypePtr,
9001 MayBePseudoDestructor);
9002 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009003 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009004
John McCallba7bf592010-08-24 05:47:05 +00009005 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009006 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9007 if (QualifierLoc) {
9008 QualifierLoc
9009 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9010 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009011 return ExprError();
9012 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009013 CXXScopeSpec SS;
9014 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009015
Douglas Gregor678f90d2010-02-25 01:56:36 +00009016 PseudoDestructorTypeStorage Destroyed;
9017 if (E->getDestroyedTypeInfo()) {
9018 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009019 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009020 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009021 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009022 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009023 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009024 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009025 // We aren't likely to be able to resolve the identifier down to a type
9026 // now anyway, so just retain the identifier.
9027 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9028 E->getDestroyedTypeLoc());
9029 } else {
9030 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009031 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009032 *E->getDestroyedTypeIdentifier(),
9033 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009034 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009035 SS, ObjectTypePtr,
9036 false);
9037 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
Douglas Gregor678f90d2010-02-25 01:56:36 +00009040 Destroyed
9041 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9042 E->getDestroyedTypeLoc());
9043 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009044
Craig Topperc3ec1492014-05-26 06:22:03 +00009045 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009046 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009047 CXXScopeSpec EmptySS;
9048 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009049 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009050 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
John McCallb268a282010-08-23 23:25:46 +00009054 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009055 E->getOperatorLoc(),
9056 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009057 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009058 ScopeTypeInfo,
9059 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009060 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009061 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009062}
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregorad8a3362009-09-04 17:36:40 +00009064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009066TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009067 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009068 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9069 Sema::LookupOrdinaryName);
9070
9071 // Transform all the decls.
9072 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9073 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009074 NamedDecl *InstD = static_cast<NamedDecl*>(
9075 getDerived().TransformDecl(Old->getNameLoc(),
9076 *I));
John McCall84d87672009-12-10 09:41:52 +00009077 if (!InstD) {
9078 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9079 // This can happen because of dependent hiding.
9080 if (isa<UsingShadowDecl>(*I))
9081 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009082 else {
9083 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009084 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009085 }
John McCall84d87672009-12-10 09:41:52 +00009086 }
John McCalle66edc12009-11-24 19:00:30 +00009087
9088 // Expand using declarations.
9089 if (isa<UsingDecl>(InstD)) {
9090 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009091 for (auto *I : UD->shadows())
9092 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009093 continue;
9094 }
9095
9096 R.addDecl(InstD);
9097 }
9098
9099 // Resolve a kind, but don't do any further analysis. If it's
9100 // ambiguous, the callee needs to deal with it.
9101 R.resolveKind();
9102
9103 // Rebuild the nested-name qualifier, if present.
9104 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009105 if (Old->getQualifierLoc()) {
9106 NestedNameSpecifierLoc QualifierLoc
9107 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9108 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009109 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009110
Douglas Gregor0da1d432011-02-28 20:01:57 +00009111 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009112 }
9113
Douglas Gregor9262f472010-04-27 18:19:34 +00009114 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009115 CXXRecordDecl *NamingClass
9116 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9117 Old->getNameLoc(),
9118 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009119 if (!NamingClass) {
9120 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Douglas Gregorda7be082010-04-27 16:10:10 +00009124 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009125 }
9126
Abramo Bagnara7945c982012-01-27 09:46:47 +00009127 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9128
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009129 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009130 // it's a normal declaration name or member reference.
9131 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9132 NamedDecl *D = R.getAsSingle<NamedDecl>();
9133 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9134 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9135 // give a good diagnostic.
9136 if (D && D->isCXXInstanceMember()) {
9137 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9138 /*TemplateArgs=*/nullptr,
9139 /*Scope=*/nullptr);
9140 }
9141
John McCalle66edc12009-11-24 19:00:30 +00009142 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009143 }
John McCalle66edc12009-11-24 19:00:30 +00009144
9145 // If we have template arguments, rebuild them, then rebuild the
9146 // templateid expression.
9147 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009148 if (Old->hasExplicitTemplateArgs() &&
9149 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009150 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009151 TransArgs)) {
9152 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009153 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009154 }
John McCalle66edc12009-11-24 19:00:30 +00009155
Abramo Bagnara7945c982012-01-27 09:46:47 +00009156 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009157 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009158}
Mike Stump11289f42009-09-09 15:08:12 +00009159
Douglas Gregora16548e2009-08-11 05:31:07 +00009160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009161ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009162TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9163 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009164 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009165 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9166 TypeSourceInfo *From = E->getArg(I);
9167 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009168 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009169 TypeLocBuilder TLB;
9170 TLB.reserve(FromTL.getFullDataSize());
9171 QualType To = getDerived().TransformType(TLB, FromTL);
9172 if (To.isNull())
9173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009174
Douglas Gregor29c42f22012-02-24 07:38:34 +00009175 if (To == From->getType())
9176 Args.push_back(From);
9177 else {
9178 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9179 ArgChanged = true;
9180 }
9181 continue;
9182 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
Douglas Gregor29c42f22012-02-24 07:38:34 +00009184 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009185
Douglas Gregor29c42f22012-02-24 07:38:34 +00009186 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009187 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009188 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9189 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9190 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009191
Douglas Gregor29c42f22012-02-24 07:38:34 +00009192 // Determine whether the set of unexpanded parameter packs can and should
9193 // be expanded.
9194 bool Expand = true;
9195 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009196 Optional<unsigned> OrigNumExpansions =
9197 ExpansionTL.getTypePtr()->getNumExpansions();
9198 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009199 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9200 PatternTL.getSourceRange(),
9201 Unexpanded,
9202 Expand, RetainExpansion,
9203 NumExpansions))
9204 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Douglas Gregor29c42f22012-02-24 07:38:34 +00009206 if (!Expand) {
9207 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009208 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009209 // expansion.
9210 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009211
Douglas Gregor29c42f22012-02-24 07:38:34 +00009212 TypeLocBuilder TLB;
9213 TLB.reserve(From->getTypeLoc().getFullDataSize());
9214
9215 QualType To = getDerived().TransformType(TLB, PatternTL);
9216 if (To.isNull())
9217 return ExprError();
9218
Chad Rosier1dcde962012-08-08 18:46:20 +00009219 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009220 PatternTL.getSourceRange(),
9221 ExpansionTL.getEllipsisLoc(),
9222 NumExpansions);
9223 if (To.isNull())
9224 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009225
Douglas Gregor29c42f22012-02-24 07:38:34 +00009226 PackExpansionTypeLoc ToExpansionTL
9227 = TLB.push<PackExpansionTypeLoc>(To);
9228 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9229 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9230 continue;
9231 }
9232
9233 // Expand the pack expansion by substituting for each argument in the
9234 // pack(s).
9235 for (unsigned I = 0; I != *NumExpansions; ++I) {
9236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9237 TypeLocBuilder TLB;
9238 TLB.reserve(PatternTL.getFullDataSize());
9239 QualType To = getDerived().TransformType(TLB, PatternTL);
9240 if (To.isNull())
9241 return ExprError();
9242
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009243 if (To->containsUnexpandedParameterPack()) {
9244 To = getDerived().RebuildPackExpansionType(To,
9245 PatternTL.getSourceRange(),
9246 ExpansionTL.getEllipsisLoc(),
9247 NumExpansions);
9248 if (To.isNull())
9249 return ExprError();
9250
9251 PackExpansionTypeLoc ToExpansionTL
9252 = TLB.push<PackExpansionTypeLoc>(To);
9253 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9254 }
9255
Douglas Gregor29c42f22012-02-24 07:38:34 +00009256 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009258
Douglas Gregor29c42f22012-02-24 07:38:34 +00009259 if (!RetainExpansion)
9260 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
Douglas Gregor29c42f22012-02-24 07:38:34 +00009262 // If we're supposed to retain a pack expansion, do so by temporarily
9263 // forgetting the partially-substituted parameter pack.
9264 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9265
9266 TypeLocBuilder TLB;
9267 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009268
Douglas Gregor29c42f22012-02-24 07:38:34 +00009269 QualType To = getDerived().TransformType(TLB, PatternTL);
9270 if (To.isNull())
9271 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009272
9273 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009274 PatternTL.getSourceRange(),
9275 ExpansionTL.getEllipsisLoc(),
9276 NumExpansions);
9277 if (To.isNull())
9278 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009279
Douglas Gregor29c42f22012-02-24 07:38:34 +00009280 PackExpansionTypeLoc ToExpansionTL
9281 = TLB.push<PackExpansionTypeLoc>(To);
9282 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9283 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9284 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009285
Douglas Gregor29c42f22012-02-24 07:38:34 +00009286 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009287 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009288
9289 return getDerived().RebuildTypeTrait(E->getTrait(),
9290 E->getLocStart(),
9291 Args,
9292 E->getLocEnd());
9293}
9294
9295template<typename Derived>
9296ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009297TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9298 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9299 if (!T)
9300 return ExprError();
9301
9302 if (!getDerived().AlwaysRebuild() &&
9303 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009304 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009305
9306 ExprResult SubExpr;
9307 {
9308 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9309 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9310 if (SubExpr.isInvalid())
9311 return ExprError();
9312
9313 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009314 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009315 }
9316
9317 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9318 E->getLocStart(),
9319 T,
9320 SubExpr.get(),
9321 E->getLocEnd());
9322}
9323
9324template<typename Derived>
9325ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009326TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9327 ExprResult SubExpr;
9328 {
9329 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9330 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9331 if (SubExpr.isInvalid())
9332 return ExprError();
9333
9334 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009335 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009336 }
9337
9338 return getDerived().RebuildExpressionTrait(
9339 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9340}
9341
Reid Kleckner32506ed2014-06-12 23:03:48 +00009342template <typename Derived>
9343ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9344 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9345 TypeSourceInfo **RecoveryTSI) {
9346 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9347 DRE, AddrTaken, RecoveryTSI);
9348
9349 // Propagate both errors and recovered types, which return ExprEmpty.
9350 if (!NewDRE.isUsable())
9351 return NewDRE;
9352
9353 // We got an expr, wrap it up in parens.
9354 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9355 return PE;
9356 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9357 PE->getRParen());
9358}
9359
9360template <typename Derived>
9361ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9362 DependentScopeDeclRefExpr *E) {
9363 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9364 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009365}
9366
9367template<typename Derived>
9368ExprResult
9369TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9370 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009371 bool IsAddressOfOperand,
9372 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009373 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009374 NestedNameSpecifierLoc QualifierLoc
9375 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9376 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009377 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009378 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009379
John McCall31f82722010-11-12 08:19:04 +00009380 // TODO: If this is a conversion-function-id, verify that the
9381 // destination type name (if present) resolves the same way after
9382 // instantiation as it did in the local scope.
9383
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009384 DeclarationNameInfo NameInfo
9385 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9386 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009388
John McCalle66edc12009-11-24 19:00:30 +00009389 if (!E->hasExplicitTemplateArgs()) {
9390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009391 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009392 // Note: it is sufficient to compare the Name component of NameInfo:
9393 // if name has not changed, DNLoc has not changed either.
9394 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009395 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009396
Reid Kleckner32506ed2014-06-12 23:03:48 +00009397 return getDerived().RebuildDependentScopeDeclRefExpr(
9398 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9399 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009400 }
John McCall6b51f282009-11-23 01:53:49 +00009401
9402 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009403 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9404 E->getNumTemplateArgs(),
9405 TransArgs))
9406 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009407
Reid Kleckner32506ed2014-06-12 23:03:48 +00009408 return getDerived().RebuildDependentScopeDeclRefExpr(
9409 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9410 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009411}
9412
9413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009415TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009416 // CXXConstructExprs other than for list-initialization and
9417 // CXXTemporaryObjectExpr are always implicit, so when we have
9418 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009419 if ((E->getNumArgs() == 1 ||
9420 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009421 (!getDerived().DropCallArgument(E->getArg(0))) &&
9422 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009423 return getDerived().TransformExpr(E->getArg(0));
9424
Douglas Gregora16548e2009-08-11 05:31:07 +00009425 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9426
9427 QualType T = getDerived().TransformType(E->getType());
9428 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009429 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009430
9431 CXXConstructorDecl *Constructor
9432 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009433 getDerived().TransformDecl(E->getLocStart(),
9434 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009435 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009437
Douglas Gregora16548e2009-08-11 05:31:07 +00009438 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009439 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009440 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009441 &ArgumentChanged))
9442 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009443
Douglas Gregora16548e2009-08-11 05:31:07 +00009444 if (!getDerived().AlwaysRebuild() &&
9445 T == E->getType() &&
9446 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009447 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009448 // Mark the constructor as referenced.
9449 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009450 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009451 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009452 }
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregordb121ba2009-12-14 16:27:04 +00009454 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9455 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009456 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009457 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009458 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009459 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009460 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009461 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009462 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009463}
Mike Stump11289f42009-09-09 15:08:12 +00009464
Douglas Gregora16548e2009-08-11 05:31:07 +00009465/// \brief Transform a C++ temporary-binding expression.
9466///
Douglas Gregor363b1512009-12-24 18:51:59 +00009467/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9468/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009471TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009472 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009473}
Mike Stump11289f42009-09-09 15:08:12 +00009474
John McCall5d413782010-12-06 08:20:24 +00009475/// \brief Transform a C++ expression that contains cleanups that should
9476/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009477///
John McCall5d413782010-12-06 08:20:24 +00009478/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009479/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009481ExprResult
John McCall5d413782010-12-06 08:20:24 +00009482TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009483 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009484}
Mike Stump11289f42009-09-09 15:08:12 +00009485
Douglas Gregora16548e2009-08-11 05:31:07 +00009486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009487ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009488TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009489 CXXTemporaryObjectExpr *E) {
9490 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9491 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009493
Douglas Gregora16548e2009-08-11 05:31:07 +00009494 CXXConstructorDecl *Constructor
9495 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009496 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009497 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009498 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009499 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009500
Douglas Gregora16548e2009-08-11 05:31:07 +00009501 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009502 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009504 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009505 &ArgumentChanged))
9506 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009507
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009509 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009510 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009511 !ArgumentChanged) {
9512 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009513 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009514 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009516
Richard Smithd59b8322012-12-19 01:39:02 +00009517 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009518 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9519 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009520 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009521 E->getLocEnd());
9522}
Mike Stump11289f42009-09-09 15:08:12 +00009523
Douglas Gregora16548e2009-08-11 05:31:07 +00009524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009525ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009526TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009527 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009528 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009529 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009530 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9531 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009532 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009533 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009534 CEnd = E->capture_end();
9535 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009536 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009537 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009538 EnterExpressionEvaluationContext EEEC(getSema(),
9539 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009540 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9541 C->getCapturedVar()->getInit(),
9542 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009543
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009544 if (NewExprInitResult.isInvalid())
9545 return ExprError();
9546 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009547
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009548 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009549 QualType NewInitCaptureType =
9550 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9551 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009552 NewExprInit);
9553 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009554 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9555 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009556 }
9557
Faisal Vali2cba1332013-10-23 06:44:28 +00009558 // Transform the template parameters, and add them to the current
9559 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009560 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009561 E->getTemplateParameterList());
9562
Richard Smith01014ce2014-11-20 23:53:14 +00009563 // Transform the type of the original lambda's call operator.
9564 // The transformation MUST be done in the CurrentInstantiationScope since
9565 // it introduces a mapping of the original to the newly created
9566 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009567 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009568 {
9569 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9570 FunctionProtoTypeLoc OldCallOpFPTL =
9571 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009572
9573 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009574 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009575 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009576 QualType NewCallOpType = TransformFunctionProtoType(
9577 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009578 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9579 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9580 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009581 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009582 if (NewCallOpType.isNull())
9583 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009584 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9585 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009586 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009587
Richard Smithc38498f2015-04-27 21:27:54 +00009588 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9589 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9590 LSI->GLTemplateParameterList = TPL;
9591
Eli Friedmand564afb2012-09-19 01:18:11 +00009592 // Create the local class that will describe the lambda.
9593 CXXRecordDecl *Class
9594 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009595 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009596 /*KnownDependent=*/false,
9597 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009598 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9599
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009600 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009601 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9602 Class, E->getIntroducerRange(), NewCallOpTSI,
9603 E->getCallOperator()->getLocEnd(),
9604 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009605 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009606
Faisal Vali2cba1332013-10-23 06:44:28 +00009607 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009608 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009609
Douglas Gregorb4328232012-02-14 00:00:48 +00009610 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009611 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009612 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009613
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009614 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009615 getSema().buildLambdaScope(LSI, NewCallOperator,
9616 E->getIntroducerRange(),
9617 E->getCaptureDefault(),
9618 E->getCaptureDefaultLoc(),
9619 E->hasExplicitParameters(),
9620 E->hasExplicitResultType(),
9621 E->isMutable());
9622
9623 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009624
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009625 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009626 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009627 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009628 CEnd = E->capture_end();
9629 C != CEnd; ++C) {
9630 // When we hit the first implicit capture, tell Sema that we've finished
9631 // the list of explicit captures.
9632 if (!FinishedExplicitCaptures && C->isImplicit()) {
9633 getSema().finishLambdaExplicitCaptures(LSI);
9634 FinishedExplicitCaptures = true;
9635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009636
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009637 // Capturing 'this' is trivial.
9638 if (C->capturesThis()) {
9639 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9640 continue;
9641 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009642 // Captured expression will be recaptured during captured variables
9643 // rebuilding.
9644 if (C->capturesVLAType())
9645 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009646
Richard Smithba71c082013-05-16 06:20:58 +00009647 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009648 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009649 InitCaptureInfoTy InitExprTypePair =
9650 InitCaptureExprsAndTypes[C - E->capture_begin()];
9651 ExprResult Init = InitExprTypePair.first;
9652 QualType InitQualType = InitExprTypePair.second;
9653 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009654 Invalid = true;
9655 continue;
9656 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009657 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009658 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9659 OldVD->getLocation(), InitExprTypePair.second,
9660 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009661 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009662 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009663 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009664 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009665 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009666 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009667 continue;
9668 }
9669
9670 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9671
Douglas Gregor3e308b12012-02-14 19:27:52 +00009672 // Determine the capture kind for Sema.
9673 Sema::TryCaptureKind Kind
9674 = C->isImplicit()? Sema::TryCapture_Implicit
9675 : C->getCaptureKind() == LCK_ByCopy
9676 ? Sema::TryCapture_ExplicitByVal
9677 : Sema::TryCapture_ExplicitByRef;
9678 SourceLocation EllipsisLoc;
9679 if (C->isPackExpansion()) {
9680 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9681 bool ShouldExpand = false;
9682 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009683 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009684 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9685 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009686 Unexpanded,
9687 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009688 NumExpansions)) {
9689 Invalid = true;
9690 continue;
9691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009692
Douglas Gregor3e308b12012-02-14 19:27:52 +00009693 if (ShouldExpand) {
9694 // The transform has determined that we should perform an expansion;
9695 // transform and capture each of the arguments.
9696 // expansion of the pattern. Do so.
9697 VarDecl *Pack = C->getCapturedVar();
9698 for (unsigned I = 0; I != *NumExpansions; ++I) {
9699 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9700 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009701 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009702 Pack));
9703 if (!CapturedVar) {
9704 Invalid = true;
9705 continue;
9706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009707
Douglas Gregor3e308b12012-02-14 19:27:52 +00009708 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009709 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9710 }
Richard Smith9467be42014-06-06 17:33:35 +00009711
9712 // FIXME: Retain a pack expansion if RetainExpansion is true.
9713
Douglas Gregor3e308b12012-02-14 19:27:52 +00009714 continue;
9715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009716
Douglas Gregor3e308b12012-02-14 19:27:52 +00009717 EllipsisLoc = C->getEllipsisLoc();
9718 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009719
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009720 // Transform the captured variable.
9721 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009722 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009723 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009724 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009725 Invalid = true;
9726 continue;
9727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009728
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009729 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009730 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9731 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009732 }
9733 if (!FinishedExplicitCaptures)
9734 getSema().finishLambdaExplicitCaptures(LSI);
9735
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009736 // Enter a new evaluation context to insulate the lambda from any
9737 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009738 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009739
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009740 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009741 StmtResult Body =
9742 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9743
9744 // ActOnLambda* will pop the function scope for us.
9745 FuncScopeCleanup.disable();
9746
Douglas Gregorb4328232012-02-14 00:00:48 +00009747 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009748 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009749 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009750 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009751 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009752 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009753
Richard Smithc38498f2015-04-27 21:27:54 +00009754 // Copy the LSI before ActOnFinishFunctionBody removes it.
9755 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9756 // the call operator.
9757 auto LSICopy = *LSI;
9758 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9759 /*IsInstantiation*/ true);
9760 SavedContext.pop();
9761
9762 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9763 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009764}
9765
9766template<typename Derived>
9767ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009768TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009769 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009770 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9771 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009772 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009773
Douglas Gregora16548e2009-08-11 05:31:07 +00009774 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009775 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009776 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009777 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009778 &ArgumentChanged))
9779 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009780
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009782 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009783 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009784 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009785
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009787 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009789 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009790 E->getRParenLoc());
9791}
Mike Stump11289f42009-09-09 15:08:12 +00009792
Douglas Gregora16548e2009-08-11 05:31:07 +00009793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009794ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009795TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009796 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009797 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009798 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009799 Expr *OldBase;
9800 QualType BaseType;
9801 QualType ObjectType;
9802 if (!E->isImplicitAccess()) {
9803 OldBase = E->getBase();
9804 Base = getDerived().TransformExpr(OldBase);
9805 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009807
John McCall2d74de92009-12-01 22:10:20 +00009808 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009809 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009810 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009811 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009812 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009813 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009814 ObjectTy,
9815 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009816 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009817 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009818
John McCallba7bf592010-08-24 05:47:05 +00009819 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009820 BaseType = ((Expr*) Base.get())->getType();
9821 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009822 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009823 BaseType = getDerived().TransformType(E->getBaseType());
9824 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9825 }
Mike Stump11289f42009-09-09 15:08:12 +00009826
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009827 // Transform the first part of the nested-name-specifier that qualifies
9828 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009829 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009830 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009831 E->getFirstQualifierFoundInScope(),
9832 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009833
Douglas Gregore16af532011-02-28 18:50:33 +00009834 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009835 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009836 QualifierLoc
9837 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9838 ObjectType,
9839 FirstQualifierInScope);
9840 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009841 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009842 }
Mike Stump11289f42009-09-09 15:08:12 +00009843
Abramo Bagnara7945c982012-01-27 09:46:47 +00009844 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9845
John McCall31f82722010-11-12 08:19:04 +00009846 // TODO: If this is a conversion-function-id, verify that the
9847 // destination type name (if present) resolves the same way after
9848 // instantiation as it did in the local scope.
9849
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009850 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009851 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009852 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009853 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009854
John McCall2d74de92009-12-01 22:10:20 +00009855 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009856 // This is a reference to a member without an explicitly-specified
9857 // template argument list. Optimize for this common case.
9858 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009859 Base.get() == OldBase &&
9860 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009861 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009862 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009863 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009864 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009865
John McCallb268a282010-08-23 23:25:46 +00009866 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009867 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009868 E->isArrow(),
9869 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009870 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009871 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009872 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009873 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009874 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009875 }
9876
John McCall6b51f282009-11-23 01:53:49 +00009877 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009878 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9879 E->getNumTemplateArgs(),
9880 TransArgs))
9881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009882
John McCallb268a282010-08-23 23:25:46 +00009883 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009884 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009885 E->isArrow(),
9886 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009887 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009888 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009889 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009890 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009891 &TransArgs);
9892}
9893
9894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009896TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009897 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009898 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009899 QualType BaseType;
9900 if (!Old->isImplicitAccess()) {
9901 Base = getDerived().TransformExpr(Old->getBase());
9902 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009903 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009904 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009905 Old->isArrow());
9906 if (Base.isInvalid())
9907 return ExprError();
9908 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009909 } else {
9910 BaseType = getDerived().TransformType(Old->getBaseType());
9911 }
John McCall10eae182009-11-30 22:42:35 +00009912
Douglas Gregor0da1d432011-02-28 20:01:57 +00009913 NestedNameSpecifierLoc QualifierLoc;
9914 if (Old->getQualifierLoc()) {
9915 QualifierLoc
9916 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9917 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009918 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009919 }
9920
Abramo Bagnara7945c982012-01-27 09:46:47 +00009921 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9922
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009923 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009924 Sema::LookupOrdinaryName);
9925
9926 // Transform all the decls.
9927 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9928 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009929 NamedDecl *InstD = static_cast<NamedDecl*>(
9930 getDerived().TransformDecl(Old->getMemberLoc(),
9931 *I));
John McCall84d87672009-12-10 09:41:52 +00009932 if (!InstD) {
9933 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9934 // This can happen because of dependent hiding.
9935 if (isa<UsingShadowDecl>(*I))
9936 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009937 else {
9938 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009939 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009940 }
John McCall84d87672009-12-10 09:41:52 +00009941 }
John McCall10eae182009-11-30 22:42:35 +00009942
9943 // Expand using declarations.
9944 if (isa<UsingDecl>(InstD)) {
9945 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009946 for (auto *I : UD->shadows())
9947 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009948 continue;
9949 }
9950
9951 R.addDecl(InstD);
9952 }
9953
9954 R.resolveKind();
9955
Douglas Gregor9262f472010-04-27 18:19:34 +00009956 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009957 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009958 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009959 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009960 Old->getMemberLoc(),
9961 Old->getNamingClass()));
9962 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009963 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009964
Douglas Gregorda7be082010-04-27 16:10:10 +00009965 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009967
John McCall10eae182009-11-30 22:42:35 +00009968 TemplateArgumentListInfo TransArgs;
9969 if (Old->hasExplicitTemplateArgs()) {
9970 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9971 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009972 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9973 Old->getNumTemplateArgs(),
9974 TransArgs))
9975 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009976 }
John McCall38836f02010-01-15 08:34:02 +00009977
9978 // FIXME: to do this check properly, we will need to preserve the
9979 // first-qualifier-in-scope here, just in case we had a dependent
9980 // base (and therefore couldn't do the check) and a
9981 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009982 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009983
John McCallb268a282010-08-23 23:25:46 +00009984 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009985 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009986 Old->getOperatorLoc(),
9987 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009988 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009989 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009990 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009991 R,
9992 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009993 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009994}
9995
9996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009997ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009998TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009999 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010000 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10001 if (SubExpr.isInvalid())
10002 return ExprError();
10003
10004 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010005 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010006
10007 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10008}
10009
10010template<typename Derived>
10011ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010012TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010013 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10014 if (Pattern.isInvalid())
10015 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010016
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010017 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010018 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010019
Douglas Gregorb8840002011-01-14 21:20:45 +000010020 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10021 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010022}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010023
10024template<typename Derived>
10025ExprResult
10026TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10027 // If E is not value-dependent, then nothing will change when we transform it.
10028 // Note: This is an instantiation-centric view.
10029 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010030 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010031
Richard Smithd784e682015-09-23 21:41:42 +000010032 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010033
Richard Smithd784e682015-09-23 21:41:42 +000010034 ArrayRef<TemplateArgument> PackArgs;
10035 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010036
Richard Smithd784e682015-09-23 21:41:42 +000010037 // Find the argument list to transform.
10038 if (E->isPartiallySubstituted()) {
10039 PackArgs = E->getPartialArguments();
10040 } else if (E->isValueDependent()) {
10041 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10042 bool ShouldExpand = false;
10043 bool RetainExpansion = false;
10044 Optional<unsigned> NumExpansions;
10045 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10046 Unexpanded,
10047 ShouldExpand, RetainExpansion,
10048 NumExpansions))
10049 return ExprError();
10050
10051 // If we need to expand the pack, build a template argument from it and
10052 // expand that.
10053 if (ShouldExpand) {
10054 auto *Pack = E->getPack();
10055 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10056 ArgStorage = getSema().Context.getPackExpansionType(
10057 getSema().Context.getTypeDeclType(TTPD), None);
10058 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10059 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10060 } else {
10061 auto *VD = cast<ValueDecl>(Pack);
10062 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10063 VK_RValue, E->getPackLoc());
10064 if (DRE.isInvalid())
10065 return ExprError();
10066 ArgStorage = new (getSema().Context) PackExpansionExpr(
10067 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10068 }
10069 PackArgs = ArgStorage;
10070 }
10071 }
10072
10073 // If we're not expanding the pack, just transform the decl.
10074 if (!PackArgs.size()) {
10075 auto *Pack = cast_or_null<NamedDecl>(
10076 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010077 if (!Pack)
10078 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010079 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10080 E->getPackLoc(),
10081 E->getRParenLoc(), None, None);
10082 }
10083
10084 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10085 E->getPackLoc());
10086 {
10087 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10088 typedef TemplateArgumentLocInventIterator<
10089 Derived, const TemplateArgument*> PackLocIterator;
10090 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10091 PackLocIterator(*this, PackArgs.end()),
10092 TransformedPackArgs, /*Uneval*/true))
10093 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010094 }
10095
Richard Smithd784e682015-09-23 21:41:42 +000010096 SmallVector<TemplateArgument, 8> Args;
10097 bool PartialSubstitution = false;
10098 for (auto &Loc : TransformedPackArgs.arguments()) {
10099 Args.push_back(Loc.getArgument());
10100 if (Loc.getArgument().isPackExpansion())
10101 PartialSubstitution = true;
10102 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010103
Richard Smithd784e682015-09-23 21:41:42 +000010104 if (PartialSubstitution)
10105 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10106 E->getPackLoc(),
10107 E->getRParenLoc(), None, Args);
10108
10109 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010110 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010111 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010112}
10113
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010114template<typename Derived>
10115ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010116TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10117 SubstNonTypeTemplateParmPackExpr *E) {
10118 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010119 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010120}
10121
10122template<typename Derived>
10123ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010124TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10125 SubstNonTypeTemplateParmExpr *E) {
10126 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010127 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010128}
10129
10130template<typename Derived>
10131ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010132TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10133 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010134 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010135}
10136
10137template<typename Derived>
10138ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010139TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10140 MaterializeTemporaryExpr *E) {
10141 return getDerived().TransformExpr(E->GetTemporaryExpr());
10142}
Chad Rosier1dcde962012-08-08 18:46:20 +000010143
Douglas Gregorfe314812011-06-21 17:03:29 +000010144template<typename Derived>
10145ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010146TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10147 Expr *Pattern = E->getPattern();
10148
10149 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10150 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10151 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10152
10153 // Determine whether the set of unexpanded parameter packs can and should
10154 // be expanded.
10155 bool Expand = true;
10156 bool RetainExpansion = false;
10157 Optional<unsigned> NumExpansions;
10158 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10159 Pattern->getSourceRange(),
10160 Unexpanded,
10161 Expand, RetainExpansion,
10162 NumExpansions))
10163 return true;
10164
10165 if (!Expand) {
10166 // Do not expand any packs here, just transform and rebuild a fold
10167 // expression.
10168 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10169
10170 ExprResult LHS =
10171 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10172 if (LHS.isInvalid())
10173 return true;
10174
10175 ExprResult RHS =
10176 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10177 if (RHS.isInvalid())
10178 return true;
10179
10180 if (!getDerived().AlwaysRebuild() &&
10181 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10182 return E;
10183
10184 return getDerived().RebuildCXXFoldExpr(
10185 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10186 RHS.get(), E->getLocEnd());
10187 }
10188
10189 // The transform has determined that we should perform an elementwise
10190 // expansion of the pattern. Do so.
10191 ExprResult Result = getDerived().TransformExpr(E->getInit());
10192 if (Result.isInvalid())
10193 return true;
10194 bool LeftFold = E->isLeftFold();
10195
10196 // If we're retaining an expansion for a right fold, it is the innermost
10197 // component and takes the init (if any).
10198 if (!LeftFold && RetainExpansion) {
10199 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10200
10201 ExprResult Out = getDerived().TransformExpr(Pattern);
10202 if (Out.isInvalid())
10203 return true;
10204
10205 Result = getDerived().RebuildCXXFoldExpr(
10206 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10207 Result.get(), E->getLocEnd());
10208 if (Result.isInvalid())
10209 return true;
10210 }
10211
10212 for (unsigned I = 0; I != *NumExpansions; ++I) {
10213 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10214 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10215 ExprResult Out = getDerived().TransformExpr(Pattern);
10216 if (Out.isInvalid())
10217 return true;
10218
10219 if (Out.get()->containsUnexpandedParameterPack()) {
10220 // We still have a pack; retain a pack expansion for this slice.
10221 Result = getDerived().RebuildCXXFoldExpr(
10222 E->getLocStart(),
10223 LeftFold ? Result.get() : Out.get(),
10224 E->getOperator(), E->getEllipsisLoc(),
10225 LeftFold ? Out.get() : Result.get(),
10226 E->getLocEnd());
10227 } else if (Result.isUsable()) {
10228 // We've got down to a single element; build a binary operator.
10229 Result = getDerived().RebuildBinaryOperator(
10230 E->getEllipsisLoc(), E->getOperator(),
10231 LeftFold ? Result.get() : Out.get(),
10232 LeftFold ? Out.get() : Result.get());
10233 } else
10234 Result = Out;
10235
10236 if (Result.isInvalid())
10237 return true;
10238 }
10239
10240 // If we're retaining an expansion for a left fold, it is the outermost
10241 // component and takes the complete expansion so far as its init (if any).
10242 if (LeftFold && RetainExpansion) {
10243 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10244
10245 ExprResult Out = getDerived().TransformExpr(Pattern);
10246 if (Out.isInvalid())
10247 return true;
10248
10249 Result = getDerived().RebuildCXXFoldExpr(
10250 E->getLocStart(), Result.get(),
10251 E->getOperator(), E->getEllipsisLoc(),
10252 Out.get(), E->getLocEnd());
10253 if (Result.isInvalid())
10254 return true;
10255 }
10256
10257 // If we had no init and an empty pack, and we're not retaining an expansion,
10258 // then produce a fallback value or error.
10259 if (Result.isUnset())
10260 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10261 E->getOperator());
10262
10263 return Result;
10264}
10265
10266template<typename Derived>
10267ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010268TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10269 CXXStdInitializerListExpr *E) {
10270 return getDerived().TransformExpr(E->getSubExpr());
10271}
10272
10273template<typename Derived>
10274ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010275TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010276 return SemaRef.MaybeBindToTemporary(E);
10277}
10278
10279template<typename Derived>
10280ExprResult
10281TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010282 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010283}
10284
10285template<typename Derived>
10286ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010287TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10288 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10289 if (SubExpr.isInvalid())
10290 return ExprError();
10291
10292 if (!getDerived().AlwaysRebuild() &&
10293 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010294 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010295
10296 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010297}
10298
10299template<typename Derived>
10300ExprResult
10301TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10302 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010303 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010304 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010305 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010306 /*IsCall=*/false, Elements, &ArgChanged))
10307 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010308
Ted Kremeneke65b0862012-03-06 20:05:56 +000010309 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10310 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010311
Ted Kremeneke65b0862012-03-06 20:05:56 +000010312 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10313 Elements.data(),
10314 Elements.size());
10315}
10316
10317template<typename Derived>
10318ExprResult
10319TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010320 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010321 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010322 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010323 bool ArgChanged = false;
10324 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10325 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010326
Ted Kremeneke65b0862012-03-06 20:05:56 +000010327 if (OrigElement.isPackExpansion()) {
10328 // This key/value element is a pack expansion.
10329 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10330 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10331 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10332 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10333
10334 // Determine whether the set of unexpanded parameter packs can
10335 // and should be expanded.
10336 bool Expand = true;
10337 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010338 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10339 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010340 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10341 OrigElement.Value->getLocEnd());
10342 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10343 PatternRange,
10344 Unexpanded,
10345 Expand, RetainExpansion,
10346 NumExpansions))
10347 return ExprError();
10348
10349 if (!Expand) {
10350 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010351 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010352 // expansion.
10353 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10354 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10355 if (Key.isInvalid())
10356 return ExprError();
10357
10358 if (Key.get() != OrigElement.Key)
10359 ArgChanged = true;
10360
10361 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10362 if (Value.isInvalid())
10363 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010364
Ted Kremeneke65b0862012-03-06 20:05:56 +000010365 if (Value.get() != OrigElement.Value)
10366 ArgChanged = true;
10367
Chad Rosier1dcde962012-08-08 18:46:20 +000010368 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010369 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10370 };
10371 Elements.push_back(Expansion);
10372 continue;
10373 }
10374
10375 // Record right away that the argument was changed. This needs
10376 // to happen even if the array expands to nothing.
10377 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010378
Ted Kremeneke65b0862012-03-06 20:05:56 +000010379 // The transform has determined that we should perform an elementwise
10380 // expansion of the pattern. Do so.
10381 for (unsigned I = 0; I != *NumExpansions; ++I) {
10382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10383 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10384 if (Key.isInvalid())
10385 return ExprError();
10386
10387 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10388 if (Value.isInvalid())
10389 return ExprError();
10390
Chad Rosier1dcde962012-08-08 18:46:20 +000010391 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010392 Key.get(), Value.get(), SourceLocation(), NumExpansions
10393 };
10394
10395 // If any unexpanded parameter packs remain, we still have a
10396 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010397 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010398 if (Key.get()->containsUnexpandedParameterPack() ||
10399 Value.get()->containsUnexpandedParameterPack())
10400 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010401
Ted Kremeneke65b0862012-03-06 20:05:56 +000010402 Elements.push_back(Element);
10403 }
10404
Richard Smith9467be42014-06-06 17:33:35 +000010405 // FIXME: Retain a pack expansion if RetainExpansion is true.
10406
Ted Kremeneke65b0862012-03-06 20:05:56 +000010407 // We've finished with this pack expansion.
10408 continue;
10409 }
10410
10411 // Transform and check key.
10412 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10413 if (Key.isInvalid())
10414 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010415
Ted Kremeneke65b0862012-03-06 20:05:56 +000010416 if (Key.get() != OrigElement.Key)
10417 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010418
Ted Kremeneke65b0862012-03-06 20:05:56 +000010419 // Transform and check value.
10420 ExprResult Value
10421 = getDerived().TransformExpr(OrigElement.Value);
10422 if (Value.isInvalid())
10423 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010424
Ted Kremeneke65b0862012-03-06 20:05:56 +000010425 if (Value.get() != OrigElement.Value)
10426 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010427
10428 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010429 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010430 };
10431 Elements.push_back(Element);
10432 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010433
Ted Kremeneke65b0862012-03-06 20:05:56 +000010434 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10435 return SemaRef.MaybeBindToTemporary(E);
10436
10437 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10438 Elements.data(),
10439 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010440}
10441
Mike Stump11289f42009-09-09 15:08:12 +000010442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010443ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010444TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010445 TypeSourceInfo *EncodedTypeInfo
10446 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10447 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010449
Douglas Gregora16548e2009-08-11 05:31:07 +000010450 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010451 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010452 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010453
10454 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010455 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010456 E->getRParenLoc());
10457}
Mike Stump11289f42009-09-09 15:08:12 +000010458
Douglas Gregora16548e2009-08-11 05:31:07 +000010459template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010460ExprResult TreeTransform<Derived>::
10461TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010462 // This is a kind of implicit conversion, and it needs to get dropped
10463 // and recomputed for the same general reasons that ImplicitCastExprs
10464 // do, as well a more specific one: this expression is only valid when
10465 // it appears *immediately* as an argument expression.
10466 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010467}
10468
10469template<typename Derived>
10470ExprResult TreeTransform<Derived>::
10471TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010472 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010473 = getDerived().TransformType(E->getTypeInfoAsWritten());
10474 if (!TSInfo)
10475 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010476
John McCall31168b02011-06-15 23:02:42 +000010477 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010478 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010479 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010480
John McCall31168b02011-06-15 23:02:42 +000010481 if (!getDerived().AlwaysRebuild() &&
10482 TSInfo == E->getTypeInfoAsWritten() &&
10483 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010484 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010485
John McCall31168b02011-06-15 23:02:42 +000010486 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010487 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010488 Result.get());
10489}
10490
10491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010493TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010494 // Transform arguments.
10495 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010496 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010497 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010498 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010499 &ArgChanged))
10500 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010501
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010502 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10503 // Class message: transform the receiver type.
10504 TypeSourceInfo *ReceiverTypeInfo
10505 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10506 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010507 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010508
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010509 // If nothing changed, just retain the existing message send.
10510 if (!getDerived().AlwaysRebuild() &&
10511 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010512 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010513
10514 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010515 SmallVector<SourceLocation, 16> SelLocs;
10516 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010517 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10518 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010519 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010520 E->getMethodDecl(),
10521 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010522 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010523 E->getRightLoc());
10524 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010525 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10526 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10527 // Build a new class message send to 'super'.
10528 SmallVector<SourceLocation, 16> SelLocs;
10529 E->getSelectorLocs(SelLocs);
10530 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10531 E->getSelector(),
10532 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010533 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010534 E->getMethodDecl(),
10535 E->getLeftLoc(),
10536 Args,
10537 E->getRightLoc());
10538 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010539
10540 // Instance message: transform the receiver
10541 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10542 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010543 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010544 = getDerived().TransformExpr(E->getInstanceReceiver());
10545 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010546 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010547
10548 // If nothing changed, just retain the existing message send.
10549 if (!getDerived().AlwaysRebuild() &&
10550 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010551 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010552
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010553 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010554 SmallVector<SourceLocation, 16> SelLocs;
10555 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010556 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010557 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010558 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010559 E->getMethodDecl(),
10560 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010561 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010562 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010563}
10564
Mike Stump11289f42009-09-09 15:08:12 +000010565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010567TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010568 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010569}
10570
Mike Stump11289f42009-09-09 15:08:12 +000010571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010573TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010574 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010575}
10576
Mike Stump11289f42009-09-09 15:08:12 +000010577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010579TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010580 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010581 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010582 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010583 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010584
10585 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010586
Douglas Gregord51d90d2010-04-26 20:11:03 +000010587 // If nothing changed, just retain the existing expression.
10588 if (!getDerived().AlwaysRebuild() &&
10589 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010590 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010591
John McCallb268a282010-08-23 23:25:46 +000010592 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010593 E->getLocation(),
10594 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010595}
10596
Mike Stump11289f42009-09-09 15:08:12 +000010597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010598ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010599TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010600 // 'super' and types never change. Property never changes. Just
10601 // retain the existing expression.
10602 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010603 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010604
Douglas Gregor9faee212010-04-26 20:47:02 +000010605 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010606 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010607 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010608 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010609
Douglas Gregor9faee212010-04-26 20:47:02 +000010610 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010611
Douglas Gregor9faee212010-04-26 20:47:02 +000010612 // If nothing changed, just retain the existing expression.
10613 if (!getDerived().AlwaysRebuild() &&
10614 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010615 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010616
John McCallb7bd14f2010-12-02 01:19:52 +000010617 if (E->isExplicitProperty())
10618 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10619 E->getExplicitProperty(),
10620 E->getLocation());
10621
10622 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010623 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010624 E->getImplicitPropertyGetter(),
10625 E->getImplicitPropertySetter(),
10626 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010627}
10628
Mike Stump11289f42009-09-09 15:08:12 +000010629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010630ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010631TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10632 // Transform the base expression.
10633 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10634 if (Base.isInvalid())
10635 return ExprError();
10636
10637 // Transform the key expression.
10638 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10639 if (Key.isInvalid())
10640 return ExprError();
10641
10642 // If nothing changed, just retain the existing expression.
10643 if (!getDerived().AlwaysRebuild() &&
10644 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010645 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010646
Chad Rosier1dcde962012-08-08 18:46:20 +000010647 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010648 Base.get(), Key.get(),
10649 E->getAtIndexMethodDecl(),
10650 E->setAtIndexMethodDecl());
10651}
10652
10653template<typename Derived>
10654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010655TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010656 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010658 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010659 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010660
Douglas Gregord51d90d2010-04-26 20:11:03 +000010661 // If nothing changed, just retain the existing expression.
10662 if (!getDerived().AlwaysRebuild() &&
10663 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010664 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010665
John McCallb268a282010-08-23 23:25:46 +000010666 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010667 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010668 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010669}
10670
Mike Stump11289f42009-09-09 15:08:12 +000010671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010673TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010674 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010675 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010676 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010677 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010678 SubExprs, &ArgumentChanged))
10679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010680
Douglas Gregora16548e2009-08-11 05:31:07 +000010681 if (!getDerived().AlwaysRebuild() &&
10682 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010683 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010684
Douglas Gregora16548e2009-08-11 05:31:07 +000010685 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010686 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010687 E->getRParenLoc());
10688}
10689
Mike Stump11289f42009-09-09 15:08:12 +000010690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010691ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010692TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10693 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10694 if (SrcExpr.isInvalid())
10695 return ExprError();
10696
10697 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10698 if (!Type)
10699 return ExprError();
10700
10701 if (!getDerived().AlwaysRebuild() &&
10702 Type == E->getTypeSourceInfo() &&
10703 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010704 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010705
10706 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10707 SrcExpr.get(), Type,
10708 E->getRParenLoc());
10709}
10710
10711template<typename Derived>
10712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010713TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010714 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010715
Craig Topperc3ec1492014-05-26 06:22:03 +000010716 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010717 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10718
10719 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010720 blockScope->TheDecl->setBlockMissingReturnType(
10721 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010722
Chris Lattner01cf8db2011-07-20 06:58:45 +000010723 SmallVector<ParmVarDecl*, 4> params;
10724 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010725
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010726 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010727 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10728 oldBlock->param_begin(),
10729 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010730 nullptr, paramTypes, &params)) {
10731 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010732 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010733 }
John McCall490112f2011-02-04 18:33:18 +000010734
Jordan Rosea0a86be2013-03-08 22:25:36 +000010735 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010736 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010737 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010738
Jordan Rose5c382722013-03-08 21:51:21 +000010739 QualType functionType =
10740 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010741 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010742 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010743
10744 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010745 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010746 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010747
10748 if (!oldBlock->blockMissingReturnType()) {
10749 blockScope->HasImplicitReturnType = false;
10750 blockScope->ReturnType = exprResultType;
10751 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010752
John McCall3882ace2011-01-05 12:14:39 +000010753 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010754 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010755 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010756 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010757 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010758 }
John McCall3882ace2011-01-05 12:14:39 +000010759
John McCall490112f2011-02-04 18:33:18 +000010760#ifndef NDEBUG
10761 // In builds with assertions, make sure that we captured everything we
10762 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010763 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010764 for (const auto &I : oldBlock->captures()) {
10765 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010766
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010767 // Ignore parameter packs.
10768 if (isa<ParmVarDecl>(oldCapture) &&
10769 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10770 continue;
John McCall490112f2011-02-04 18:33:18 +000010771
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010772 VarDecl *newCapture =
10773 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10774 oldCapture));
10775 assert(blockScope->CaptureMap.count(newCapture));
10776 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010777 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010778 }
10779#endif
10780
10781 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010782 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010783}
10784
Mike Stump11289f42009-09-09 15:08:12 +000010785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010786ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010787TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010788 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010789}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010790
10791template<typename Derived>
10792ExprResult
10793TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010794 QualType RetTy = getDerived().TransformType(E->getType());
10795 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010796 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010797 SubExprs.reserve(E->getNumSubExprs());
10798 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10799 SubExprs, &ArgumentChanged))
10800 return ExprError();
10801
10802 if (!getDerived().AlwaysRebuild() &&
10803 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010804 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010805
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010806 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010807 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010808}
Chad Rosier1dcde962012-08-08 18:46:20 +000010809
Douglas Gregora16548e2009-08-11 05:31:07 +000010810//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010811// Type reconstruction
10812//===----------------------------------------------------------------------===//
10813
Mike Stump11289f42009-09-09 15:08:12 +000010814template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010815QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10816 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010817 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010818 getDerived().getBaseEntity());
10819}
10820
Mike Stump11289f42009-09-09 15:08:12 +000010821template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010822QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10823 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010824 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010825 getDerived().getBaseEntity());
10826}
10827
Mike Stump11289f42009-09-09 15:08:12 +000010828template<typename Derived>
10829QualType
John McCall70dd5f62009-10-30 00:06:24 +000010830TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10831 bool WrittenAsLValue,
10832 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010833 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010834 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010835}
10836
10837template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010838QualType
John McCall70dd5f62009-10-30 00:06:24 +000010839TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10840 QualType ClassType,
10841 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010842 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10843 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010844}
10845
10846template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010847QualType TreeTransform<Derived>::RebuildObjCObjectType(
10848 QualType BaseType,
10849 SourceLocation Loc,
10850 SourceLocation TypeArgsLAngleLoc,
10851 ArrayRef<TypeSourceInfo *> TypeArgs,
10852 SourceLocation TypeArgsRAngleLoc,
10853 SourceLocation ProtocolLAngleLoc,
10854 ArrayRef<ObjCProtocolDecl *> Protocols,
10855 ArrayRef<SourceLocation> ProtocolLocs,
10856 SourceLocation ProtocolRAngleLoc) {
10857 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10858 TypeArgs, TypeArgsRAngleLoc,
10859 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10860 ProtocolRAngleLoc,
10861 /*FailOnError=*/true);
10862}
10863
10864template<typename Derived>
10865QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10866 QualType PointeeType,
10867 SourceLocation Star) {
10868 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10869}
10870
10871template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010872QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010873TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10874 ArrayType::ArraySizeModifier SizeMod,
10875 const llvm::APInt *Size,
10876 Expr *SizeExpr,
10877 unsigned IndexTypeQuals,
10878 SourceRange BracketsRange) {
10879 if (SizeExpr || !Size)
10880 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10881 IndexTypeQuals, BracketsRange,
10882 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010883
10884 QualType Types[] = {
10885 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10886 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10887 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010888 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010889 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010890 QualType SizeType;
10891 for (unsigned I = 0; I != NumTypes; ++I)
10892 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10893 SizeType = Types[I];
10894 break;
10895 }
Mike Stump11289f42009-09-09 15:08:12 +000010896
Eli Friedman9562f392012-01-25 23:20:27 +000010897 // Note that we can return a VariableArrayType here in the case where
10898 // the element type was a dependent VariableArrayType.
10899 IntegerLiteral *ArraySize
10900 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10901 /*FIXME*/BracketsRange.getBegin());
10902 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010903 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010904 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010905}
Mike Stump11289f42009-09-09 15:08:12 +000010906
Douglas Gregord6ff3322009-08-04 16:50:30 +000010907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010908QualType
10909TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010910 ArrayType::ArraySizeModifier SizeMod,
10911 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010912 unsigned IndexTypeQuals,
10913 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010914 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010915 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010916}
10917
10918template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010919QualType
Mike Stump11289f42009-09-09 15:08:12 +000010920TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010921 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010922 unsigned IndexTypeQuals,
10923 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010924 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010925 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010926}
Mike Stump11289f42009-09-09 15:08:12 +000010927
Douglas Gregord6ff3322009-08-04 16:50:30 +000010928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010929QualType
10930TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010931 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010932 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010933 unsigned IndexTypeQuals,
10934 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010935 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010936 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010937 IndexTypeQuals, BracketsRange);
10938}
10939
10940template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010941QualType
10942TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010943 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010944 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010945 unsigned IndexTypeQuals,
10946 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010947 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010948 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010949 IndexTypeQuals, BracketsRange);
10950}
10951
10952template<typename Derived>
10953QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010954 unsigned NumElements,
10955 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010956 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010957 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010958}
Mike Stump11289f42009-09-09 15:08:12 +000010959
Douglas Gregord6ff3322009-08-04 16:50:30 +000010960template<typename Derived>
10961QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10962 unsigned NumElements,
10963 SourceLocation AttributeLoc) {
10964 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10965 NumElements, true);
10966 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010967 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10968 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010969 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010970}
Mike Stump11289f42009-09-09 15:08:12 +000010971
Douglas Gregord6ff3322009-08-04 16:50:30 +000010972template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010973QualType
10974TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010975 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010976 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010977 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010978}
Mike Stump11289f42009-09-09 15:08:12 +000010979
Douglas Gregord6ff3322009-08-04 16:50:30 +000010980template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010981QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10982 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010983 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010984 const FunctionProtoType::ExtProtoInfo &EPI) {
10985 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010986 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010987 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010988 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010989}
Mike Stump11289f42009-09-09 15:08:12 +000010990
Douglas Gregord6ff3322009-08-04 16:50:30 +000010991template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010992QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10993 return SemaRef.Context.getFunctionNoProtoType(T);
10994}
10995
10996template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010997QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10998 assert(D && "no decl found");
10999 if (D->isInvalidDecl()) return QualType();
11000
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011001 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011002 TypeDecl *Ty;
11003 if (isa<UsingDecl>(D)) {
11004 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011005 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011006 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11007
11008 // A valid resolved using typename decl points to exactly one type decl.
11009 assert(++Using->shadow_begin() == Using->shadow_end());
11010 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011011
John McCallb96ec562009-12-04 22:46:56 +000011012 } else {
11013 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11014 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11015 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11016 }
11017
11018 return SemaRef.Context.getTypeDeclType(Ty);
11019}
11020
11021template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011022QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11023 SourceLocation Loc) {
11024 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011025}
11026
11027template<typename Derived>
11028QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11029 return SemaRef.Context.getTypeOfType(Underlying);
11030}
11031
11032template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011033QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11034 SourceLocation Loc) {
11035 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011036}
11037
11038template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011039QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11040 UnaryTransformType::UTTKind UKind,
11041 SourceLocation Loc) {
11042 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11043}
11044
11045template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011046QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011047 TemplateName Template,
11048 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011049 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011050 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011051}
Mike Stump11289f42009-09-09 15:08:12 +000011052
Douglas Gregor1135c352009-08-06 05:28:30 +000011053template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011054QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11055 SourceLocation KWLoc) {
11056 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11057}
11058
11059template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011060TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011061TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011062 bool TemplateKW,
11063 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011064 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011065 Template);
11066}
11067
11068template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011069TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011070TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11071 const IdentifierInfo &Name,
11072 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011073 QualType ObjectType,
11074 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011075 UnqualifiedId TemplateName;
11076 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011077 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011078 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011079 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011080 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011081 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011082 /*EnteringContext=*/false,
11083 Template);
John McCall31f82722010-11-12 08:19:04 +000011084 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011085}
Mike Stump11289f42009-09-09 15:08:12 +000011086
Douglas Gregora16548e2009-08-11 05:31:07 +000011087template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011088TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011089TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011090 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011091 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011092 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011093 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011094 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011095 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011096 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011097 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011098 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011099 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011100 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011101 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011102 /*EnteringContext=*/false,
11103 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011104 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011105}
Chad Rosier1dcde962012-08-08 18:46:20 +000011106
Douglas Gregor71395fa2009-11-04 00:56:37 +000011107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011108ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011109TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11110 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011111 Expr *OrigCallee,
11112 Expr *First,
11113 Expr *Second) {
11114 Expr *Callee = OrigCallee->IgnoreParenCasts();
11115 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011116
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011117 if (First->getObjectKind() == OK_ObjCProperty) {
11118 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11119 if (BinaryOperator::isAssignmentOp(Opc))
11120 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11121 First, Second);
11122 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11123 if (Result.isInvalid())
11124 return ExprError();
11125 First = Result.get();
11126 }
11127
11128 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11129 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11130 if (Result.isInvalid())
11131 return ExprError();
11132 Second = Result.get();
11133 }
11134
Douglas Gregora16548e2009-08-11 05:31:07 +000011135 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011136 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011137 if (!First->getType()->isOverloadableType() &&
11138 !Second->getType()->isOverloadableType())
11139 return getSema().CreateBuiltinArraySubscriptExpr(First,
11140 Callee->getLocStart(),
11141 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011142 } else if (Op == OO_Arrow) {
11143 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011144 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11145 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011146 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011147 // The argument is not of overloadable type, so try to create a
11148 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011149 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011150 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011151
John McCallb268a282010-08-23 23:25:46 +000011152 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011153 }
11154 } else {
John McCallb268a282010-08-23 23:25:46 +000011155 if (!First->getType()->isOverloadableType() &&
11156 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011157 // Neither of the arguments is an overloadable type, so try to
11158 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011159 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011160 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011161 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011162 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011164
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011165 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011166 }
11167 }
Mike Stump11289f42009-09-09 15:08:12 +000011168
11169 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011170 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011171 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011172
John McCallb268a282010-08-23 23:25:46 +000011173 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011174 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011175 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011176 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011177 // If we've resolved this to a particular non-member function, just call
11178 // that function. If we resolved it to a member function,
11179 // CreateOverloaded* will find that function for us.
11180 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11181 if (!isa<CXXMethodDecl>(ND))
11182 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011183 }
Mike Stump11289f42009-09-09 15:08:12 +000011184
Douglas Gregora16548e2009-08-11 05:31:07 +000011185 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011186 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011187 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011188
Douglas Gregora16548e2009-08-11 05:31:07 +000011189 // Create the overloaded operator invocation for unary operators.
11190 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011191 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011192 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011193 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011194 }
Mike Stump11289f42009-09-09 15:08:12 +000011195
Douglas Gregore9d62932011-07-15 16:25:15 +000011196 if (Op == OO_Subscript) {
11197 SourceLocation LBrace;
11198 SourceLocation RBrace;
11199
11200 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011201 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011202 LBrace = SourceLocation::getFromRawEncoding(
11203 NameLoc.CXXOperatorName.BeginOpNameLoc);
11204 RBrace = SourceLocation::getFromRawEncoding(
11205 NameLoc.CXXOperatorName.EndOpNameLoc);
11206 } else {
11207 LBrace = Callee->getLocStart();
11208 RBrace = OpLoc;
11209 }
11210
11211 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11212 First, Second);
11213 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011214
Douglas Gregora16548e2009-08-11 05:31:07 +000011215 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011216 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011217 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011218 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11219 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011220 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011221
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011222 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011223}
Mike Stump11289f42009-09-09 15:08:12 +000011224
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011225template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011226ExprResult
John McCallb268a282010-08-23 23:25:46 +000011227TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011228 SourceLocation OperatorLoc,
11229 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011230 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011231 TypeSourceInfo *ScopeType,
11232 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011233 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011234 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011235 QualType BaseType = Base->getType();
11236 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011237 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011238 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011239 !BaseType->getAs<PointerType>()->getPointeeType()
11240 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011241 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011242 return SemaRef.BuildPseudoDestructorExpr(
11243 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11244 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011245 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011246
Douglas Gregor678f90d2010-02-25 01:56:36 +000011247 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011248 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11249 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11250 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11251 NameInfo.setNamedTypeInfo(DestroyedType);
11252
Richard Smith8e4a3862012-05-15 06:15:11 +000011253 // The scope type is now known to be a valid nested name specifier
11254 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011255 if (ScopeType) {
11256 if (!ScopeType->getType()->getAs<TagType>()) {
11257 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11258 diag::err_expected_class_or_namespace)
11259 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11260 return ExprError();
11261 }
11262 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11263 CCLoc);
11264 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011265
Abramo Bagnara7945c982012-01-27 09:46:47 +000011266 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011267 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011268 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011269 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011270 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011271 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011272 /*TemplateArgs*/ nullptr,
11273 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011274}
11275
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011276template<typename Derived>
11277StmtResult
11278TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011279 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011280 CapturedDecl *CD = S->getCapturedDecl();
11281 unsigned NumParams = CD->getNumParams();
11282 unsigned ContextParamPos = CD->getContextParamPosition();
11283 SmallVector<Sema::CapturedParamNameType, 4> Params;
11284 for (unsigned I = 0; I < NumParams; ++I) {
11285 if (I != ContextParamPos) {
11286 Params.push_back(
11287 std::make_pair(
11288 CD->getParam(I)->getName(),
11289 getDerived().TransformType(CD->getParam(I)->getType())));
11290 } else {
11291 Params.push_back(std::make_pair(StringRef(), QualType()));
11292 }
11293 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011294 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011295 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011296 StmtResult Body;
11297 {
11298 Sema::CompoundScopeRAII CompoundScope(getSema());
11299 Body = getDerived().TransformStmt(S->getCapturedStmt());
11300 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011301
11302 if (Body.isInvalid()) {
11303 getSema().ActOnCapturedRegionError();
11304 return StmtError();
11305 }
11306
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011307 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011308}
11309
Douglas Gregord6ff3322009-08-04 16:50:30 +000011310} // end namespace clang
11311
Hans Wennborg59dbe862015-09-29 20:56:43 +000011312#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H