blob: ebd33db1602875d918e1da0b1ab03ebeaefdfa75 [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.
Craig Topper99d23532015-12-24 23:58:29 +0000394 bool TransformExprs(Expr *const *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
Richard Smith03a4aa32016-06-23 19:02:52 +0000413 /// \brief Transform the specified condition.
414 ///
415 /// By default, this transforms the variable and expression and rebuilds
416 /// the condition.
417 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
418 Expr *Expr,
419 Sema::ConditionKind Kind);
420
Chad Rosier1dcde962012-08-08 18:46:20 +0000421 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 /// place them on the new declaration.
423 ///
424 /// By default, this operation does nothing. Subclasses may override this
425 /// behavior to transform attributes.
426 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 /// \brief Note that a local declaration has been transformed by this
429 /// transformer.
430 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000431 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000432 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
433 /// the transformer itself has to transform the declarations. This routine
434 /// can be overridden by a subclass that keeps track of such mappings.
435 void transformedLocalDecl(Decl *Old, Decl *New) {
436 TransformedLocalDecls[Old] = New;
437 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregorebe10102009-08-20 07:17:43 +0000439 /// \brief Transform the definition of the given declaration.
440 ///
Mike Stump11289f42009-09-09 15:08:12 +0000441 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000442 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
444 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000445 }
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000447 /// \brief Transform the given declaration, which was the first part of a
448 /// nested-name-specifier in a member access expression.
449 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000450 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000451 /// identifier in a nested-name-specifier of a member access expression, e.g.,
452 /// the \c T in \c x->T::member
453 ///
454 /// By default, invokes TransformDecl() to transform the declaration.
455 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000456 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
457 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000459
Douglas Gregor14454802011-02-25 02:25:35 +0000460 /// \brief Transform the given nested-name-specifier with source-location
461 /// information.
462 ///
463 /// By default, transforms all of the types and declarations within the
464 /// nested-name-specifier. Subclasses may override this function to provide
465 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000466 NestedNameSpecifierLoc
467 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
468 QualType ObjectType = QualType(),
469 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000470
Douglas Gregorf816bd72009-09-03 22:13:48 +0000471 /// \brief Transform the given declaration name.
472 ///
473 /// By default, transforms the types of conversion function, constructor,
474 /// and destructor names and then (if needed) rebuilds the declaration name.
475 /// Identifiers and selectors are returned unmodified. Sublcasses may
476 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000477 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000478 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000481 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// \param SS The nested-name-specifier that qualifies the template
483 /// name. This nested-name-specifier must already have been transformed.
484 ///
485 /// \param Name The template name to transform.
486 ///
487 /// \param NameLoc The source location of the template name.
488 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000489 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000490 /// access expression, this is the type of the object whose member template
491 /// is being referenced.
492 ///
493 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
494 /// also refers to a name within the current (lexical) scope, this is the
495 /// declaration it refers to.
496 ///
497 /// By default, transforms the template name by transforming the declarations
498 /// and nested-name-specifiers that occur within the template name.
499 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000500 TemplateName
501 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
502 SourceLocation NameLoc,
503 QualType ObjectType = QualType(),
504 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000505
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// \brief Transform the given template argument.
507 ///
Mike Stump11289f42009-09-09 15:08:12 +0000508 /// By default, this operation transforms the type, expression, or
509 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000510 /// new template argument from the transformed result. Subclasses may
511 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000512 ///
513 /// Returns true if there was an error.
514 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000515 TemplateArgumentLoc &Output,
516 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000517
Douglas Gregor62e06f22010-12-20 17:31:10 +0000518 /// \brief Transform the given set of template arguments.
519 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000520 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000521 /// in the input set using \c TransformTemplateArgument(), and appends
522 /// the transformed arguments to the output list.
523 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000524 /// Note that this overload of \c TransformTemplateArguments() is merely
525 /// a convenience function. Subclasses that wish to override this behavior
526 /// should override the iterator-based member template version.
527 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000528 /// \param Inputs The set of template arguments to be transformed.
529 ///
530 /// \param NumInputs The number of template arguments in \p Inputs.
531 ///
532 /// \param Outputs The set of transformed template arguments output by this
533 /// routine.
534 ///
535 /// Returns true if an error occurred.
536 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
537 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentListInfo &Outputs,
539 bool Uneval = false) {
540 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
541 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000543
544 /// \brief Transform the given set of template arguments.
545 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000546 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000547 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000548 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000549 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 /// \param First An iterator to the first template argument.
551 ///
552 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000553 ///
554 /// \param Outputs The set of transformed template arguments output by this
555 /// routine.
556 ///
557 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 template<typename InputIterator>
559 bool TransformTemplateArguments(InputIterator First,
560 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563
John McCall0ad16662009-10-29 08:12:44 +0000564 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
565 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
566 TemplateArgumentLoc &ArgLoc);
567
John McCallbcd03502009-12-07 02:54:59 +0000568 /// \brief Fakes up a TypeSourceInfo for a type.
569 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
570 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000571 getDerived().getBaseLocation());
572 }
Mike Stump11289f42009-09-09 15:08:12 +0000573
John McCall550e0c22009-10-21 00:40:46 +0000574#define ABSTRACT_TYPELOC(CLASS, PARENT)
575#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000576 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000577#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Richard Smith2e321552014-11-12 02:00:47 +0000579 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000580 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
581 FunctionProtoTypeLoc TL,
582 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000583 unsigned ThisTypeQuals,
584 Fn TransformExceptionSpec);
585
586 bool TransformExceptionSpec(SourceLocation Loc,
587 FunctionProtoType::ExceptionSpecInfo &ESI,
588 SmallVectorImpl<QualType> &Exceptions,
589 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000590
David Majnemerfad8f482013-10-15 09:33:02 +0000591 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000592
Chad Rosier1dcde962012-08-08 18:46:20 +0000593 QualType
John McCall31f82722010-11-12 08:19:04 +0000594 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
595 TemplateSpecializationTypeLoc TL,
596 TemplateName Template);
597
Chad Rosier1dcde962012-08-08 18:46:20 +0000598 QualType
John McCall31f82722010-11-12 08:19:04 +0000599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
600 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000601 TemplateName Template,
602 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000603
Nico Weberc153d242014-07-28 00:02:09 +0000604 QualType TransformDependentTemplateSpecializationType(
605 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
606 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000607
John McCall58f10c32010-03-11 09:03:00 +0000608 /// \brief Transforms the parameters of a function type into the
609 /// given vectors.
610 ///
611 /// The result vectors should be kept in sync; null entries in the
612 /// variables vector are acceptable.
613 ///
614 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000615 bool TransformFunctionTypeParams(
616 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
617 const QualType *ParamTypes,
618 const FunctionProtoType::ExtParameterInfo *ParamInfos,
619 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
620 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000621
622 /// \brief Transforms a single function-type parameter. Return null
623 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000624 ///
625 /// \param indexAdjustment - A number to add to the parameter's
626 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000627 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000628 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000629 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000630 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000631
John McCall31f82722010-11-12 08:19:04 +0000632 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000633
John McCalldadc5752010-08-24 06:29:42 +0000634 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
635 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000636
Faisal Vali2cba1332013-10-23 06:44:28 +0000637 TemplateParameterList *TransformTemplateParameterList(
638 TemplateParameterList *TPL) {
639 return TPL;
640 }
641
Richard Smithdb2630f2012-10-21 03:28:35 +0000642 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000643
Richard Smithdb2630f2012-10-21 03:28:35 +0000644 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000645 bool IsAddressOfOperand,
646 TypeSourceInfo **RecoveryTSI);
647
648 ExprResult TransformParenDependentScopeDeclRefExpr(
649 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
650 TypeSourceInfo **RecoveryTSI);
651
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000652 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000653
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000654// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
655// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000656#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000658 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000659#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000660 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000661 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000662#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000663#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000664
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000665#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000666 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667 OMPClause *Transform ## Class(Class *S);
668#include "clang/Basic/OpenMPKinds.def"
669
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// \brief Build a new pointer type given its pointee type.
671 ///
672 /// By default, performs semantic analysis when building the pointer type.
673 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000674 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675
676 /// \brief Build a new block pointer type given its pointee type.
677 ///
Mike Stump11289f42009-09-09 15:08:12 +0000678 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000680 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681
John McCall70dd5f62009-10-30 00:06:24 +0000682 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000683 ///
John McCall70dd5f62009-10-30 00:06:24 +0000684 /// By default, performs semantic analysis when building the
685 /// reference type. Subclasses may override this routine to provide
686 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000687 ///
John McCall70dd5f62009-10-30 00:06:24 +0000688 /// \param LValue whether the type was written with an lvalue sigil
689 /// or an rvalue sigil.
690 QualType RebuildReferenceType(QualType ReferentType,
691 bool LValue,
692 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new member pointer type given the pointee type and the
695 /// class type it refers into.
696 ///
697 /// By default, performs semantic analysis when building the member pointer
698 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
700 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000701
Manman Rene6be26c2016-09-13 17:25:08 +0000702 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
703 SourceLocation ProtocolLAngleLoc,
704 ArrayRef<ObjCProtocolDecl *> Protocols,
705 ArrayRef<SourceLocation> ProtocolLocs,
706 SourceLocation ProtocolRAngleLoc);
707
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000708 /// \brief Build an Objective-C object type.
709 ///
710 /// By default, performs semantic analysis when building the object type.
711 /// Subclasses may override this routine to provide different behavior.
712 QualType RebuildObjCObjectType(QualType BaseType,
713 SourceLocation Loc,
714 SourceLocation TypeArgsLAngleLoc,
715 ArrayRef<TypeSourceInfo *> TypeArgs,
716 SourceLocation TypeArgsRAngleLoc,
717 SourceLocation ProtocolLAngleLoc,
718 ArrayRef<ObjCProtocolDecl *> Protocols,
719 ArrayRef<SourceLocation> ProtocolLocs,
720 SourceLocation ProtocolRAngleLoc);
721
722 /// \brief Build a new Objective-C object pointer type given the pointee type.
723 ///
724 /// By default, directly builds the pointer type, with no additional semantic
725 /// analysis.
726 QualType RebuildObjCObjectPointerType(QualType PointeeType,
727 SourceLocation Star);
728
Douglas Gregord6ff3322009-08-04 16:50:30 +0000729 /// \brief Build a new array type given the element type, size
730 /// modifier, size of the array (if known), size expression, and index type
731 /// qualifiers.
732 ///
733 /// By default, performs semantic analysis when building the array type.
734 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000735 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000736 QualType RebuildArrayType(QualType ElementType,
737 ArrayType::ArraySizeModifier SizeMod,
738 const llvm::APInt *Size,
739 Expr *SizeExpr,
740 unsigned IndexTypeQuals,
741 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 /// \brief Build a new constant array type given the element type, size
744 /// modifier, (known) size of the array, and index type qualifiers.
745 ///
746 /// By default, performs semantic analysis when building the array type.
747 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000748 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000749 ArrayType::ArraySizeModifier SizeMod,
750 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000751 unsigned IndexTypeQuals,
752 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 /// \brief Build a new incomplete array type given the element type, size
755 /// modifier, and index type qualifiers.
756 ///
757 /// By default, performs semantic analysis when building the array type.
758 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000759 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000761 unsigned IndexTypeQuals,
762 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763
Mike Stump11289f42009-09-09 15:08:12 +0000764 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// size modifier, size expression, and index type qualifiers.
766 ///
767 /// By default, performs semantic analysis when building the array type.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000769 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000771 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000772 unsigned IndexTypeQuals,
773 SourceRange BracketsRange);
774
Mike Stump11289f42009-09-09 15:08:12 +0000775 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 /// size modifier, size expression, and index type qualifiers.
777 ///
778 /// By default, performs semantic analysis when building the array type.
779 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000780 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000782 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 unsigned IndexTypeQuals,
784 SourceRange BracketsRange);
785
786 /// \brief Build a new vector type given the element type and
787 /// number of elements.
788 ///
789 /// By default, performs semantic analysis when building the vector type.
790 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000791 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000792 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000793
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 /// \brief Build a new extended vector type given the element type and
795 /// number of elements.
796 ///
797 /// By default, performs semantic analysis when building the vector type.
798 /// Subclasses may override this routine to provide different behavior.
799 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
800 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000801
802 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// given the element type and number of elements.
804 ///
805 /// By default, performs semantic analysis when building the vector type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000808 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new function type.
812 ///
813 /// By default, performs semantic analysis when building the function type.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000816 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000817 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000818
John McCall550e0c22009-10-21 00:40:46 +0000819 /// \brief Build a new unprototyped function type.
820 QualType RebuildFunctionNoProtoType(QualType ResultType);
821
John McCallb96ec562009-12-04 22:46:56 +0000822 /// \brief Rebuild an unresolved typename type, given the decl that
823 /// the UnresolvedUsingTypenameDecl was transformed to.
824 QualType RebuildUnresolvedUsingType(Decl *D);
825
Douglas Gregord6ff3322009-08-04 16:50:30 +0000826 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000827 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 return SemaRef.Context.getTypeDeclType(Typedef);
829 }
830
831 /// \brief Build a new class/struct/union type.
832 QualType RebuildRecordType(RecordDecl *Record) {
833 return SemaRef.Context.getTypeDeclType(Record);
834 }
835
836 /// \brief Build a new Enum type.
837 QualType RebuildEnumType(EnumDecl *Enum) {
838 return SemaRef.Context.getTypeDeclType(Enum);
839 }
John McCallfcc33b02009-09-05 00:15:47 +0000840
Mike Stump11289f42009-09-09 15:08:12 +0000841 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000842 ///
843 /// By default, performs semantic analysis when building the typeof type.
844 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000845 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000846
Mike Stump11289f42009-09-09 15:08:12 +0000847 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 ///
849 /// By default, builds a new TypeOfType with the given underlying type.
850 QualType RebuildTypeOfType(QualType Underlying);
851
Alexis Hunte852b102011-05-24 22:41:36 +0000852 /// \brief Build a new unary transform type.
853 QualType RebuildUnaryTransformType(QualType BaseType,
854 UnaryTransformType::UTTKind UKind,
855 SourceLocation Loc);
856
Richard Smith74aeef52013-04-26 16:15:35 +0000857 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000858 ///
859 /// By default, performs semantic analysis when building the decltype type.
860 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000861 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000862
Richard Smith74aeef52013-04-26 16:15:35 +0000863 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000864 ///
865 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000866 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000867 // Note, IsDependent is always false here: we implicitly convert an 'auto'
868 // which has been deduced to a dependent type into an undeduced 'auto', so
869 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000870 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000871 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000872 }
873
Douglas Gregord6ff3322009-08-04 16:50:30 +0000874 /// \brief Build a new template specialization type.
875 ///
876 /// By default, performs semantic analysis when building the template
877 /// specialization type. Subclasses may override this routine to provide
878 /// different behavior.
879 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000880 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000881 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000882
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000883 /// \brief Build a new parenthesized type.
884 ///
885 /// By default, builds a new ParenType type from the inner type.
886 /// Subclasses may override this routine to provide different behavior.
887 QualType RebuildParenType(QualType InnerType) {
888 return SemaRef.Context.getParenType(InnerType);
889 }
890
Douglas Gregord6ff3322009-08-04 16:50:30 +0000891 /// \brief Build a new qualified name type.
892 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000893 /// By default, builds a new ElaboratedType type from the keyword,
894 /// the nested-name-specifier and the named type.
895 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000896 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
897 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000898 NestedNameSpecifierLoc QualifierLoc,
899 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000900 return SemaRef.Context.getElaboratedType(Keyword,
901 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000902 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000903 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000904
905 /// \brief Build a new typename type that refers to a template-id.
906 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000907 /// By default, builds a new DependentNameType type from the
908 /// nested-name-specifier and the given type. Subclasses may override
909 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000910 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000911 ElaboratedTypeKeyword Keyword,
912 NestedNameSpecifierLoc QualifierLoc,
913 const IdentifierInfo *Name,
914 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000915 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000916 // Rebuild the template name.
917 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000918 CXXScopeSpec SS;
919 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000920 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000921 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
922 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000923
Douglas Gregora7a795b2011-03-01 20:11:18 +0000924 if (InstName.isNull())
925 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000926
Douglas Gregora7a795b2011-03-01 20:11:18 +0000927 // If it's still dependent, make a dependent specialization.
928 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000929 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
930 QualifierLoc.getNestedNameSpecifier(),
931 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000932 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000933
Douglas Gregora7a795b2011-03-01 20:11:18 +0000934 // Otherwise, make an elaborated type wrapping a non-dependent
935 // specialization.
936 QualType T =
937 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
938 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000939
Craig Topperc3ec1492014-05-26 06:22:03 +0000940 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000941 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000942
943 return SemaRef.Context.getElaboratedType(Keyword,
944 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000945 T);
946 }
947
Douglas Gregord6ff3322009-08-04 16:50:30 +0000948 /// \brief Build a new typename type that refers to an identifier.
949 ///
950 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000951 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000952 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000953 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 NestedNameSpecifierLoc QualifierLoc,
956 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000957 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000958 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000959 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000961 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000962 // If the name is still dependent, just build a new dependent name type.
963 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000964 return SemaRef.Context.getDependentNameType(Keyword,
965 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000966 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000967 }
968
Abramo Bagnara6150c882010-05-11 21:36:43 +0000969 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000970 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000971 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000972
973 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
974
Abramo Bagnarad7548482010-05-19 21:37:53 +0000975 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000976 // into a non-dependent elaborated-type-specifier. Find the tag we're
977 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000978 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000979 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
980 if (!DC)
981 return QualType();
982
John McCallbf8c5192010-05-27 06:40:31 +0000983 if (SemaRef.RequireCompleteDeclContext(SS, DC))
984 return QualType();
985
Craig Topperc3ec1492014-05-26 06:22:03 +0000986 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000987 SemaRef.LookupQualifiedName(Result, DC);
988 switch (Result.getResultKind()) {
989 case LookupResult::NotFound:
990 case LookupResult::NotFoundInCurrentInstantiation:
991 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000992
Douglas Gregore677daf2010-03-31 22:19:08 +0000993 case LookupResult::Found:
994 Tag = Result.getAsSingle<TagDecl>();
995 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000996
Douglas Gregore677daf2010-03-31 22:19:08 +0000997 case LookupResult::FoundOverloaded:
998 case LookupResult::FoundUnresolvedValue:
999 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001000
Douglas Gregore677daf2010-03-31 22:19:08 +00001001 case LookupResult::Ambiguous:
1002 // Let the LookupResult structure handle ambiguities.
1003 return QualType();
1004 }
1005
1006 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001007 // Check where the name exists but isn't a tag type and use that to emit
1008 // better diagnostics.
1009 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1010 SemaRef.LookupQualifiedName(Result, DC);
1011 switch (Result.getResultKind()) {
1012 case LookupResult::Found:
1013 case LookupResult::FoundOverloaded:
1014 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001015 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001016 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1017 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1018 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001019 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1020 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001021 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001022 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001023 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001024 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001025 break;
1026 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001027 return QualType();
1028 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001029
Richard Trieucaa33d32011-06-10 03:11:26 +00001030 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001031 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001032 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001033 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1034 return QualType();
1035 }
1036
1037 // Build the elaborated-type-specifier type.
1038 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001039 return SemaRef.Context.getElaboratedType(Keyword,
1040 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001041 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001042 }
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregor822d0302011-01-12 17:07:58 +00001044 /// \brief Build a new pack expansion type.
1045 ///
1046 /// By default, builds a new PackExpansionType type from the given pattern.
1047 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001048 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001049 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001050 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001051 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001052 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1053 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001054 }
1055
Eli Friedman0dfb8892011-10-06 23:00:33 +00001056 /// \brief Build a new atomic type given its value type.
1057 ///
1058 /// By default, performs semantic analysis when building the atomic type.
1059 /// Subclasses may override this routine to provide different behavior.
1060 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1061
Xiuli Pan9c14e282016-01-09 12:53:17 +00001062 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001063 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1064 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001065
Douglas Gregor71dc5092009-08-06 06:41:21 +00001066 /// \brief Build a new template name given a nested name specifier, a flag
1067 /// indicating whether the "template" keyword was provided, and the template
1068 /// that the template name refers to.
1069 ///
1070 /// By default, builds the new template name directly. Subclasses may override
1071 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001072 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001073 bool TemplateKW,
1074 TemplateDecl *Template);
1075
Douglas Gregor71dc5092009-08-06 06:41:21 +00001076 /// \brief Build a new template name given a nested name specifier and the
1077 /// name that is referred to as a template.
1078 ///
1079 /// By default, performs semantic analysis to determine whether the name can
1080 /// be resolved to a specific template, then builds the appropriate kind of
1081 /// template name. Subclasses may override this routine to provide different
1082 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001083 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1084 const IdentifierInfo &Name,
1085 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001086 QualType ObjectType,
1087 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregor71395fa2009-11-04 00:56:37 +00001089 /// \brief Build a new template name given a nested name specifier and the
1090 /// overloaded operator name that is referred to as a template.
1091 ///
1092 /// By default, performs semantic analysis to determine whether the name can
1093 /// be resolved to a specific template, then builds the appropriate kind of
1094 /// template name. Subclasses may override this routine to provide different
1095 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001096 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001097 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001098 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001099 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001100
1101 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001102 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001103 ///
1104 /// By default, performs semantic analysis to determine whether the name can
1105 /// be resolved to a specific template, then builds the appropriate kind of
1106 /// template name. Subclasses may override this routine to provide different
1107 /// behavior.
1108 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1109 const TemplateArgument &ArgPack) {
1110 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1111 }
1112
Douglas Gregorebe10102009-08-20 07:17:43 +00001113 /// \brief Build a new compound statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 MultiStmtArg Statements,
1119 SourceLocation RBraceLoc,
1120 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001121 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001122 IsStmtExpr);
1123 }
1124
1125 /// \brief Build a new case statement.
1126 ///
1127 /// By default, performs semantic analysis to build the new statement.
1128 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001129 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001130 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001132 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001133 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001134 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 ColonLoc);
1136 }
Mike Stump11289f42009-09-09 15:08:12 +00001137
Douglas Gregorebe10102009-08-20 07:17:43 +00001138 /// \brief Attach the body to a new case statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001142 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001143 getSema().ActOnCaseStmtBody(S, Body);
1144 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001145 }
Mike Stump11289f42009-09-09 15:08:12 +00001146
Douglas Gregorebe10102009-08-20 07:17:43 +00001147 /// \brief Build a new default statement.
1148 ///
1149 /// By default, performs semantic analysis to build the new statement.
1150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001151 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001152 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001153 Stmt *SubStmt) {
1154 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001155 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001156 }
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregorebe10102009-08-20 07:17:43 +00001158 /// \brief Build a new label statement.
1159 ///
1160 /// By default, performs semantic analysis to build the new statement.
1161 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001162 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1163 SourceLocation ColonLoc, Stmt *SubStmt) {
1164 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 }
Mike Stump11289f42009-09-09 15:08:12 +00001166
Richard Smithc202b282012-04-14 00:33:13 +00001167 /// \brief Build a new label statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001171 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1172 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001173 Stmt *SubStmt) {
1174 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1175 }
1176
Douglas Gregorebe10102009-08-20 07:17:43 +00001177 /// \brief Build a new "if" statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001181 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001182 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001183 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001184 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001185 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 }
Mike Stump11289f42009-09-09 15:08:12 +00001187
Douglas Gregorebe10102009-08-20 07:17:43 +00001188 /// \brief Start building a new switch statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001192 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001193 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001194 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 }
Mike Stump11289f42009-09-09 15:08:12 +00001196
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 /// \brief Attach the body to the switch statement.
1198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001201 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001202 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001203 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001204 }
1205
1206 /// \brief Build a new while statement.
1207 ///
1208 /// By default, performs semantic analysis to build the new statement.
1209 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001210 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1211 Sema::ConditionResult Cond, Stmt *Body) {
1212 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregorebe10102009-08-20 07:17:43 +00001215 /// \brief Build a new do-while statement.
1216 ///
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001220 SourceLocation WhileLoc, SourceLocation LParenLoc,
1221 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001222 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1223 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001224 }
1225
1226 /// \brief Build a new for statement.
1227 ///
1228 /// By default, performs semantic analysis to build the new statement.
1229 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001230 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001231 Stmt *Init, Sema::ConditionResult Cond,
1232 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1233 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001234 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001235 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 /// \brief Build a new goto statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001242 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1243 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001244 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001245 }
1246
1247 /// \brief Build a new indirect goto statement.
1248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001251 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001252 SourceLocation StarLoc,
1253 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001254 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 }
Mike Stump11289f42009-09-09 15:08:12 +00001256
Douglas Gregorebe10102009-08-20 07:17:43 +00001257 /// \brief Build a new return statement.
1258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001261 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001262 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 }
Mike Stump11289f42009-09-09 15:08:12 +00001264
Douglas Gregorebe10102009-08-20 07:17:43 +00001265 /// \brief Build a new declaration statement.
1266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001269 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001270 SourceLocation StartLoc, SourceLocation EndLoc) {
1271 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001272 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 }
Mike Stump11289f42009-09-09 15:08:12 +00001274
Anders Carlssonaaeef072010-01-24 05:50:09 +00001275 /// \brief Build a new inline asm statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001279 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1280 bool IsVolatile, unsigned NumOutputs,
1281 unsigned NumInputs, IdentifierInfo **Names,
1282 MultiExprArg Constraints, MultiExprArg Exprs,
1283 Expr *AsmString, MultiExprArg Clobbers,
1284 SourceLocation RParenLoc) {
1285 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1286 NumInputs, Names, Constraints, Exprs,
1287 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001288 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001289
Chad Rosier32503022012-06-11 20:47:18 +00001290 /// \brief Build a new MS style inline asm statement.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001294 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001295 ArrayRef<Token> AsmToks,
1296 StringRef AsmString,
1297 unsigned NumOutputs, unsigned NumInputs,
1298 ArrayRef<StringRef> Constraints,
1299 ArrayRef<StringRef> Clobbers,
1300 ArrayRef<Expr*> Exprs,
1301 SourceLocation EndLoc) {
1302 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1303 NumOutputs, NumInputs,
1304 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001305 }
1306
Richard Smith9f690bd2015-10-27 06:02:45 +00001307 /// \brief Build a new co_return statement.
1308 ///
1309 /// By default, performs semantic analysis to build the new statement.
1310 /// Subclasses may override this routine to provide different behavior.
1311 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1312 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1313 }
1314
1315 /// \brief Build a new co_await expression.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1320 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1321 }
1322
1323 /// \brief Build a new co_yield expression.
1324 ///
1325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
1327 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1328 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1329 }
1330
James Dennett2a4d13c2012-06-15 07:13:21 +00001331 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001336 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001337 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001338 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001339 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001340 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001341 }
1342
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001343 /// \brief Rebuild an Objective-C exception declaration.
1344 ///
1345 /// By default, performs semantic analysis to build the new declaration.
1346 /// Subclasses may override this routine to provide different behavior.
1347 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1348 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001349 return getSema().BuildObjCExceptionDecl(TInfo, T,
1350 ExceptionDecl->getInnerLocStart(),
1351 ExceptionDecl->getLocation(),
1352 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001354
James Dennett2a4d13c2012-06-15 07:13:21 +00001355 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001356 ///
1357 /// By default, performs semantic analysis to build the new statement.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001360 SourceLocation RParenLoc,
1361 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001362 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001363 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001364 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001365 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001366
James Dennett2a4d13c2012-06-15 07:13:21 +00001367 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001368 ///
1369 /// By default, performs semantic analysis to build the new statement.
1370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001371 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001372 Stmt *Body) {
1373 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001374 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001375
James Dennett2a4d13c2012-06-15 07:13:21 +00001376 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001380 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001381 Expr *Operand) {
1382 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001384
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001385 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001389 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001390 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001391 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001392 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001393 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001394 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001395 return getSema().ActOnOpenMPExecutableDirective(
1396 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001397 }
1398
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001399 /// \brief Build a new OpenMP 'if' clause.
1400 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001401 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001402 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001403 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1404 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001405 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001406 SourceLocation NameModifierLoc,
1407 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001408 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001409 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1410 LParenLoc, NameModifierLoc, ColonLoc,
1411 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001412 }
1413
Alexey Bataev3778b602014-07-17 07:32:53 +00001414 /// \brief Build a new OpenMP 'final' clause.
1415 ///
1416 /// By default, performs semantic analysis to build the new OpenMP clause.
1417 /// Subclasses may override this routine to provide different behavior.
1418 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1419 SourceLocation LParenLoc,
1420 SourceLocation EndLoc) {
1421 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1422 EndLoc);
1423 }
1424
Alexey Bataev568a8332014-03-06 06:15:19 +00001425 /// \brief Build a new OpenMP 'num_threads' clause.
1426 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001427 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001428 /// Subclasses may override this routine to provide different behavior.
1429 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1430 SourceLocation StartLoc,
1431 SourceLocation LParenLoc,
1432 SourceLocation EndLoc) {
1433 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1434 LParenLoc, EndLoc);
1435 }
1436
Alexey Bataev62c87d22014-03-21 04:51:18 +00001437 /// \brief Build a new OpenMP 'safelen' clause.
1438 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001439 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001440 /// Subclasses may override this routine to provide different behavior.
1441 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1442 SourceLocation LParenLoc,
1443 SourceLocation EndLoc) {
1444 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1445 }
1446
Alexey Bataev66b15b52015-08-21 11:14:16 +00001447 /// \brief Build a new OpenMP 'simdlen' clause.
1448 ///
1449 /// By default, performs semantic analysis to build the new OpenMP clause.
1450 /// Subclasses may override this routine to provide different behavior.
1451 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1452 SourceLocation LParenLoc,
1453 SourceLocation EndLoc) {
1454 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1455 }
1456
Alexander Musman8bd31e62014-05-27 15:12:19 +00001457 /// \brief Build a new OpenMP 'collapse' clause.
1458 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001459 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001460 /// Subclasses may override this routine to provide different behavior.
1461 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1462 SourceLocation LParenLoc,
1463 SourceLocation EndLoc) {
1464 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1465 EndLoc);
1466 }
1467
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001468 /// \brief Build a new OpenMP 'default' clause.
1469 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001470 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001471 /// Subclasses may override this routine to provide different behavior.
1472 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1473 SourceLocation KindKwLoc,
1474 SourceLocation StartLoc,
1475 SourceLocation LParenLoc,
1476 SourceLocation EndLoc) {
1477 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1478 StartLoc, LParenLoc, EndLoc);
1479 }
1480
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001481 /// \brief Build a new OpenMP 'proc_bind' clause.
1482 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001483 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001484 /// Subclasses may override this routine to provide different behavior.
1485 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1486 SourceLocation KindKwLoc,
1487 SourceLocation StartLoc,
1488 SourceLocation LParenLoc,
1489 SourceLocation EndLoc) {
1490 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1491 StartLoc, LParenLoc, EndLoc);
1492 }
1493
Alexey Bataev56dafe82014-06-20 07:16:17 +00001494 /// \brief Build a new OpenMP 'schedule' clause.
1495 ///
1496 /// By default, performs semantic analysis to build the new OpenMP clause.
1497 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001498 OMPClause *RebuildOMPScheduleClause(
1499 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1500 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1501 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1502 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001503 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001504 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1505 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001506 }
1507
Alexey Bataev10e775f2015-07-30 11:36:16 +00001508 /// \brief Build a new OpenMP 'ordered' clause.
1509 ///
1510 /// By default, performs semantic analysis to build the new OpenMP clause.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1513 SourceLocation EndLoc,
1514 SourceLocation LParenLoc, Expr *Num) {
1515 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1516 }
1517
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001518 /// \brief Build a new OpenMP 'private' clause.
1519 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001520 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1523 SourceLocation StartLoc,
1524 SourceLocation LParenLoc,
1525 SourceLocation EndLoc) {
1526 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1527 EndLoc);
1528 }
1529
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001530 /// \brief Build a new OpenMP 'firstprivate' clause.
1531 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001532 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1535 SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Alexander Musman1bb328c2014-06-04 13:06:39 +00001542 /// \brief Build a new OpenMP 'lastprivate' clause.
1543 ///
1544 /// By default, performs semantic analysis to build the new OpenMP clause.
1545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1551 EndLoc);
1552 }
1553
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001554 /// \brief Build a new OpenMP 'shared' clause.
1555 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001556 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001557 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001558 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1559 SourceLocation StartLoc,
1560 SourceLocation LParenLoc,
1561 SourceLocation EndLoc) {
1562 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1563 EndLoc);
1564 }
1565
Alexey Bataevc5e02582014-06-16 07:08:35 +00001566 /// \brief Build a new OpenMP 'reduction' clause.
1567 ///
1568 /// By default, performs semantic analysis to build the new statement.
1569 /// Subclasses may override this routine to provide different behavior.
1570 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1571 SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
1573 SourceLocation ColonLoc,
1574 SourceLocation EndLoc,
1575 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001576 const DeclarationNameInfo &ReductionId,
1577 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001578 return getSema().ActOnOpenMPReductionClause(
1579 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001580 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001581 }
1582
Alexander Musman8dba6642014-04-22 13:09:42 +00001583 /// \brief Build a new OpenMP 'linear' clause.
1584 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001585 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001586 /// Subclasses may override this routine to provide different behavior.
1587 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1588 SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001590 OpenMPLinearClauseKind Modifier,
1591 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001592 SourceLocation ColonLoc,
1593 SourceLocation EndLoc) {
1594 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001595 Modifier, ModifierLoc, ColonLoc,
1596 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001597 }
1598
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001599 /// \brief Build a new OpenMP 'aligned' clause.
1600 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001601 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001602 /// Subclasses may override this routine to provide different behavior.
1603 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1604 SourceLocation StartLoc,
1605 SourceLocation LParenLoc,
1606 SourceLocation ColonLoc,
1607 SourceLocation EndLoc) {
1608 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1609 LParenLoc, ColonLoc, EndLoc);
1610 }
1611
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001612 /// \brief Build a new OpenMP 'copyin' clause.
1613 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001614 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001615 /// Subclasses may override this routine to provide different behavior.
1616 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation EndLoc) {
1620 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1621 EndLoc);
1622 }
1623
Alexey Bataevbae9a792014-06-27 10:37:06 +00001624 /// \brief Build a new OpenMP 'copyprivate' clause.
1625 ///
1626 /// By default, performs semantic analysis to build the new OpenMP clause.
1627 /// Subclasses may override this routine to provide different behavior.
1628 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1629 SourceLocation StartLoc,
1630 SourceLocation LParenLoc,
1631 SourceLocation EndLoc) {
1632 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1633 EndLoc);
1634 }
1635
Alexey Bataev6125da92014-07-21 11:26:11 +00001636 /// \brief Build a new OpenMP 'flush' pseudo clause.
1637 ///
1638 /// By default, performs semantic analysis to build the new OpenMP clause.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1641 SourceLocation StartLoc,
1642 SourceLocation LParenLoc,
1643 SourceLocation EndLoc) {
1644 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1645 EndLoc);
1646 }
1647
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001648 /// \brief Build a new OpenMP 'depend' pseudo clause.
1649 ///
1650 /// By default, performs semantic analysis to build the new OpenMP clause.
1651 /// Subclasses may override this routine to provide different behavior.
1652 OMPClause *
1653 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1654 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1655 SourceLocation StartLoc, SourceLocation LParenLoc,
1656 SourceLocation EndLoc) {
1657 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1658 StartLoc, LParenLoc, EndLoc);
1659 }
1660
Michael Wonge710d542015-08-07 16:16:36 +00001661 /// \brief Build a new OpenMP 'device' clause.
1662 ///
1663 /// By default, performs semantic analysis to build the new statement.
1664 /// Subclasses may override this routine to provide different behavior.
1665 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1666 SourceLocation LParenLoc,
1667 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001668 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001669 EndLoc);
1670 }
1671
Kelvin Li0bff7af2015-11-23 05:32:03 +00001672 /// \brief Build a new OpenMP 'map' clause.
1673 ///
1674 /// By default, performs semantic analysis to build the new OpenMP clause.
1675 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001676 OMPClause *
1677 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1678 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1679 SourceLocation MapLoc, SourceLocation ColonLoc,
1680 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1681 SourceLocation LParenLoc, SourceLocation EndLoc) {
1682 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1683 IsMapTypeImplicit, MapLoc, ColonLoc,
1684 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001685 }
1686
Kelvin Li099bb8c2015-11-24 20:50:12 +00001687 /// \brief Build a new OpenMP 'num_teams' clause.
1688 ///
1689 /// By default, performs semantic analysis to build the new statement.
1690 /// Subclasses may override this routine to provide different behavior.
1691 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1692 SourceLocation LParenLoc,
1693 SourceLocation EndLoc) {
1694 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1695 EndLoc);
1696 }
1697
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001698 /// \brief Build a new OpenMP 'thread_limit' clause.
1699 ///
1700 /// By default, performs semantic analysis to build the new statement.
1701 /// Subclasses may override this routine to provide different behavior.
1702 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1703 SourceLocation StartLoc,
1704 SourceLocation LParenLoc,
1705 SourceLocation EndLoc) {
1706 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1707 LParenLoc, EndLoc);
1708 }
1709
Alexey Bataeva0569352015-12-01 10:17:31 +00001710 /// \brief Build a new OpenMP 'priority' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new statement.
1713 /// Subclasses may override this routine to provide different behavior.
1714 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1715 SourceLocation LParenLoc,
1716 SourceLocation EndLoc) {
1717 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1718 EndLoc);
1719 }
1720
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001721 /// \brief Build a new OpenMP 'grainsize' clause.
1722 ///
1723 /// By default, performs semantic analysis to build the new statement.
1724 /// Subclasses may override this routine to provide different behavior.
1725 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1726 SourceLocation LParenLoc,
1727 SourceLocation EndLoc) {
1728 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1729 EndLoc);
1730 }
1731
Alexey Bataev382967a2015-12-08 12:06:20 +00001732 /// \brief Build a new OpenMP 'num_tasks' clause.
1733 ///
1734 /// By default, performs semantic analysis to build the new statement.
1735 /// Subclasses may override this routine to provide different behavior.
1736 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1737 SourceLocation LParenLoc,
1738 SourceLocation EndLoc) {
1739 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1740 EndLoc);
1741 }
1742
Alexey Bataev28c75412015-12-15 08:19:24 +00001743 /// \brief Build a new OpenMP 'hint' clause.
1744 ///
1745 /// By default, performs semantic analysis to build the new statement.
1746 /// Subclasses may override this routine to provide different behavior.
1747 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1748 SourceLocation LParenLoc,
1749 SourceLocation EndLoc) {
1750 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1751 }
1752
Carlo Bertollib4adf552016-01-15 18:50:31 +00001753 /// \brief Build a new OpenMP 'dist_schedule' clause.
1754 ///
1755 /// By default, performs semantic analysis to build the new OpenMP clause.
1756 /// Subclasses may override this routine to provide different behavior.
1757 OMPClause *
1758 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1759 Expr *ChunkSize, SourceLocation StartLoc,
1760 SourceLocation LParenLoc, SourceLocation KindLoc,
1761 SourceLocation CommaLoc, SourceLocation EndLoc) {
1762 return getSema().ActOnOpenMPDistScheduleClause(
1763 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1764 }
1765
Samuel Antao661c0902016-05-26 17:39:58 +00001766 /// \brief Build a new OpenMP 'to' clause.
1767 ///
1768 /// By default, performs semantic analysis to build the new statement.
1769 /// Subclasses may override this routine to provide different behavior.
1770 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1771 SourceLocation StartLoc,
1772 SourceLocation LParenLoc,
1773 SourceLocation EndLoc) {
1774 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1775 }
1776
Samuel Antaoec172c62016-05-26 17:49:04 +00001777 /// \brief Build a new OpenMP 'from' clause.
1778 ///
1779 /// By default, performs semantic analysis to build the new statement.
1780 /// Subclasses may override this routine to provide different behavior.
1781 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1782 SourceLocation StartLoc,
1783 SourceLocation LParenLoc,
1784 SourceLocation EndLoc) {
1785 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1786 EndLoc);
1787 }
1788
Carlo Bertolli2404b172016-07-13 15:37:16 +00001789 /// Build a new OpenMP 'use_device_ptr' clause.
1790 ///
1791 /// By default, performs semantic analysis to build the new OpenMP clause.
1792 /// Subclasses may override this routine to provide different behavior.
1793 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1794 SourceLocation StartLoc,
1795 SourceLocation LParenLoc,
1796 SourceLocation EndLoc) {
1797 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1798 EndLoc);
1799 }
1800
Carlo Bertolli70594e92016-07-13 17:16:49 +00001801 /// Build a new OpenMP 'is_device_ptr' clause.
1802 ///
1803 /// By default, performs semantic analysis to build the new OpenMP clause.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1806 SourceLocation StartLoc,
1807 SourceLocation LParenLoc,
1808 SourceLocation EndLoc) {
1809 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1810 EndLoc);
1811 }
1812
James Dennett2a4d13c2012-06-15 07:13:21 +00001813 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001814 ///
1815 /// By default, performs semantic analysis to build the new statement.
1816 /// Subclasses may override this routine to provide different behavior.
1817 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1818 Expr *object) {
1819 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1820 }
1821
James Dennett2a4d13c2012-06-15 07:13:21 +00001822 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001823 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001826 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001827 Expr *Object, Stmt *Body) {
1828 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001829 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001830
James Dennett2a4d13c2012-06-15 07:13:21 +00001831 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001832 ///
1833 /// By default, performs semantic analysis to build the new statement.
1834 /// Subclasses may override this routine to provide different behavior.
1835 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1836 Stmt *Body) {
1837 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1838 }
John McCall53848232011-07-27 01:07:15 +00001839
Douglas Gregorf68a5082010-04-22 23:10:45 +00001840 /// \brief Build a new Objective-C fast enumeration statement.
1841 ///
1842 /// By default, performs semantic analysis to build the new statement.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001845 Stmt *Element,
1846 Expr *Collection,
1847 SourceLocation RParenLoc,
1848 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001849 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001850 Element,
John McCallb268a282010-08-23 23:25:46 +00001851 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001852 RParenLoc);
1853 if (ForEachStmt.isInvalid())
1854 return StmtError();
1855
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001856 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001857 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001858
Douglas Gregorebe10102009-08-20 07:17:43 +00001859 /// \brief Build a new C++ exception declaration.
1860 ///
1861 /// By default, performs semantic analysis to build the new decaration.
1862 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001863 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001864 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001865 SourceLocation StartLoc,
1866 SourceLocation IdLoc,
1867 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001868 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001869 StartLoc, IdLoc, Id);
1870 if (Var)
1871 getSema().CurContext->addDecl(Var);
1872 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001873 }
1874
1875 /// \brief Build a new C++ catch statement.
1876 ///
1877 /// By default, performs semantic analysis to build the new statement.
1878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001880 VarDecl *ExceptionDecl,
1881 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001882 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1883 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregorebe10102009-08-20 07:17:43 +00001886 /// \brief Build a new C++ try statement.
1887 ///
1888 /// By default, performs semantic analysis to build the new statement.
1889 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001890 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1891 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001892 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001893 }
Mike Stump11289f42009-09-09 15:08:12 +00001894
Richard Smith02e85f32011-04-14 22:09:26 +00001895 /// \brief Build a new C++0x range-based for statement.
1896 ///
1897 /// By default, performs semantic analysis to build the new statement.
1898 /// Subclasses may override this routine to provide different behavior.
1899 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001900 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001901 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001902 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001903 Expr *Cond, Expr *Inc,
1904 Stmt *LoopVar,
1905 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001906 // If we've just learned that the range is actually an Objective-C
1907 // collection, treat this as an Objective-C fast enumeration loop.
1908 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1909 if (RangeStmt->isSingleDecl()) {
1910 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001911 if (RangeVar->isInvalidDecl())
1912 return StmtError();
1913
Douglas Gregorf7106af2013-04-08 18:40:13 +00001914 Expr *RangeExpr = RangeVar->getInit();
1915 if (!RangeExpr->isTypeDependent() &&
1916 RangeExpr->getType()->isObjCObjectPointerType())
1917 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1918 RParenLoc);
1919 }
1920 }
1921 }
1922
Richard Smithcfd53b42015-10-22 06:13:50 +00001923 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001924 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001925 Cond, Inc, LoopVar, RParenLoc,
1926 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001927 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001928
1929 /// \brief Build a new C++0x range-based for statement.
1930 ///
1931 /// By default, performs semantic analysis to build the new statement.
1932 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001933 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001934 bool IsIfExists,
1935 NestedNameSpecifierLoc QualifierLoc,
1936 DeclarationNameInfo NameInfo,
1937 Stmt *Nested) {
1938 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1939 QualifierLoc, NameInfo, Nested);
1940 }
1941
Richard Smith02e85f32011-04-14 22:09:26 +00001942 /// \brief Attach body to a C++0x range-based for statement.
1943 ///
1944 /// By default, performs semantic analysis to finish the new statement.
1945 /// Subclasses may override this routine to provide different behavior.
1946 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1947 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001949
David Majnemerfad8f482013-10-15 09:33:02 +00001950 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001951 Stmt *TryBlock, Stmt *Handler) {
1952 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001953 }
1954
David Majnemerfad8f482013-10-15 09:33:02 +00001955 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001956 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001957 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001958 }
1959
David Majnemerfad8f482013-10-15 09:33:02 +00001960 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001961 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001962 }
1963
Alexey Bataevec474782014-10-09 08:45:04 +00001964 /// \brief Build a new predefined expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
1968 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1969 PredefinedExpr::IdentType IT) {
1970 return getSema().BuildPredefinedExpr(Loc, IT);
1971 }
1972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 /// \brief Build a new expression that references a declaration.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001977 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001978 LookupResult &R,
1979 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001980 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1981 }
1982
1983
1984 /// \brief Build a new expression that references a declaration.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001988 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001989 ValueDecl *VD,
1990 const DeclarationNameInfo &NameInfo,
1991 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001992 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001993 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001994
1995 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001996
1997 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002001 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002004 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002006 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 }
2008
Douglas Gregorad8a3362009-09-04 17:36:40 +00002009 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002014 SourceLocation OperatorLoc,
2015 bool isArrow,
2016 CXXScopeSpec &SS,
2017 TypeSourceInfo *ScopeType,
2018 SourceLocation CCLoc,
2019 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002020 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002021
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002023 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002026 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002027 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002028 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002029 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 }
Mike Stump11289f42009-09-09 15:08:12 +00002031
Douglas Gregor882211c2010-04-28 22:16:22 +00002032 /// \brief Build a new builtin offsetof expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002036 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002037 TypeSourceInfo *Type,
2038 ArrayRef<Sema::OffsetOfComponent> Components,
2039 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002040 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002041 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002042 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002043
2044 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002045 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002046 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002049 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2050 SourceLocation OpLoc,
2051 UnaryExprOrTypeTrait ExprKind,
2052 SourceRange R) {
2053 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 }
2055
Peter Collingbournee190dee2011-03-11 19:24:49 +00002056 /// \brief Build a new sizeof, alignof or vec step expression with an
2057 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002058 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002061 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2062 UnaryExprOrTypeTrait ExprKind,
2063 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002065 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002067 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002068
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002069 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 }
Mike Stump11289f42009-09-09 15:08:12 +00002071
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002073 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002076 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002078 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002080 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002081 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002082 RBracketLoc);
2083 }
2084
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002085 /// \brief Build a new array section expression.
2086 ///
2087 /// By default, performs semantic analysis to build the new expression.
2088 /// Subclasses may override this routine to provide different behavior.
2089 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2090 Expr *LowerBound,
2091 SourceLocation ColonLoc, Expr *Length,
2092 SourceLocation RBracketLoc) {
2093 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2094 ColonLoc, Length, RBracketLoc);
2095 }
2096
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// \brief Build a new call 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 RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002102 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002103 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002104 Expr *ExecConfig = nullptr) {
2105 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002106 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 }
2108
2109 /// \brief Build a new member access expression.
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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002114 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002115 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002116 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002117 const DeclarationNameInfo &MemberNameInfo,
2118 ValueDecl *Member,
2119 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002120 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002121 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002122 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2123 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002124 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002125 // We have a reference to an unnamed field. This is always the
2126 // base of an anonymous struct/union member access, i.e. the
2127 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002128 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002129 assert(Member->getType()->isRecordType() &&
2130 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002131
Richard Smithcab9a7d2011-10-26 19:06:56 +00002132 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002133 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002134 QualifierLoc.getNestedNameSpecifier(),
2135 FoundDecl, Member);
2136 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002137 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002138 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002139 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002140 MemberExpr *ME = new (getSema().Context)
2141 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2142 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002143 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002146 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002147 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002148
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002149 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002150 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002151
John McCall16df1e52010-03-30 21:47:33 +00002152 // FIXME: this involves duplicating earlier analysis in a lot of
2153 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002154 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002155 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002156 R.resolveKind();
2157
John McCallb268a282010-08-23 23:25:46 +00002158 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002159 SS, TemplateKWLoc,
2160 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002161 R, ExplicitTemplateArgs,
2162 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 }
Mike Stump11289f42009-09-09 15:08:12 +00002164
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002166 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002169 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002170 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002171 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002172 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002176 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002180 SourceLocation QuestionLoc,
2181 Expr *LHS,
2182 SourceLocation ColonLoc,
2183 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002184 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2185 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
2187
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002189 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002193 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002195 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002196 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002197 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002201 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002205 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002207 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002208 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002209 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 }
Mike Stump11289f42009-09-09 15:08:12 +00002211
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002213 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002216 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 SourceLocation OpLoc,
2218 SourceLocation AccessorLoc,
2219 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002220
John McCall10eae182009-11-30 22:42:35 +00002221 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002222 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002223 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002224 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002225 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002226 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002227 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002228 /* TemplateArgs */ nullptr,
2229 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 }
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002236 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002237 MultiExprArg Inits,
2238 SourceLocation RBraceLoc,
2239 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002241 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002242 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002243 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002244
Douglas Gregord3d93062009-11-09 17:16:50 +00002245 // Patch in the result type we were given, which may have been computed
2246 // when the initial InitListExpr was built.
2247 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2248 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002249 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
Mike Stump11289f42009-09-09 15:08:12 +00002251
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002253 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002256 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 MultiExprArg ArrayExprs,
2258 SourceLocation EqualOrColonLoc,
2259 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002260 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002261 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002263 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002266
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002267 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
Mike Stump11289f42009-09-09 15:08:12 +00002269
Douglas Gregora16548e2009-08-11 05:31:07 +00002270 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002271 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002272 /// By default, builds the implicit value initialization without performing
2273 /// any semantic analysis. Subclasses may override this routine to provide
2274 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002276 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 }
Mike Stump11289f42009-09-09 15:08:12 +00002278
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 /// By default, performs semantic analysis to build the new expression.
2282 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002283 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002284 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002285 SourceLocation RParenLoc) {
2286 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002287 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002288 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 }
2290
2291 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002292 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002296 MultiExprArg SubExprs,
2297 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002298 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 }
Mike Stump11289f42009-09-09 15:08:12 +00002300
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002302 ///
2303 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 /// rather than attempting to map the label statement itself.
2305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002306 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002307 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002308 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 }
Mike Stump11289f42009-09-09 15:08:12 +00002310
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// By default, performs semantic analysis to build the new expression.
2314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002315 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002316 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002318 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 }
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 /// \brief Build a new __builtin_choose_expr expression.
2322 ///
2323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002325 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002326 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 SourceLocation RParenLoc) {
2328 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002329 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 RParenLoc);
2331 }
Mike Stump11289f42009-09-09 15:08:12 +00002332
Peter Collingbourne91147592011-04-15 00:35:48 +00002333 /// \brief Build a new generic selection expression.
2334 ///
2335 /// By default, performs semantic analysis to build the new expression.
2336 /// Subclasses may override this routine to provide different behavior.
2337 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2338 SourceLocation DefaultLoc,
2339 SourceLocation RParenLoc,
2340 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002341 ArrayRef<TypeSourceInfo *> Types,
2342 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002343 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002344 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002345 }
2346
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 /// \brief Build a new overloaded operator call expression.
2348 ///
2349 /// By default, performs semantic analysis to build the new expression.
2350 /// The semantic analysis provides the behavior of template instantiation,
2351 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002352 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 /// argument-dependent lookup, etc. Subclasses may override this routine to
2354 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002355 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002357 Expr *Callee,
2358 Expr *First,
2359 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002360
2361 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 /// reinterpret_cast.
2363 ///
2364 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002365 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002367 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 Stmt::StmtClass Class,
2369 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002370 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 SourceLocation RAngleLoc,
2372 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002373 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002374 SourceLocation RParenLoc) {
2375 switch (Class) {
2376 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002377 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002378 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002379 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002380
2381 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002382 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002383 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002384 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002385
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002387 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002388 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002389 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002393 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002394 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002395 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002396
Douglas Gregora16548e2009-08-11 05:31:07 +00002397 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002398 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 }
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++ static_cast 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 RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002408 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 SourceLocation RAngleLoc,
2410 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002411 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002413 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002414 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002415 SourceRange(LAngleLoc, RAngleLoc),
2416 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
2418
2419 /// \brief Build a new C++ dynamic_cast expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002425 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 SourceLocation RAngleLoc,
2427 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002428 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002430 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002431 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002432 SourceRange(LAngleLoc, RAngleLoc),
2433 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 }
2435
2436 /// \brief Build a new C++ reinterpret_cast expression.
2437 ///
2438 /// By default, performs semantic analysis to build the new expression.
2439 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002440 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002442 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 SourceLocation RAngleLoc,
2444 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002445 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002447 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002448 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002449 SourceRange(LAngleLoc, RAngleLoc),
2450 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 }
2452
2453 /// \brief Build a new C++ const_cast expression.
2454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002458 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002459 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 SourceLocation RAngleLoc,
2461 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002462 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002464 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002465 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002466 SourceRange(LAngleLoc, RAngleLoc),
2467 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 }
Mike Stump11289f42009-09-09 15:08:12 +00002469
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 /// \brief Build a new C++ functional-style cast expression.
2471 ///
2472 /// By default, performs semantic analysis to build the new expression.
2473 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002474 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2475 SourceLocation LParenLoc,
2476 Expr *Sub,
2477 SourceLocation RParenLoc) {
2478 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002479 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 RParenLoc);
2481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 /// \brief Build a new C++ typeid(type) expression.
2484 ///
2485 /// By default, performs semantic analysis to build the new expression.
2486 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002488 SourceLocation TypeidLoc,
2489 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002491 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002492 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002493 }
Mike Stump11289f42009-09-09 15:08:12 +00002494
Francois Pichet9f4f2072010-09-08 12:20:18 +00002495
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 /// \brief Build a new C++ typeid(expr) expression.
2497 ///
2498 /// By default, performs semantic analysis to build the new expression.
2499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002500 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002501 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002502 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002504 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002505 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002506 }
2507
Francois Pichet9f4f2072010-09-08 12:20:18 +00002508 /// \brief Build a new C++ __uuidof(type) expression.
2509 ///
2510 /// By default, performs semantic analysis to build the new expression.
2511 /// Subclasses may override this routine to provide different behavior.
2512 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2513 SourceLocation TypeidLoc,
2514 TypeSourceInfo *Operand,
2515 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002516 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002517 RParenLoc);
2518 }
2519
2520 /// \brief Build a new C++ __uuidof(expr) expression.
2521 ///
2522 /// By default, performs semantic analysis to build the new expression.
2523 /// Subclasses may override this routine to provide different behavior.
2524 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2525 SourceLocation TypeidLoc,
2526 Expr *Operand,
2527 SourceLocation RParenLoc) {
2528 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2529 RParenLoc);
2530 }
2531
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 /// \brief Build a new C++ "this" expression.
2533 ///
2534 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002535 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002537 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002538 QualType ThisType,
2539 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002540 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002541 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 }
2543
2544 /// \brief Build a new C++ throw expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002548 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2549 bool IsThrownVariableInScope) {
2550 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 }
2552
2553 /// \brief Build a new C++ default-argument expression.
2554 ///
2555 /// By default, builds a new default-argument expression, which does not
2556 /// require any semantic analysis. Subclasses may override this routine to
2557 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002558 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002559 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002560 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 }
2562
Richard Smith852c9db2013-04-20 22:23:05 +00002563 /// \brief Build a new C++11 default-initialization expression.
2564 ///
2565 /// By default, builds a new default field initialization expression, which
2566 /// does not require any semantic analysis. Subclasses may override this
2567 /// routine to provide different behavior.
2568 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2569 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002570 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002571 }
2572
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 /// \brief Build a new C++ zero-initialization expression.
2574 ///
2575 /// By default, performs semantic analysis to build the new expression.
2576 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002577 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2578 SourceLocation LParenLoc,
2579 SourceLocation RParenLoc) {
2580 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002581 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 /// \brief Build a new C++ "new" expression.
2585 ///
2586 /// By default, performs semantic analysis to build the new expression.
2587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002588 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002589 bool UseGlobal,
2590 SourceLocation PlacementLParen,
2591 MultiExprArg PlacementArgs,
2592 SourceLocation PlacementRParen,
2593 SourceRange TypeIdParens,
2594 QualType AllocatedType,
2595 TypeSourceInfo *AllocatedTypeInfo,
2596 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002597 SourceRange DirectInitRange,
2598 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002599 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002601 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002603 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002604 AllocatedType,
2605 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002606 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002607 DirectInitRange,
2608 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002609 }
Mike Stump11289f42009-09-09 15:08:12 +00002610
Douglas Gregora16548e2009-08-11 05:31:07 +00002611 /// \brief Build a new C++ "delete" expression.
2612 ///
2613 /// By default, performs semantic analysis to build the new expression.
2614 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002615 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002616 bool IsGlobalDelete,
2617 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002618 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002619 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002620 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002621 }
Mike Stump11289f42009-09-09 15:08:12 +00002622
Douglas Gregor29c42f22012-02-24 07:38:34 +00002623 /// \brief Build a new type trait expression.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
2627 ExprResult RebuildTypeTrait(TypeTrait Trait,
2628 SourceLocation StartLoc,
2629 ArrayRef<TypeSourceInfo *> Args,
2630 SourceLocation RParenLoc) {
2631 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2632 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002633
John Wiegley6242b6a2011-04-28 00:16:57 +00002634 /// \brief Build a new array type trait expression.
2635 ///
2636 /// By default, performs semantic analysis to build the new expression.
2637 /// Subclasses may override this routine to provide different behavior.
2638 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2639 SourceLocation StartLoc,
2640 TypeSourceInfo *TSInfo,
2641 Expr *DimExpr,
2642 SourceLocation RParenLoc) {
2643 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2644 }
2645
John Wiegleyf9f65842011-04-25 06:54:41 +00002646 /// \brief Build a new expression trait expression.
2647 ///
2648 /// By default, performs semantic analysis to build the new expression.
2649 /// Subclasses may override this routine to provide different behavior.
2650 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2651 SourceLocation StartLoc,
2652 Expr *Queried,
2653 SourceLocation RParenLoc) {
2654 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2655 }
2656
Mike Stump11289f42009-09-09 15:08:12 +00002657 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002658 /// expression.
2659 ///
2660 /// By default, performs semantic analysis to build the new expression.
2661 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002662 ExprResult RebuildDependentScopeDeclRefExpr(
2663 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002664 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002665 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002666 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002667 bool IsAddressOfOperand,
2668 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002670 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002671
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002672 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002673 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2674 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002675
Reid Kleckner32506ed2014-06-12 23:03:48 +00002676 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002677 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 }
2679
2680 /// \brief Build a new template-id expression.
2681 ///
2682 /// By default, performs semantic analysis to build the new expression.
2683 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002684 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002685 SourceLocation TemplateKWLoc,
2686 LookupResult &R,
2687 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002688 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002689 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2690 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 }
2692
2693 /// \brief Build a new object-construction expression.
2694 ///
2695 /// By default, performs semantic analysis to build the new expression.
2696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002697 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002698 SourceLocation Loc,
2699 CXXConstructorDecl *Constructor,
2700 bool IsElidable,
2701 MultiExprArg Args,
2702 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002703 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002704 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002705 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002706 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002707 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002708 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002709 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002710 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002711 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002712
Richard Smithc83bf822016-06-10 00:58:19 +00002713 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002714 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002715 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002716 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002717 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002718 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002719 RequiresZeroInit, ConstructKind,
2720 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 }
2722
Richard Smith5179eb72016-06-28 19:03:57 +00002723 /// \brief Build a new implicit construction via inherited constructor
2724 /// expression.
2725 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2726 CXXConstructorDecl *Constructor,
2727 bool ConstructsVBase,
2728 bool InheritedFromVBase) {
2729 return new (getSema().Context) CXXInheritedCtorInitExpr(
2730 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2731 }
2732
Douglas Gregora16548e2009-08-11 05:31:07 +00002733 /// \brief Build a new object-construction expression.
2734 ///
2735 /// By default, performs semantic analysis to build the new expression.
2736 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002737 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2738 SourceLocation LParenLoc,
2739 MultiExprArg Args,
2740 SourceLocation RParenLoc) {
2741 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002743 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002744 RParenLoc);
2745 }
2746
2747 /// \brief Build a new object-construction expression.
2748 ///
2749 /// By default, performs semantic analysis to build the new expression.
2750 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002751 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2752 SourceLocation LParenLoc,
2753 MultiExprArg Args,
2754 SourceLocation RParenLoc) {
2755 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002757 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002758 RParenLoc);
2759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregora16548e2009-08-11 05:31:07 +00002761 /// \brief Build a new member reference expression.
2762 ///
2763 /// By default, performs semantic analysis to build the new expression.
2764 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002765 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002766 QualType BaseType,
2767 bool IsArrow,
2768 SourceLocation OperatorLoc,
2769 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002770 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002771 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002772 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002773 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002774 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002775 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002776
John McCallb268a282010-08-23 23:25:46 +00002777 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002778 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002779 SS, TemplateKWLoc,
2780 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002781 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002782 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002783 }
2784
John McCall10eae182009-11-30 22:42:35 +00002785 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002786 ///
2787 /// By default, performs semantic analysis to build the new expression.
2788 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002789 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2790 SourceLocation OperatorLoc,
2791 bool IsArrow,
2792 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002793 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002794 NamedDecl *FirstQualifierInScope,
2795 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002796 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002797 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002798 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002799
John McCallb268a282010-08-23 23:25:46 +00002800 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002801 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002802 SS, TemplateKWLoc,
2803 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002804 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002805 }
Mike Stump11289f42009-09-09 15:08:12 +00002806
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002807 /// \brief Build a new noexcept expression.
2808 ///
2809 /// By default, performs semantic analysis to build the new expression.
2810 /// Subclasses may override this routine to provide different behavior.
2811 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2812 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2813 }
2814
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002815 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002816 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2817 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002818 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002819 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002820 Optional<unsigned> Length,
2821 ArrayRef<TemplateArgument> PartialArgs) {
2822 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2823 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002824 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002825
Patrick Beard0caa3942012-04-19 00:25:12 +00002826 /// \brief Build a new Objective-C boxed expression.
2827 ///
2828 /// By default, performs semantic analysis to build the new expression.
2829 /// Subclasses may override this routine to provide different behavior.
2830 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2831 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2832 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002833
Ted Kremeneke65b0862012-03-06 20:05:56 +00002834 /// \brief Build a new Objective-C array literal.
2835 ///
2836 /// By default, performs semantic analysis to build the new expression.
2837 /// Subclasses may override this routine to provide different behavior.
2838 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2839 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002840 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002841 MultiExprArg(Elements, NumElements));
2842 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002843
2844 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002845 Expr *Base, Expr *Key,
2846 ObjCMethodDecl *getterMethod,
2847 ObjCMethodDecl *setterMethod) {
2848 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2849 getterMethod, setterMethod);
2850 }
2851
2852 /// \brief Build a new Objective-C dictionary literal.
2853 ///
2854 /// By default, performs semantic analysis to build the new expression.
2855 /// Subclasses may override this routine to provide different behavior.
2856 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002857 MutableArrayRef<ObjCDictionaryElement> Elements) {
2858 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002860
James Dennett2a4d13c2012-06-15 07:13:21 +00002861 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002862 ///
2863 /// By default, performs semantic analysis to build the new expression.
2864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002865 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002866 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002867 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002868 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002869 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002870
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002871 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002872 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002873 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002874 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002875 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002876 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002877 MultiExprArg Args,
2878 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002879 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2880 ReceiverTypeInfo->getType(),
2881 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002882 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002883 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002884 }
2885
2886 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002887 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002888 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002889 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002890 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002891 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002892 MultiExprArg Args,
2893 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002894 return SemaRef.BuildInstanceMessage(Receiver,
2895 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002896 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002897 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002898 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002899 }
2900
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002901 /// \brief Build a new Objective-C instance/class message to 'super'.
2902 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2903 Selector Sel,
2904 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002905 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002906 ObjCMethodDecl *Method,
2907 SourceLocation LBracLoc,
2908 MultiExprArg Args,
2909 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002910 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002911 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002912 SuperLoc,
2913 Sel, Method, LBracLoc, SelectorLocs,
2914 RBracLoc, Args)
2915 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002916 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002917 SuperLoc,
2918 Sel, Method, LBracLoc, SelectorLocs,
2919 RBracLoc, Args);
2920
2921
2922 }
2923
Douglas Gregord51d90d2010-04-26 20:11:03 +00002924 /// \brief Build a new Objective-C ivar reference expression.
2925 ///
2926 /// By default, performs semantic analysis to build the new expression.
2927 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002928 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002929 SourceLocation IvarLoc,
2930 bool IsArrow, bool IsFreeIvar) {
2931 // FIXME: We lose track of the IsFreeIvar bit.
2932 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002933 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2934 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002935 /*FIXME:*/IvarLoc, IsArrow,
2936 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002937 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002938 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002939 /*TemplateArgs=*/nullptr,
2940 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002941 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002942
2943 /// \brief Build a new Objective-C property reference expression.
2944 ///
2945 /// By default, performs semantic analysis to build the new expression.
2946 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002947 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002948 ObjCPropertyDecl *Property,
2949 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002950 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002951 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2952 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2953 /*FIXME:*/PropertyLoc,
2954 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002955 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002956 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002957 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002958 /*TemplateArgs=*/nullptr,
2959 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002961
John McCallb7bd14f2010-12-02 01:19:52 +00002962 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002963 ///
2964 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002965 /// Subclasses may override this routine to provide different behavior.
2966 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2967 ObjCMethodDecl *Getter,
2968 ObjCMethodDecl *Setter,
2969 SourceLocation PropertyLoc) {
2970 // Since these expressions can only be value-dependent, we do not
2971 // need to perform semantic analysis again.
2972 return Owned(
2973 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2974 VK_LValue, OK_ObjCProperty,
2975 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002976 }
2977
Douglas Gregord51d90d2010-04-26 20:11:03 +00002978 /// \brief Build a new Objective-C "isa" expression.
2979 ///
2980 /// By default, performs semantic analysis to build the new expression.
2981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002982 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002983 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002984 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002985 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2986 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002987 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002988 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002989 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002990 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002991 /*TemplateArgs=*/nullptr,
2992 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002994
Douglas Gregora16548e2009-08-11 05:31:07 +00002995 /// \brief Build a new shuffle vector expression.
2996 ///
2997 /// By default, performs semantic analysis to build the new expression.
2998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002999 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003000 MultiExprArg SubExprs,
3001 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003002 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003003 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003004 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3005 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3006 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003007 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003008
Douglas Gregora16548e2009-08-11 05:31:07 +00003009 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003010 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003011 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3012 SemaRef.Context.BuiltinFnTy,
3013 VK_RValue, BuiltinLoc);
3014 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3015 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003016 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003017
3018 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003019 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003020 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003021 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003022
Douglas Gregora16548e2009-08-11 05:31:07 +00003023 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003024 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003025 }
John McCall31f82722010-11-12 08:19:04 +00003026
Hal Finkelc4d7c822013-09-18 03:29:45 +00003027 /// \brief Build a new convert vector expression.
3028 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3029 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3030 SourceLocation RParenLoc) {
3031 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3032 BuiltinLoc, RParenLoc);
3033 }
3034
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003035 /// \brief Build a new template argument pack expansion.
3036 ///
3037 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003038 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003039 /// different behavior.
3040 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003041 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003042 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003043 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003044 case TemplateArgument::Expression: {
3045 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003046 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3047 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003048 if (Result.isInvalid())
3049 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003050
Douglas Gregor98318c22011-01-03 21:37:45 +00003051 return TemplateArgumentLoc(Result.get(), Result.get());
3052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003053
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003054 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003055 return TemplateArgumentLoc(TemplateArgument(
3056 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003057 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003058 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003059 Pattern.getTemplateNameLoc(),
3060 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003061
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003062 case TemplateArgument::Null:
3063 case TemplateArgument::Integral:
3064 case TemplateArgument::Declaration:
3065 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003066 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003067 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003068 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003069
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003071 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003072 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003073 EllipsisLoc,
3074 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003075 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3076 Expansion);
3077 break;
3078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003079
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003080 return TemplateArgumentLoc();
3081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003082
Douglas Gregor968f23a2011-01-03 19:31:53 +00003083 /// \brief Build a new expression pack expansion.
3084 ///
3085 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003086 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003087 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003088 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003089 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003090 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003091 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003092
Richard Smith0f0af192014-11-08 05:07:16 +00003093 /// \brief Build a new C++1z fold-expression.
3094 ///
3095 /// By default, performs semantic analysis in order to build a new fold
3096 /// expression.
3097 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3098 BinaryOperatorKind Operator,
3099 SourceLocation EllipsisLoc, Expr *RHS,
3100 SourceLocation RParenLoc) {
3101 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3102 RHS, RParenLoc);
3103 }
3104
3105 /// \brief Build an empty C++1z fold-expression with the given operator.
3106 ///
3107 /// By default, produces the fallback value for the fold-expression, or
3108 /// produce an error if there is no fallback value.
3109 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3110 BinaryOperatorKind Operator) {
3111 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3112 }
3113
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003114 /// \brief Build a new atomic operation expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3118 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3119 MultiExprArg SubExprs,
3120 QualType RetTy,
3121 AtomicExpr::AtomicOp Op,
3122 SourceLocation RParenLoc) {
3123 // Just create the expression; there is not any interesting semantic
3124 // analysis here because we can't actually build an AtomicExpr until
3125 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003126 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003127 RParenLoc);
3128 }
3129
John McCall31f82722010-11-12 08:19:04 +00003130private:
Douglas Gregor14454802011-02-25 02:25:35 +00003131 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3132 QualType ObjectType,
3133 NamedDecl *FirstQualifierInScope,
3134 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003135
3136 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3137 QualType ObjectType,
3138 NamedDecl *FirstQualifierInScope,
3139 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003140
3141 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3142 NamedDecl *FirstQualifierInScope,
3143 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144};
Douglas Gregora16548e2009-08-11 05:31:07 +00003145
Douglas Gregorebe10102009-08-20 07:17:43 +00003146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003147StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003148 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003149 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003150
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 switch (S->getStmtClass()) {
3152 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003153
Douglas Gregorebe10102009-08-20 07:17:43 +00003154 // Transform individual statement nodes
3155#define STMT(Node, Parent) \
3156 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003157#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003158#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003159#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregorebe10102009-08-20 07:17:43 +00003161 // Transform expressions by calling TransformExpr.
3162#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003163#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003164#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003165#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003166 {
John McCalldadc5752010-08-24 06:29:42 +00003167 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003168 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003169 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003170
Richard Smith945f8d32013-01-14 22:39:08 +00003171 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003172 }
Mike Stump11289f42009-09-09 15:08:12 +00003173 }
3174
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003175 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003176}
Mike Stump11289f42009-09-09 15:08:12 +00003177
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003178template<typename Derived>
3179OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3180 if (!S)
3181 return S;
3182
3183 switch (S->getClauseKind()) {
3184 default: break;
3185 // Transform individual clause nodes
3186#define OPENMP_CLAUSE(Name, Class) \
3187 case OMPC_ ## Name : \
3188 return getDerived().Transform ## Class(cast<Class>(S));
3189#include "clang/Basic/OpenMPKinds.def"
3190 }
3191
3192 return S;
3193}
3194
Mike Stump11289f42009-09-09 15:08:12 +00003195
Douglas Gregore922c772009-08-04 22:27:00 +00003196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003197ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003198 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003199 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003200
3201 switch (E->getStmtClass()) {
3202 case Stmt::NoStmtClass: break;
3203#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003204#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003205#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003206 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003207#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003208 }
3209
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003210 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003211}
3212
3213template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003214ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003215 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003216 // Initializers are instantiated like expressions, except that various outer
3217 // layers are stripped.
3218 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003219 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003220
3221 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3222 Init = ExprTemp->getSubExpr();
3223
Richard Smith410306b2016-12-12 02:53:20 +00003224 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3225 Init = AIL->getCommonExpr();
3226
Richard Smithe6ca4752013-05-30 22:40:16 +00003227 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3228 Init = MTE->GetTemporaryExpr();
3229
Richard Smithd59b8322012-12-19 01:39:02 +00003230 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3231 Init = Binder->getSubExpr();
3232
3233 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3234 Init = ICE->getSubExprAsWritten();
3235
Richard Smithcc1b96d2013-06-12 22:31:48 +00003236 if (CXXStdInitializerListExpr *ILE =
3237 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003238 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003239
Richard Smithc6abd962014-07-25 01:12:44 +00003240 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003241 // InitListExprs. Other forms of copy-initialization will be a no-op if
3242 // the initializer is already the right type.
3243 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003244 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003245 return getDerived().TransformExpr(Init);
3246
3247 // Revert value-initialization back to empty parens.
3248 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3249 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003250 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003251 Parens.getEnd());
3252 }
3253
3254 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3255 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003256 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003257 SourceLocation());
3258
3259 // Revert initialization by constructor back to a parenthesized or braced list
3260 // of expressions. Any other form of initializer can just be reused directly.
3261 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003262 return getDerived().TransformExpr(Init);
3263
Richard Smithf8adcdc2014-07-17 05:12:35 +00003264 // If the initialization implicitly converted an initializer list to a
3265 // std::initializer_list object, unwrap the std::initializer_list too.
3266 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003267 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003268
Richard Smithd59b8322012-12-19 01:39:02 +00003269 SmallVector<Expr*, 8> NewArgs;
3270 bool ArgChanged = false;
3271 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003272 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003273 return ExprError();
3274
3275 // If this was list initialization, revert to list form.
3276 if (Construct->isListInitialization())
3277 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3278 Construct->getLocEnd(),
3279 Construct->getType());
3280
Richard Smithd59b8322012-12-19 01:39:02 +00003281 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003282 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003283 if (Parens.isInvalid()) {
3284 // This was a variable declaration's initialization for which no initializer
3285 // was specified.
3286 assert(NewArgs.empty() &&
3287 "no parens or braces but have direct init with arguments?");
3288 return ExprEmpty();
3289 }
Richard Smithd59b8322012-12-19 01:39:02 +00003290 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3291 Parens.getEnd());
3292}
3293
3294template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003295bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003296 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003297 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003298 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003299 bool *ArgChanged) {
3300 for (unsigned I = 0; I != NumInputs; ++I) {
3301 // If requested, drop call arguments that need to be dropped.
3302 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3303 if (ArgChanged)
3304 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregora3efea12011-01-03 19:04:46 +00003306 break;
3307 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003308
Douglas Gregor968f23a2011-01-03 19:31:53 +00003309 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3310 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003311
Chris Lattner01cf8db2011-07-20 06:58:45 +00003312 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003313 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3314 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
Douglas Gregor968f23a2011-01-03 19:31:53 +00003316 // Determine whether the set of unexpanded parameter packs can and should
3317 // be expanded.
3318 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003319 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003320 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3321 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003322 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3323 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003324 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003325 Expand, RetainExpansion,
3326 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003327 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003328
Douglas Gregor968f23a2011-01-03 19:31:53 +00003329 if (!Expand) {
3330 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003331 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003332 // expansion.
3333 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3334 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3335 if (OutPattern.isInvalid())
3336 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003337
3338 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003339 Expansion->getEllipsisLoc(),
3340 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003341 if (Out.isInvalid())
3342 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003343
Douglas Gregor968f23a2011-01-03 19:31:53 +00003344 if (ArgChanged)
3345 *ArgChanged = true;
3346 Outputs.push_back(Out.get());
3347 continue;
3348 }
John McCall542e7c62011-07-06 07:30:07 +00003349
3350 // Record right away that the argument was changed. This needs
3351 // to happen even if the array expands to nothing.
3352 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003353
Douglas Gregor968f23a2011-01-03 19:31:53 +00003354 // The transform has determined that we should perform an elementwise
3355 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003356 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3358 ExprResult Out = getDerived().TransformExpr(Pattern);
3359 if (Out.isInvalid())
3360 return true;
3361
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003362 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003363 Out = getDerived().RebuildPackExpansion(
3364 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003365 if (Out.isInvalid())
3366 return true;
3367 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003368
Douglas Gregor968f23a2011-01-03 19:31:53 +00003369 Outputs.push_back(Out.get());
3370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003371
Richard Smith9467be42014-06-06 17:33:35 +00003372 // If we're supposed to retain a pack expansion, do so by temporarily
3373 // forgetting the partially-substituted parameter pack.
3374 if (RetainExpansion) {
3375 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3376
3377 ExprResult Out = getDerived().TransformExpr(Pattern);
3378 if (Out.isInvalid())
3379 return true;
3380
3381 Out = getDerived().RebuildPackExpansion(
3382 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3383 if (Out.isInvalid())
3384 return true;
3385
3386 Outputs.push_back(Out.get());
3387 }
3388
Douglas Gregor968f23a2011-01-03 19:31:53 +00003389 continue;
3390 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Richard Smithd59b8322012-12-19 01:39:02 +00003392 ExprResult Result =
3393 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3394 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003395 if (Result.isInvalid())
3396 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregora3efea12011-01-03 19:04:46 +00003398 if (Result.get() != Inputs[I] && ArgChanged)
3399 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003400
3401 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003402 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003403
Douglas Gregora3efea12011-01-03 19:04:46 +00003404 return false;
3405}
3406
Richard Smith03a4aa32016-06-23 19:02:52 +00003407template <typename Derived>
3408Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3409 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3410 if (Var) {
3411 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3412 getDerived().TransformDefinition(Var->getLocation(), Var));
3413
3414 if (!ConditionVar)
3415 return Sema::ConditionError();
3416
3417 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3418 }
3419
3420 if (Expr) {
3421 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3422
3423 if (CondExpr.isInvalid())
3424 return Sema::ConditionError();
3425
3426 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3427 }
3428
3429 return Sema::ConditionResult();
3430}
3431
Douglas Gregora3efea12011-01-03 19:04:46 +00003432template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003433NestedNameSpecifierLoc
3434TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3435 NestedNameSpecifierLoc NNS,
3436 QualType ObjectType,
3437 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003438 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003439 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003440 Qualifier = Qualifier.getPrefix())
3441 Qualifiers.push_back(Qualifier);
3442
3443 CXXScopeSpec SS;
3444 while (!Qualifiers.empty()) {
3445 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3446 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor14454802011-02-25 02:25:35 +00003448 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003449 case NestedNameSpecifier::Identifier: {
3450 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3451 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3452 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3453 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003454 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003455 }
Douglas Gregor14454802011-02-25 02:25:35 +00003456 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003457
Douglas Gregor14454802011-02-25 02:25:35 +00003458 case NestedNameSpecifier::Namespace: {
3459 NamespaceDecl *NS
3460 = cast_or_null<NamespaceDecl>(
3461 getDerived().TransformDecl(
3462 Q.getLocalBeginLoc(),
3463 QNNS->getAsNamespace()));
3464 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3465 break;
3466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Douglas Gregor14454802011-02-25 02:25:35 +00003468 case NestedNameSpecifier::NamespaceAlias: {
3469 NamespaceAliasDecl *Alias
3470 = cast_or_null<NamespaceAliasDecl>(
3471 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3472 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003473 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003474 Q.getLocalEndLoc());
3475 break;
3476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor14454802011-02-25 02:25:35 +00003478 case NestedNameSpecifier::Global:
3479 // There is no meaningful transformation that one could perform on the
3480 // global scope.
3481 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3482 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003483
Nikola Smiljanic67860242014-09-26 00:28:20 +00003484 case NestedNameSpecifier::Super: {
3485 CXXRecordDecl *RD =
3486 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3487 SourceLocation(), QNNS->getAsRecordDecl()));
3488 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3489 break;
3490 }
3491
Douglas Gregor14454802011-02-25 02:25:35 +00003492 case NestedNameSpecifier::TypeSpecWithTemplate:
3493 case NestedNameSpecifier::TypeSpec: {
3494 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3495 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003496
Douglas Gregor14454802011-02-25 02:25:35 +00003497 if (!TL)
3498 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
Douglas Gregor14454802011-02-25 02:25:35 +00003500 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003501 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003502 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003503 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003504 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003505 if (TL.getType()->isEnumeralType())
3506 SemaRef.Diag(TL.getBeginLoc(),
3507 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003508 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3509 Q.getLocalEndLoc());
3510 break;
3511 }
Richard Trieude756fb2011-05-07 01:36:37 +00003512 // If the nested-name-specifier is an invalid type def, don't emit an
3513 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003514 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3515 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003516 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003517 << TL.getType() << SS.getRange();
3518 }
Douglas Gregor14454802011-02-25 02:25:35 +00003519 return NestedNameSpecifierLoc();
3520 }
Douglas Gregore16af532011-02-28 18:50:33 +00003521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Douglas Gregore16af532011-02-28 18:50:33 +00003523 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003524 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003525 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003527
Douglas Gregor14454802011-02-25 02:25:35 +00003528 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003529 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003530 !getDerived().AlwaysRebuild())
3531 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003532
3533 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003534 // nested-name-specifier, do so.
3535 if (SS.location_size() == NNS.getDataLength() &&
3536 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3537 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3538
3539 // Allocate new nested-name-specifier location information.
3540 return SS.getWithLocInContext(SemaRef.Context);
3541}
3542
3543template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003544DeclarationNameInfo
3545TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003546::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003547 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003548 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003549 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003550
3551 switch (Name.getNameKind()) {
3552 case DeclarationName::Identifier:
3553 case DeclarationName::ObjCZeroArgSelector:
3554 case DeclarationName::ObjCOneArgSelector:
3555 case DeclarationName::ObjCMultiArgSelector:
3556 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003557 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003558 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003559 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregorf816bd72009-09-03 22:13:48 +00003561 case DeclarationName::CXXConstructorName:
3562 case DeclarationName::CXXDestructorName:
3563 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003564 TypeSourceInfo *NewTInfo;
3565 CanQualType NewCanTy;
3566 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003567 NewTInfo = getDerived().TransformType(OldTInfo);
3568 if (!NewTInfo)
3569 return DeclarationNameInfo();
3570 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003571 }
3572 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003573 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003574 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003575 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003576 if (NewT.isNull())
3577 return DeclarationNameInfo();
3578 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3579 }
Mike Stump11289f42009-09-09 15:08:12 +00003580
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003581 DeclarationName NewName
3582 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3583 NewCanTy);
3584 DeclarationNameInfo NewNameInfo(NameInfo);
3585 NewNameInfo.setName(NewName);
3586 NewNameInfo.setNamedTypeInfo(NewTInfo);
3587 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003588 }
Mike Stump11289f42009-09-09 15:08:12 +00003589 }
3590
David Blaikie83d382b2011-09-23 05:06:16 +00003591 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003592}
3593
3594template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003595TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003596TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3597 TemplateName Name,
3598 SourceLocation NameLoc,
3599 QualType ObjectType,
3600 NamedDecl *FirstQualifierInScope) {
3601 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3602 TemplateDecl *Template = QTN->getTemplateDecl();
3603 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregor9db53502011-03-02 18:07:45 +00003605 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003606 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003607 Template));
3608 if (!TransTemplate)
3609 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003610
Douglas Gregor9db53502011-03-02 18:07:45 +00003611 if (!getDerived().AlwaysRebuild() &&
3612 SS.getScopeRep() == QTN->getQualifier() &&
3613 TransTemplate == Template)
3614 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003615
Douglas Gregor9db53502011-03-02 18:07:45 +00003616 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3617 TransTemplate);
3618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregor9db53502011-03-02 18:07:45 +00003620 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3621 if (SS.getScopeRep()) {
3622 // These apply to the scope specifier, not the template.
3623 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003624 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003625 }
3626
Douglas Gregor9db53502011-03-02 18:07:45 +00003627 if (!getDerived().AlwaysRebuild() &&
3628 SS.getScopeRep() == DTN->getQualifier() &&
3629 ObjectType.isNull())
3630 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003631
Douglas Gregor9db53502011-03-02 18:07:45 +00003632 if (DTN->isIdentifier()) {
3633 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003634 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003635 NameLoc,
3636 ObjectType,
3637 FirstQualifierInScope);
3638 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor9db53502011-03-02 18:07:45 +00003640 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3641 ObjectType);
3642 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor9db53502011-03-02 18:07:45 +00003644 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3645 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003646 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003647 Template));
3648 if (!TransTemplate)
3649 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregor9db53502011-03-02 18:07:45 +00003651 if (!getDerived().AlwaysRebuild() &&
3652 TransTemplate == Template)
3653 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003654
Douglas Gregor9db53502011-03-02 18:07:45 +00003655 return TemplateName(TransTemplate);
3656 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003657
Douglas Gregor9db53502011-03-02 18:07:45 +00003658 if (SubstTemplateTemplateParmPackStorage *SubstPack
3659 = Name.getAsSubstTemplateTemplateParmPack()) {
3660 TemplateTemplateParmDecl *TransParam
3661 = cast_or_null<TemplateTemplateParmDecl>(
3662 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3663 if (!TransParam)
3664 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
Douglas Gregor9db53502011-03-02 18:07:45 +00003666 if (!getDerived().AlwaysRebuild() &&
3667 TransParam == SubstPack->getParameterPack())
3668 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
3670 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003671 SubstPack->getArgumentPack());
3672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
Douglas Gregor9db53502011-03-02 18:07:45 +00003674 // These should be getting filtered out before they reach the AST.
3675 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003676}
3677
3678template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003679void TreeTransform<Derived>::InventTemplateArgumentLoc(
3680 const TemplateArgument &Arg,
3681 TemplateArgumentLoc &Output) {
3682 SourceLocation Loc = getDerived().getBaseLocation();
3683 switch (Arg.getKind()) {
3684 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003685 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003686 break;
3687
3688 case TemplateArgument::Type:
3689 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003690 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
John McCall0ad16662009-10-29 08:12:44 +00003692 break;
3693
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003694 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003695 case TemplateArgument::TemplateExpansion: {
3696 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003697 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003698 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3699 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3700 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3701 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor9d802122011-03-02 17:09:35 +00003703 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003704 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003705 Builder.getWithLocInContext(SemaRef.Context),
3706 Loc);
3707 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003708 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003709 Builder.getWithLocInContext(SemaRef.Context),
3710 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003712 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003713 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003714
John McCall0ad16662009-10-29 08:12:44 +00003715 case TemplateArgument::Expression:
3716 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3717 break;
3718
3719 case TemplateArgument::Declaration:
3720 case TemplateArgument::Integral:
3721 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003722 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003723 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003724 break;
3725 }
3726}
3727
3728template<typename Derived>
3729bool TreeTransform<Derived>::TransformTemplateArgument(
3730 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003731 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003732 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003733 switch (Arg.getKind()) {
3734 case TemplateArgument::Null:
3735 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003736 case TemplateArgument::Pack:
3737 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003738 case TemplateArgument::NullPtr:
3739 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003740
Douglas Gregore922c772009-08-04 22:27:00 +00003741 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003742 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003743 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003744 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003745
3746 DI = getDerived().TransformType(DI);
3747 if (!DI) return true;
3748
3749 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3750 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003751 }
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003753 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003754 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3755 if (QualifierLoc) {
3756 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3757 if (!QualifierLoc)
3758 return true;
3759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Douglas Gregordf846d12011-03-02 18:46:51 +00003761 CXXScopeSpec SS;
3762 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003763 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003764 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3765 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003766 if (Template.isNull())
3767 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003768
Douglas Gregor9d802122011-03-02 17:09:35 +00003769 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003770 Input.getTemplateNameLoc());
3771 return false;
3772 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003773
3774 case TemplateArgument::TemplateExpansion:
3775 llvm_unreachable("Caller should expand pack expansions");
3776
Douglas Gregore922c772009-08-04 22:27:00 +00003777 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003778 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003779 EnterExpressionEvaluationContext Unevaluated(
3780 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003781
John McCall0ad16662009-10-29 08:12:44 +00003782 Expr *InputExpr = Input.getSourceExpression();
3783 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3784
Chris Lattnercdb591a2011-04-25 20:37:58 +00003785 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003786 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003787 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003788 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003789 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003790 }
Douglas Gregore922c772009-08-04 22:27:00 +00003791 }
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregore922c772009-08-04 22:27:00 +00003793 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003794 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003795}
3796
Douglas Gregorfe921a72010-12-20 23:36:19 +00003797/// \brief Iterator adaptor that invents template argument location information
3798/// for each of the template arguments in its underlying iterator.
3799template<typename Derived, typename InputIterator>
3800class TemplateArgumentLocInventIterator {
3801 TreeTransform<Derived> &Self;
3802 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003803
Douglas Gregorfe921a72010-12-20 23:36:19 +00003804public:
3805 typedef TemplateArgumentLoc value_type;
3806 typedef TemplateArgumentLoc reference;
3807 typedef typename std::iterator_traits<InputIterator>::difference_type
3808 difference_type;
3809 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
Douglas Gregorfe921a72010-12-20 23:36:19 +00003811 class pointer {
3812 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003813
Douglas Gregorfe921a72010-12-20 23:36:19 +00003814 public:
3815 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregorfe921a72010-12-20 23:36:19 +00003817 const TemplateArgumentLoc *operator->() const { return &Arg; }
3818 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003819
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003820 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003821
Douglas Gregorfe921a72010-12-20 23:36:19 +00003822 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3823 InputIterator Iter)
3824 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregorfe921a72010-12-20 23:36:19 +00003826 TemplateArgumentLocInventIterator &operator++() {
3827 ++Iter;
3828 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003829 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
Douglas Gregorfe921a72010-12-20 23:36:19 +00003831 TemplateArgumentLocInventIterator operator++(int) {
3832 TemplateArgumentLocInventIterator Old(*this);
3833 ++(*this);
3834 return Old;
3835 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Douglas Gregorfe921a72010-12-20 23:36:19 +00003837 reference operator*() const {
3838 TemplateArgumentLoc Result;
3839 Self.InventTemplateArgumentLoc(*Iter, Result);
3840 return Result;
3841 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003842
Douglas Gregorfe921a72010-12-20 23:36:19 +00003843 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003844
Douglas Gregorfe921a72010-12-20 23:36:19 +00003845 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3846 const TemplateArgumentLocInventIterator &Y) {
3847 return X.Iter == Y.Iter;
3848 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003849
Douglas Gregorfe921a72010-12-20 23:36:19 +00003850 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3851 const TemplateArgumentLocInventIterator &Y) {
3852 return X.Iter != Y.Iter;
3853 }
3854};
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor42cafa82010-12-20 17:42:22 +00003856template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003857template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003858bool TreeTransform<Derived>::TransformTemplateArguments(
3859 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3860 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003861 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003862 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003863 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003865 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3866 // Unpack argument packs, which we translate them into separate
3867 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003868 // FIXME: We could do much better if we could guarantee that the
3869 // TemplateArgumentLocInfo for the pack expansion would be usable for
3870 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003871 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003872 TemplateArgument::pack_iterator>
3873 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003874 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003875 In.getArgument().pack_begin()),
3876 PackLocIterator(*this,
3877 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003878 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003879 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003881 continue;
3882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003883
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003884 if (In.getArgument().isPackExpansion()) {
3885 // We have a pack expansion, for which we will be substituting into
3886 // the pattern.
3887 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003888 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003889 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003890 = getSema().getTemplateArgumentPackExpansionPattern(
3891 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003892
Chris Lattner01cf8db2011-07-20 06:58:45 +00003893 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003894 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3895 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003897 // Determine whether the set of unexpanded parameter packs can and should
3898 // be expanded.
3899 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003901 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003902 if (getDerived().TryExpandParameterPacks(Ellipsis,
3903 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003904 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003905 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003906 RetainExpansion,
3907 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003908 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003909
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003910 if (!Expand) {
3911 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003912 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003913 // expansion.
3914 TemplateArgumentLoc OutPattern;
3915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003916 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003917 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003918
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003919 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3920 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003921 if (Out.getArgument().isNull())
3922 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003924 Outputs.addArgument(Out);
3925 continue;
3926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003928 // The transform has determined that we should perform an elementwise
3929 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003930 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003931 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3932
Richard Smithd784e682015-09-23 21:41:42 +00003933 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003934 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003935
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003936 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003937 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3938 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003939 if (Out.getArgument().isNull())
3940 return true;
3941 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003942
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003943 Outputs.addArgument(Out);
3944 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
Douglas Gregor48d24112011-01-10 20:53:55 +00003946 // If we're supposed to retain a pack expansion, do so by temporarily
3947 // forgetting the partially-substituted parameter pack.
3948 if (RetainExpansion) {
3949 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003950
Richard Smithd784e682015-09-23 21:41:42 +00003951 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003952 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003953
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003954 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3955 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003956 if (Out.getArgument().isNull())
3957 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003958
Douglas Gregor48d24112011-01-10 20:53:55 +00003959 Outputs.addArgument(Out);
3960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003961
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003962 continue;
3963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003964
3965 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003966 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003967 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003968
Douglas Gregor42cafa82010-12-20 17:42:22 +00003969 Outputs.addArgument(Out);
3970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003971
Douglas Gregor42cafa82010-12-20 17:42:22 +00003972 return false;
3973
3974}
3975
Douglas Gregord6ff3322009-08-04 16:50:30 +00003976//===----------------------------------------------------------------------===//
3977// Type transformation
3978//===----------------------------------------------------------------------===//
3979
3980template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003981QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003982 if (getDerived().AlreadyTransformed(T))
3983 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003984
John McCall550e0c22009-10-21 00:40:46 +00003985 // Temporary workaround. All of these transformations should
3986 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003987 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3988 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003989
John McCall31f82722010-11-12 08:19:04 +00003990 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003991
John McCall550e0c22009-10-21 00:40:46 +00003992 if (!NewDI)
3993 return QualType();
3994
3995 return NewDI->getType();
3996}
3997
3998template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003999TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004000 // Refine the base location to the type's location.
4001 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4002 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004003 if (getDerived().AlreadyTransformed(DI->getType()))
4004 return DI;
4005
4006 TypeLocBuilder TLB;
4007
4008 TypeLoc TL = DI->getTypeLoc();
4009 TLB.reserve(TL.getFullDataSize());
4010
John McCall31f82722010-11-12 08:19:04 +00004011 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004012 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004013 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004014
John McCallbcd03502009-12-07 02:54:59 +00004015 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004016}
4017
4018template<typename Derived>
4019QualType
John McCall31f82722010-11-12 08:19:04 +00004020TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004021 switch (T.getTypeLocClass()) {
4022#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004023#define TYPELOC(CLASS, PARENT) \
4024 case TypeLoc::CLASS: \
4025 return getDerived().Transform##CLASS##Type(TLB, \
4026 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004027#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004028 }
Mike Stump11289f42009-09-09 15:08:12 +00004029
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004030 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004031}
4032
4033/// FIXME: By default, this routine adds type qualifiers only to types
4034/// that can have qualifiers, and silently suppresses those qualifiers
4035/// that are not permitted (e.g., qualifiers on reference or function
4036/// types). This is the right thing for template instantiation, but
4037/// probably not for other clients.
4038template<typename Derived>
4039QualType
4040TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004041 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004042 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004043
John McCall31f82722010-11-12 08:19:04 +00004044 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004045 if (Result.isNull())
4046 return QualType();
4047
4048 // Silently suppress qualifiers if the result type can't be qualified.
4049 // FIXME: this is the right thing for template instantiation, but
4050 // probably not for other clients.
4051 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00004053
John McCall31168b02011-06-15 23:02:42 +00004054 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004055 // resulting type.
4056 if (Quals.hasObjCLifetime()) {
4057 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
4058 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00004059 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004060 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004061 // A lifetime qualifier applied to a substituted template parameter
4062 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004063 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004064 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00004065 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
4066 QualType Replacement = SubstTypeParam->getReplacementType();
4067 Qualifiers Qs = Replacement.getQualifiers();
4068 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00004069 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00004070 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
4071 Qs);
4072 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00004073 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00004074 Replacement);
4075 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00004076 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
4077 // 'auto' types behave the same way as template parameters.
4078 QualType Deduced = AutoTy->getDeducedType();
4079 Qualifiers Qs = Deduced.getQualifiers();
4080 Qs.removeObjCLifetime();
4081 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
4082 Qs);
Richard Smithe301ba22015-11-11 02:02:15 +00004083 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
Faisal Vali2b391ab2013-09-26 19:54:12 +00004084 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00004085 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00004086 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004087 // Otherwise, complain about the addition of a qualifier to an
4088 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00004089 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00004090 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00004091 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00004092
Douglas Gregore46db902011-06-17 22:11:49 +00004093 Quals.removeObjCLifetime();
4094 }
4095 }
4096 }
John McCallcb0f89a2010-06-05 06:41:15 +00004097 if (!Quals.empty()) {
4098 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00004099 // BuildQualifiedType might not add qualifiers if they are invalid.
4100 if (Result.hasLocalQualifiers())
4101 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00004102 // No location information to preserve.
4103 }
John McCall550e0c22009-10-21 00:40:46 +00004104
4105 return Result;
4106}
4107
Douglas Gregor14454802011-02-25 02:25:35 +00004108template<typename Derived>
4109TypeLoc
4110TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4111 QualType ObjectType,
4112 NamedDecl *UnqualLookup,
4113 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004114 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004115 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004117 TypeSourceInfo *TSI =
4118 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4119 if (TSI)
4120 return TSI->getTypeLoc();
4121 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004122}
4123
Douglas Gregor579c15f2011-03-02 18:32:08 +00004124template<typename Derived>
4125TypeSourceInfo *
4126TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4127 QualType ObjectType,
4128 NamedDecl *UnqualLookup,
4129 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004130 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004131 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004133 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4134 UnqualLookup, SS);
4135}
4136
4137template <typename Derived>
4138TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4139 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4140 CXXScopeSpec &SS) {
4141 QualType T = TL.getType();
4142 assert(!getDerived().AlreadyTransformed(T));
4143
Douglas Gregor579c15f2011-03-02 18:32:08 +00004144 TypeLocBuilder TLB;
4145 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004146
Douglas Gregor579c15f2011-03-02 18:32:08 +00004147 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004148 TemplateSpecializationTypeLoc SpecTL =
4149 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
Douglas Gregor579c15f2011-03-02 18:32:08 +00004151 TemplateName Template
4152 = getDerived().TransformTemplateName(SS,
4153 SpecTL.getTypePtr()->getTemplateName(),
4154 SpecTL.getTemplateNameLoc(),
4155 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00004156 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004157 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004158
4159 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004160 Template);
4161 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004162 DependentTemplateSpecializationTypeLoc SpecTL =
4163 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004164
Douglas Gregor579c15f2011-03-02 18:32:08 +00004165 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004166 = getDerived().RebuildTemplateName(SS,
4167 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004168 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00004169 ObjectType, UnqualLookup);
4170 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004171 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
4173 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004174 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004175 Template,
4176 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004177 } else {
4178 // Nothing special needs to be done for these.
4179 Result = getDerived().TransformType(TLB, TL);
4180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004181
4182 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004183 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004184
Douglas Gregor579c15f2011-03-02 18:32:08 +00004185 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4186}
4187
John McCall550e0c22009-10-21 00:40:46 +00004188template <class TyLoc> static inline
4189QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4190 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4191 NewT.setNameLoc(T.getNameLoc());
4192 return T.getType();
4193}
4194
John McCall550e0c22009-10-21 00:40:46 +00004195template<typename Derived>
4196QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004197 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004198 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4199 NewT.setBuiltinLoc(T.getBuiltinLoc());
4200 if (T.needsExtraLocalData())
4201 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4202 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004203}
Mike Stump11289f42009-09-09 15:08:12 +00004204
Douglas Gregord6ff3322009-08-04 16:50:30 +00004205template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004206QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004207 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004208 // FIXME: recurse?
4209 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004210}
Mike Stump11289f42009-09-09 15:08:12 +00004211
Reid Kleckner0503a872013-12-05 01:23:43 +00004212template <typename Derived>
4213QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4214 AdjustedTypeLoc TL) {
4215 // Adjustments applied during transformation are handled elsewhere.
4216 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4217}
4218
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004220QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4221 DecayedTypeLoc TL) {
4222 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4223 if (OriginalType.isNull())
4224 return QualType();
4225
4226 QualType Result = TL.getType();
4227 if (getDerived().AlwaysRebuild() ||
4228 OriginalType != TL.getOriginalLoc().getType())
4229 Result = SemaRef.Context.getDecayedType(OriginalType);
4230 TLB.push<DecayedTypeLoc>(Result);
4231 // Nothing to set for DecayedTypeLoc.
4232 return Result;
4233}
4234
4235template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004236QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004237 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004238 QualType PointeeType
4239 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004240 if (PointeeType.isNull())
4241 return QualType();
4242
4243 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004244 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004245 // A dependent pointer type 'T *' has is being transformed such
4246 // that an Objective-C class type is being replaced for 'T'. The
4247 // resulting pointer type is an ObjCObjectPointerType, not a
4248 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004249 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004250
John McCall8b07ec22010-05-15 11:32:37 +00004251 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4252 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004253 return Result;
4254 }
John McCall31f82722010-11-12 08:19:04 +00004255
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004256 if (getDerived().AlwaysRebuild() ||
4257 PointeeType != TL.getPointeeLoc().getType()) {
4258 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4259 if (Result.isNull())
4260 return QualType();
4261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004262
John McCall31168b02011-06-15 23:02:42 +00004263 // Objective-C ARC can add lifetime qualifiers to the type that we're
4264 // pointing to.
4265 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004266
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004267 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4268 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004269 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004270}
Mike Stump11289f42009-09-09 15:08:12 +00004271
4272template<typename Derived>
4273QualType
John McCall550e0c22009-10-21 00:40:46 +00004274TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004275 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004276 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004277 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4278 if (PointeeType.isNull())
4279 return QualType();
4280
4281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() ||
4283 PointeeType != TL.getPointeeLoc().getType()) {
4284 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004285 TL.getSigilLoc());
4286 if (Result.isNull())
4287 return QualType();
4288 }
4289
Douglas Gregor049211a2010-04-22 16:50:51 +00004290 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004291 NewT.setSigilLoc(TL.getSigilLoc());
4292 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004293}
4294
John McCall70dd5f62009-10-30 00:06:24 +00004295/// Transforms a reference type. Note that somewhat paradoxically we
4296/// don't care whether the type itself is an l-value type or an r-value
4297/// type; we only care if the type was *written* as an l-value type
4298/// or an r-value type.
4299template<typename Derived>
4300QualType
4301TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004302 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004303 const ReferenceType *T = TL.getTypePtr();
4304
4305 // Note that this works with the pointee-as-written.
4306 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4307 if (PointeeType.isNull())
4308 return QualType();
4309
4310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
4312 PointeeType != T->getPointeeTypeAsWritten()) {
4313 Result = getDerived().RebuildReferenceType(PointeeType,
4314 T->isSpelledAsLValue(),
4315 TL.getSigilLoc());
4316 if (Result.isNull())
4317 return QualType();
4318 }
4319
John McCall31168b02011-06-15 23:02:42 +00004320 // Objective-C ARC can add lifetime qualifiers to the type that we're
4321 // referring to.
4322 TLB.TypeWasModifiedSafely(
4323 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4324
John McCall70dd5f62009-10-30 00:06:24 +00004325 // r-value references can be rebuilt as l-value references.
4326 ReferenceTypeLoc NewTL;
4327 if (isa<LValueReferenceType>(Result))
4328 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4329 else
4330 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4331 NewTL.setSigilLoc(TL.getSigilLoc());
4332
4333 return Result;
4334}
4335
Mike Stump11289f42009-09-09 15:08:12 +00004336template<typename Derived>
4337QualType
John McCall550e0c22009-10-21 00:40:46 +00004338TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004339 LValueReferenceTypeLoc TL) {
4340 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004341}
4342
Mike Stump11289f42009-09-09 15:08:12 +00004343template<typename Derived>
4344QualType
John McCall550e0c22009-10-21 00:40:46 +00004345TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004346 RValueReferenceTypeLoc TL) {
4347 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregord6ff3322009-08-04 16:50:30 +00004350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004351QualType
John McCall550e0c22009-10-21 00:40:46 +00004352TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004353 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004354 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355 if (PointeeType.isNull())
4356 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004357
Abramo Bagnara509357842011-03-05 14:42:21 +00004358 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004359 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004360 if (OldClsTInfo) {
4361 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4362 if (!NewClsTInfo)
4363 return QualType();
4364 }
4365
4366 const MemberPointerType *T = TL.getTypePtr();
4367 QualType OldClsType = QualType(T->getClass(), 0);
4368 QualType NewClsType;
4369 if (NewClsTInfo)
4370 NewClsType = NewClsTInfo->getType();
4371 else {
4372 NewClsType = getDerived().TransformType(OldClsType);
4373 if (NewClsType.isNull())
4374 return QualType();
4375 }
Mike Stump11289f42009-09-09 15:08:12 +00004376
John McCall550e0c22009-10-21 00:40:46 +00004377 QualType Result = TL.getType();
4378 if (getDerived().AlwaysRebuild() ||
4379 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004380 NewClsType != OldClsType) {
4381 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004382 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004383 if (Result.isNull())
4384 return QualType();
4385 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004386
Reid Kleckner0503a872013-12-05 01:23:43 +00004387 // If we had to adjust the pointee type when building a member pointer, make
4388 // sure to push TypeLoc info for it.
4389 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4390 if (MPT && PointeeType != MPT->getPointeeType()) {
4391 assert(isa<AdjustedType>(MPT->getPointeeType()));
4392 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4393 }
4394
John McCall550e0c22009-10-21 00:40:46 +00004395 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4396 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004397 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004398
4399 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004400}
4401
Mike Stump11289f42009-09-09 15:08:12 +00004402template<typename Derived>
4403QualType
John McCall550e0c22009-10-21 00:40:46 +00004404TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004405 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004406 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004407 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004408 if (ElementType.isNull())
4409 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004410
John McCall550e0c22009-10-21 00:40:46 +00004411 QualType Result = TL.getType();
4412 if (getDerived().AlwaysRebuild() ||
4413 ElementType != T->getElementType()) {
4414 Result = getDerived().RebuildConstantArrayType(ElementType,
4415 T->getSizeModifier(),
4416 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004417 T->getIndexTypeCVRQualifiers(),
4418 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004419 if (Result.isNull())
4420 return QualType();
4421 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004422
4423 // We might have either a ConstantArrayType or a VariableArrayType now:
4424 // a ConstantArrayType is allowed to have an element type which is a
4425 // VariableArrayType if the type is dependent. Fortunately, all array
4426 // types have the same location layout.
4427 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004428 NewTL.setLBracketLoc(TL.getLBracketLoc());
4429 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004430
John McCall550e0c22009-10-21 00:40:46 +00004431 Expr *Size = TL.getSizeExpr();
4432 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004433 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4434 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004435 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4436 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004437 }
4438 NewTL.setSizeExpr(Size);
4439
4440 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregord6ff3322009-08-04 16:50:30 +00004443template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004444QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004445 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004446 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004447 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004448 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004449 if (ElementType.isNull())
4450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004451
John McCall550e0c22009-10-21 00:40:46 +00004452 QualType Result = TL.getType();
4453 if (getDerived().AlwaysRebuild() ||
4454 ElementType != T->getElementType()) {
4455 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004456 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004457 T->getIndexTypeCVRQualifiers(),
4458 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004459 if (Result.isNull())
4460 return QualType();
4461 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004462
John McCall550e0c22009-10-21 00:40:46 +00004463 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4464 NewTL.setLBracketLoc(TL.getLBracketLoc());
4465 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004466 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004467
4468 return Result;
4469}
4470
4471template<typename Derived>
4472QualType
4473TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004474 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004475 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004476 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4477 if (ElementType.isNull())
4478 return QualType();
4479
John McCalldadc5752010-08-24 06:29:42 +00004480 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004481 = getDerived().TransformExpr(T->getSizeExpr());
4482 if (SizeResult.isInvalid())
4483 return QualType();
4484
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004485 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004486
4487 QualType Result = TL.getType();
4488 if (getDerived().AlwaysRebuild() ||
4489 ElementType != T->getElementType() ||
4490 Size != T->getSizeExpr()) {
4491 Result = getDerived().RebuildVariableArrayType(ElementType,
4492 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004493 Size,
John McCall550e0c22009-10-21 00:40:46 +00004494 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004495 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004496 if (Result.isNull())
4497 return QualType();
4498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004499
Serge Pavlov774c6d02014-02-06 03:49:11 +00004500 // We might have constant size array now, but fortunately it has the same
4501 // location layout.
4502 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004503 NewTL.setLBracketLoc(TL.getLBracketLoc());
4504 NewTL.setRBracketLoc(TL.getRBracketLoc());
4505 NewTL.setSizeExpr(Size);
4506
4507 return Result;
4508}
4509
4510template<typename Derived>
4511QualType
4512TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004513 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004514 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004515 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4516 if (ElementType.isNull())
4517 return QualType();
4518
Richard Smith764d2fe2011-12-20 02:08:33 +00004519 // Array bounds are constant expressions.
4520 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4521 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004522
John McCall33ddac02011-01-19 10:06:00 +00004523 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4524 Expr *origSize = TL.getSizeExpr();
4525 if (!origSize) origSize = T->getSizeExpr();
4526
4527 ExprResult sizeResult
4528 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004529 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004530 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004531 return QualType();
4532
John McCall33ddac02011-01-19 10:06:00 +00004533 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004534
4535 QualType Result = TL.getType();
4536 if (getDerived().AlwaysRebuild() ||
4537 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004538 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004539 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4540 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004541 size,
John McCall550e0c22009-10-21 00:40:46 +00004542 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004543 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004544 if (Result.isNull())
4545 return QualType();
4546 }
John McCall550e0c22009-10-21 00:40:46 +00004547
4548 // We might have any sort of array type now, but fortunately they
4549 // all have the same location layout.
4550 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4551 NewTL.setLBracketLoc(TL.getLBracketLoc());
4552 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004553 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004554
4555 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004556}
Mike Stump11289f42009-09-09 15:08:12 +00004557
4558template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004559QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004560 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004561 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004562 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004563
4564 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004565 QualType ElementType = getDerived().TransformType(T->getElementType());
4566 if (ElementType.isNull())
4567 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004568
Richard Smith764d2fe2011-12-20 02:08:33 +00004569 // Vector sizes are constant expressions.
4570 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4571 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004572
John McCalldadc5752010-08-24 06:29:42 +00004573 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004574 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575 if (Size.isInvalid())
4576 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004577
John McCall550e0c22009-10-21 00:40:46 +00004578 QualType Result = TL.getType();
4579 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004580 ElementType != T->getElementType() ||
4581 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004582 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004583 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004584 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004585 if (Result.isNull())
4586 return QualType();
4587 }
John McCall550e0c22009-10-21 00:40:46 +00004588
4589 // Result might be dependent or not.
4590 if (isa<DependentSizedExtVectorType>(Result)) {
4591 DependentSizedExtVectorTypeLoc NewTL
4592 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4593 NewTL.setNameLoc(TL.getNameLoc());
4594 } else {
4595 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4596 NewTL.setNameLoc(TL.getNameLoc());
4597 }
4598
4599 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
4602template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004603QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004604 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004605 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004606 QualType ElementType = getDerived().TransformType(T->getElementType());
4607 if (ElementType.isNull())
4608 return QualType();
4609
John McCall550e0c22009-10-21 00:40:46 +00004610 QualType Result = TL.getType();
4611 if (getDerived().AlwaysRebuild() ||
4612 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004613 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004614 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004615 if (Result.isNull())
4616 return QualType();
4617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004618
John McCall550e0c22009-10-21 00:40:46 +00004619 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4620 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCall550e0c22009-10-21 00:40:46 +00004622 return Result;
4623}
4624
4625template<typename Derived>
4626QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004627 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004628 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004629 QualType ElementType = getDerived().TransformType(T->getElementType());
4630 if (ElementType.isNull())
4631 return QualType();
4632
4633 QualType Result = TL.getType();
4634 if (getDerived().AlwaysRebuild() ||
4635 ElementType != T->getElementType()) {
4636 Result = getDerived().RebuildExtVectorType(ElementType,
4637 T->getNumElements(),
4638 /*FIXME*/ SourceLocation());
4639 if (Result.isNull())
4640 return QualType();
4641 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004642
John McCall550e0c22009-10-21 00:40:46 +00004643 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4644 NewTL.setNameLoc(TL.getNameLoc());
4645
4646 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004647}
Mike Stump11289f42009-09-09 15:08:12 +00004648
David Blaikie05785d12013-02-20 22:23:23 +00004649template <typename Derived>
4650ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4651 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4652 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004653 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004654 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004655
Douglas Gregor715e4612011-01-14 22:40:04 +00004656 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004657 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004658 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004659 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004660 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004661
Douglas Gregor715e4612011-01-14 22:40:04 +00004662 TypeLocBuilder TLB;
4663 TypeLoc NewTL = OldDI->getTypeLoc();
4664 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004665
4666 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004667 OldExpansionTL.getPatternLoc());
4668 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004669 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004670
4671 Result = RebuildPackExpansionType(Result,
4672 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004673 OldExpansionTL.getEllipsisLoc(),
4674 NumExpansions);
4675 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004676 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004677
Douglas Gregor715e4612011-01-14 22:40:04 +00004678 PackExpansionTypeLoc NewExpansionTL
4679 = TLB.push<PackExpansionTypeLoc>(Result);
4680 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4681 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4682 } else
4683 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004684 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004685 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004686
John McCall8fb0d9d2011-05-01 22:35:37 +00004687 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004688 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004689
4690 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4691 OldParm->getDeclContext(),
4692 OldParm->getInnerLocStart(),
4693 OldParm->getLocation(),
4694 OldParm->getIdentifier(),
4695 NewDI->getType(),
4696 NewDI,
4697 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004698 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004699 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4700 OldParm->getFunctionScopeIndex() + indexAdjustment);
4701 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004702}
4703
David Majnemer59f77922016-06-24 04:05:48 +00004704template <typename Derived>
4705bool TreeTransform<Derived>::TransformFunctionTypeParams(
4706 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4707 const QualType *ParamTypes,
4708 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4709 SmallVectorImpl<QualType> &OutParamTypes,
4710 SmallVectorImpl<ParmVarDecl *> *PVars,
4711 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004712 int indexAdjustment = 0;
4713
David Majnemer59f77922016-06-24 04:05:48 +00004714 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004715 for (unsigned i = 0; i != NumParams; ++i) {
4716 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004717 assert(OldParm->getFunctionScopeIndex() == i);
4718
David Blaikie05785d12013-02-20 22:23:23 +00004719 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004720 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004721 if (OldParm->isParameterPack()) {
4722 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004723 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004724
Douglas Gregor5499af42011-01-05 23:12:31 +00004725 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004726 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004727 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004728 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4729 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004730 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4731
Douglas Gregor5499af42011-01-05 23:12:31 +00004732 // Determine whether we should expand the parameter packs.
4733 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004734 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004735 Optional<unsigned> OrigNumExpansions =
4736 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004737 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004738 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4739 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004740 Unexpanded,
4741 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004742 RetainExpansion,
4743 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004744 return true;
4745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004746
Douglas Gregor5499af42011-01-05 23:12:31 +00004747 if (ShouldExpand) {
4748 // Expand the function parameter pack into multiple, separate
4749 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004750 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004751 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004752 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004753 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004754 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004755 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004756 OrigNumExpansions,
4757 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004758 if (!NewParm)
4759 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004760
John McCallc8e321d2016-03-01 02:09:25 +00004761 if (ParamInfos)
4762 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004763 OutParamTypes.push_back(NewParm->getType());
4764 if (PVars)
4765 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004766 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004767
4768 // If we're supposed to retain a pack expansion, do so by temporarily
4769 // forgetting the partially-substituted parameter pack.
4770 if (RetainExpansion) {
4771 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004772 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004773 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004774 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004775 OrigNumExpansions,
4776 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004777 if (!NewParm)
4778 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004779
John McCallc8e321d2016-03-01 02:09:25 +00004780 if (ParamInfos)
4781 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004782 OutParamTypes.push_back(NewParm->getType());
4783 if (PVars)
4784 PVars->push_back(NewParm);
4785 }
4786
John McCall8fb0d9d2011-05-01 22:35:37 +00004787 // The next parameter should have the same adjustment as the
4788 // last thing we pushed, but we post-incremented indexAdjustment
4789 // on every push. Also, if we push nothing, the adjustment should
4790 // go down by one.
4791 indexAdjustment--;
4792
Douglas Gregor5499af42011-01-05 23:12:31 +00004793 // We're done with the pack expansion.
4794 continue;
4795 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004796
4797 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004798 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4800 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004801 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004802 NumExpansions,
4803 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004804 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004805 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004806 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004807 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004808
John McCall58f10c32010-03-11 09:03:00 +00004809 if (!NewParm)
4810 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004811
John McCallc8e321d2016-03-01 02:09:25 +00004812 if (ParamInfos)
4813 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004814 OutParamTypes.push_back(NewParm->getType());
4815 if (PVars)
4816 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004817 continue;
4818 }
John McCall58f10c32010-03-11 09:03:00 +00004819
4820 // Deal with the possibility that we don't have a parameter
4821 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004822 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004823 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004824 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004825 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004826 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004827 = dyn_cast<PackExpansionType>(OldType)) {
4828 // We have a function parameter pack that may need to be expanded.
4829 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004830 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004831 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004832
Douglas Gregor5499af42011-01-05 23:12:31 +00004833 // Determine whether we should expand the parameter packs.
4834 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004835 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004836 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004837 Unexpanded,
4838 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004839 RetainExpansion,
4840 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004841 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004842 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004843
Douglas Gregor5499af42011-01-05 23:12:31 +00004844 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004845 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004846 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004847 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004848 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4849 QualType NewType = getDerived().TransformType(Pattern);
4850 if (NewType.isNull())
4851 return true;
John McCall58f10c32010-03-11 09:03:00 +00004852
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004853 if (NewType->containsUnexpandedParameterPack()) {
4854 NewType =
4855 getSema().getASTContext().getPackExpansionType(NewType, None);
4856
4857 if (NewType.isNull())
4858 return true;
4859 }
4860
John McCallc8e321d2016-03-01 02:09:25 +00004861 if (ParamInfos)
4862 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004863 OutParamTypes.push_back(NewType);
4864 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004865 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004867
Douglas Gregor5499af42011-01-05 23:12:31 +00004868 // We're done with the pack expansion.
4869 continue;
4870 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004871
Douglas Gregor48d24112011-01-10 20:53:55 +00004872 // If we're supposed to retain a pack expansion, do so by temporarily
4873 // forgetting the partially-substituted parameter pack.
4874 if (RetainExpansion) {
4875 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4876 QualType NewType = getDerived().TransformType(Pattern);
4877 if (NewType.isNull())
4878 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
John McCallc8e321d2016-03-01 02:09:25 +00004880 if (ParamInfos)
4881 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00004882 OutParamTypes.push_back(NewType);
4883 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004884 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004885 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004886
Chad Rosier1dcde962012-08-08 18:46:20 +00004887 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004888 // expansion.
4889 OldType = Expansion->getPattern();
4890 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004891 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4892 NewType = getDerived().TransformType(OldType);
4893 } else {
4894 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004895 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004896
Douglas Gregor5499af42011-01-05 23:12:31 +00004897 if (NewType.isNull())
4898 return true;
4899
4900 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004901 NewType = getSema().Context.getPackExpansionType(NewType,
4902 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004903
John McCallc8e321d2016-03-01 02:09:25 +00004904 if (ParamInfos)
4905 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004906 OutParamTypes.push_back(NewType);
4907 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004908 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004909 }
4910
John McCall8fb0d9d2011-05-01 22:35:37 +00004911#ifndef NDEBUG
4912 if (PVars) {
4913 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4914 if (ParmVarDecl *parm = (*PVars)[i])
4915 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004916 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004917#endif
4918
4919 return false;
4920}
John McCall58f10c32010-03-11 09:03:00 +00004921
4922template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004923QualType
John McCall550e0c22009-10-21 00:40:46 +00004924TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004925 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004926 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004927 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004928 return getDerived().TransformFunctionProtoType(
4929 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004930 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4931 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4932 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004933 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004934}
4935
Richard Smith2e321552014-11-12 02:00:47 +00004936template<typename Derived> template<typename Fn>
4937QualType TreeTransform<Derived>::TransformFunctionProtoType(
4938 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4939 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00004940
Douglas Gregor4afc2362010-08-31 00:26:14 +00004941 // Transform the parameters and return type.
4942 //
Richard Smithf623c962012-04-17 00:58:00 +00004943 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004944 // When the function has a trailing return type, we instantiate the
4945 // parameters before the return type, since the return type can then refer
4946 // to the parameters themselves (via decltype, sizeof, etc.).
4947 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004948 SmallVector<QualType, 4> ParamTypes;
4949 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00004950 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00004951 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004952
Douglas Gregor7fb25412010-10-01 18:44:50 +00004953 QualType ResultType;
4954
Richard Smith1226c602012-08-14 22:51:13 +00004955 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004956 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004957 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004958 TL.getTypePtr()->param_type_begin(),
4959 T->getExtParameterInfosOrNull(),
4960 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004961 return QualType();
4962
Douglas Gregor3024f072012-04-16 07:05:22 +00004963 {
4964 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004965 // If a declaration declares a member function or member function
4966 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004967 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004968 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004969 // declarator.
4970 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004971
Alp Toker42a16a62014-01-25 23:51:36 +00004972 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004973 if (ResultType.isNull())
4974 return QualType();
4975 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004976 }
4977 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004978 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004979 if (ResultType.isNull())
4980 return QualType();
4981
Alp Toker9cacbab2014-01-20 20:26:09 +00004982 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00004983 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00004984 TL.getTypePtr()->param_type_begin(),
4985 T->getExtParameterInfosOrNull(),
4986 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004987 return QualType();
4988 }
4989
Richard Smith2e321552014-11-12 02:00:47 +00004990 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4991
4992 bool EPIChanged = false;
4993 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4994 return QualType();
4995
John McCallc8e321d2016-03-01 02:09:25 +00004996 // Handle extended parameter information.
4997 if (auto NewExtParamInfos =
4998 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
4999 if (!EPI.ExtParameterInfos ||
5000 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5001 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5002 EPIChanged = true;
5003 }
5004 EPI.ExtParameterInfos = NewExtParamInfos;
5005 } else if (EPI.ExtParameterInfos) {
5006 EPIChanged = true;
5007 EPI.ExtParameterInfos = nullptr;
5008 }
Richard Smithf623c962012-04-17 00:58:00 +00005009
John McCall550e0c22009-10-21 00:40:46 +00005010 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005011 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005012 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005013 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005014 if (Result.isNull())
5015 return QualType();
5016 }
Mike Stump11289f42009-09-09 15:08:12 +00005017
John McCall550e0c22009-10-21 00:40:46 +00005018 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005019 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005020 NewTL.setLParenLoc(TL.getLParenLoc());
5021 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005022 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005023 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5024 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005025
5026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005027}
Mike Stump11289f42009-09-09 15:08:12 +00005028
Douglas Gregord6ff3322009-08-04 16:50:30 +00005029template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005030bool TreeTransform<Derived>::TransformExceptionSpec(
5031 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5032 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5033 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5034
5035 // Instantiate a dynamic noexcept expression, if any.
5036 if (ESI.Type == EST_ComputedNoexcept) {
5037 EnterExpressionEvaluationContext Unevaluated(getSema(),
5038 Sema::ConstantEvaluated);
5039 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5040 if (NoexceptExpr.isInvalid())
5041 return true;
5042
Richard Smith03a4aa32016-06-23 19:02:52 +00005043 // FIXME: This is bogus, a noexcept expression is not a condition.
5044 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005045 if (NoexceptExpr.isInvalid())
5046 return true;
5047
5048 if (!NoexceptExpr.get()->isValueDependent()) {
5049 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5050 NoexceptExpr.get(), nullptr,
5051 diag::err_noexcept_needs_constant_expression,
5052 /*AllowFold*/false);
5053 if (NoexceptExpr.isInvalid())
5054 return true;
5055 }
5056
5057 if (ESI.NoexceptExpr != NoexceptExpr.get())
5058 Changed = true;
5059 ESI.NoexceptExpr = NoexceptExpr.get();
5060 }
5061
5062 if (ESI.Type != EST_Dynamic)
5063 return false;
5064
5065 // Instantiate a dynamic exception specification's type.
5066 for (QualType T : ESI.Exceptions) {
5067 if (const PackExpansionType *PackExpansion =
5068 T->getAs<PackExpansionType>()) {
5069 Changed = true;
5070
5071 // We have a pack expansion. Instantiate it.
5072 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5073 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5074 Unexpanded);
5075 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5076
5077 // Determine whether the set of unexpanded parameter packs can and
5078 // should
5079 // be expanded.
5080 bool Expand = false;
5081 bool RetainExpansion = false;
5082 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5083 // FIXME: Track the location of the ellipsis (and track source location
5084 // information for the types in the exception specification in general).
5085 if (getDerived().TryExpandParameterPacks(
5086 Loc, SourceRange(), Unexpanded, Expand,
5087 RetainExpansion, NumExpansions))
5088 return true;
5089
5090 if (!Expand) {
5091 // We can't expand this pack expansion into separate arguments yet;
5092 // just substitute into the pattern and create a new pack expansion
5093 // type.
5094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5095 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5096 if (U.isNull())
5097 return true;
5098
5099 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5100 Exceptions.push_back(U);
5101 continue;
5102 }
5103
5104 // Substitute into the pack expansion pattern for each slice of the
5105 // pack.
5106 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5107 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5108
5109 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5110 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5111 return true;
5112
5113 Exceptions.push_back(U);
5114 }
5115 } else {
5116 QualType U = getDerived().TransformType(T);
5117 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5118 return true;
5119 if (T != U)
5120 Changed = true;
5121
5122 Exceptions.push_back(U);
5123 }
5124 }
5125
5126 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005127 if (ESI.Exceptions.empty())
5128 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005129 return false;
5130}
5131
5132template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005133QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005134 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005135 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005136 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005137 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005138 if (ResultType.isNull())
5139 return QualType();
5140
5141 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005142 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005143 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5144
5145 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005146 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005147 NewTL.setLParenLoc(TL.getLParenLoc());
5148 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005149 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005150
5151 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
John McCallb96ec562009-12-04 22:46:56 +00005154template<typename Derived> QualType
5155TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005156 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005157 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005158 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005159 if (!D)
5160 return QualType();
5161
5162 QualType Result = TL.getType();
5163 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
5164 Result = getDerived().RebuildUnresolvedUsingType(D);
5165 if (Result.isNull())
5166 return QualType();
5167 }
5168
5169 // We might get an arbitrary type spec type back. We should at
5170 // least always get a type spec type, though.
5171 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5172 NewTL.setNameLoc(TL.getNameLoc());
5173
5174 return Result;
5175}
5176
Douglas Gregord6ff3322009-08-04 16:50:30 +00005177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005178QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005179 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005180 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005181 TypedefNameDecl *Typedef
5182 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5183 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184 if (!Typedef)
5185 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005186
John McCall550e0c22009-10-21 00:40:46 +00005187 QualType Result = TL.getType();
5188 if (getDerived().AlwaysRebuild() ||
5189 Typedef != T->getDecl()) {
5190 Result = getDerived().RebuildTypedefType(Typedef);
5191 if (Result.isNull())
5192 return QualType();
5193 }
Mike Stump11289f42009-09-09 15:08:12 +00005194
John McCall550e0c22009-10-21 00:40:46 +00005195 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5196 NewTL.setNameLoc(TL.getNameLoc());
5197
5198 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005202QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005203 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005204 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005205 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5206 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005207
John McCalldadc5752010-08-24 06:29:42 +00005208 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005209 if (E.isInvalid())
5210 return QualType();
5211
Eli Friedmane4f22df2012-02-29 04:03:55 +00005212 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5213 if (E.isInvalid())
5214 return QualType();
5215
John McCall550e0c22009-10-21 00:40:46 +00005216 QualType Result = TL.getType();
5217 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005218 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005219 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005220 if (Result.isNull())
5221 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005222 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005223 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005224
John McCall550e0c22009-10-21 00:40:46 +00005225 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005226 NewTL.setTypeofLoc(TL.getTypeofLoc());
5227 NewTL.setLParenLoc(TL.getLParenLoc());
5228 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005229
5230 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
5233template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005234QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005235 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005236 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5237 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5238 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005239 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005240
John McCall550e0c22009-10-21 00:40:46 +00005241 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005242 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5243 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005244 if (Result.isNull())
5245 return QualType();
5246 }
Mike Stump11289f42009-09-09 15:08:12 +00005247
John McCall550e0c22009-10-21 00:40:46 +00005248 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005249 NewTL.setTypeofLoc(TL.getTypeofLoc());
5250 NewTL.setLParenLoc(TL.getLParenLoc());
5251 NewTL.setRParenLoc(TL.getRParenLoc());
5252 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005253
5254 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255}
Mike Stump11289f42009-09-09 15:08:12 +00005256
5257template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005258QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005259 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005260 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005261
Douglas Gregore922c772009-08-04 22:27:00 +00005262 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005263 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5264 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005265
John McCalldadc5752010-08-24 06:29:42 +00005266 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267 if (E.isInvalid())
5268 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005269
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005270 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005271 if (E.isInvalid())
5272 return QualType();
5273
John McCall550e0c22009-10-21 00:40:46 +00005274 QualType Result = TL.getType();
5275 if (getDerived().AlwaysRebuild() ||
5276 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005277 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005278 if (Result.isNull())
5279 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005281 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005282
John McCall550e0c22009-10-21 00:40:46 +00005283 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5284 NewTL.setNameLoc(TL.getNameLoc());
5285
5286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005287}
5288
5289template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005290QualType TreeTransform<Derived>::TransformUnaryTransformType(
5291 TypeLocBuilder &TLB,
5292 UnaryTransformTypeLoc TL) {
5293 QualType Result = TL.getType();
5294 if (Result->isDependentType()) {
5295 const UnaryTransformType *T = TL.getTypePtr();
5296 QualType NewBase =
5297 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5298 Result = getDerived().RebuildUnaryTransformType(NewBase,
5299 T->getUTTKind(),
5300 TL.getKWLoc());
5301 if (Result.isNull())
5302 return QualType();
5303 }
5304
5305 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5306 NewTL.setKWLoc(TL.getKWLoc());
5307 NewTL.setParensRange(TL.getParensRange());
5308 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5309 return Result;
5310}
5311
5312template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005313QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5314 AutoTypeLoc TL) {
5315 const AutoType *T = TL.getTypePtr();
5316 QualType OldDeduced = T->getDeducedType();
5317 QualType NewDeduced;
5318 if (!OldDeduced.isNull()) {
5319 NewDeduced = getDerived().TransformType(OldDeduced);
5320 if (NewDeduced.isNull())
5321 return QualType();
5322 }
5323
5324 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005325 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5326 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005327 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005328 if (Result.isNull())
5329 return QualType();
5330 }
5331
5332 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5333 NewTL.setNameLoc(TL.getNameLoc());
5334
5335 return Result;
5336}
5337
5338template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005339QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005340 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005341 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005342 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005343 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5344 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005345 if (!Record)
5346 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall550e0c22009-10-21 00:40:46 +00005348 QualType Result = TL.getType();
5349 if (getDerived().AlwaysRebuild() ||
5350 Record != T->getDecl()) {
5351 Result = getDerived().RebuildRecordType(Record);
5352 if (Result.isNull())
5353 return QualType();
5354 }
Mike Stump11289f42009-09-09 15:08:12 +00005355
John McCall550e0c22009-10-21 00:40:46 +00005356 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5357 NewTL.setNameLoc(TL.getNameLoc());
5358
5359 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
5362template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005363QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005364 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005365 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005366 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005367 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5368 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005369 if (!Enum)
5370 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005371
John McCall550e0c22009-10-21 00:40:46 +00005372 QualType Result = TL.getType();
5373 if (getDerived().AlwaysRebuild() ||
5374 Enum != T->getDecl()) {
5375 Result = getDerived().RebuildEnumType(Enum);
5376 if (Result.isNull())
5377 return QualType();
5378 }
Mike Stump11289f42009-09-09 15:08:12 +00005379
John McCall550e0c22009-10-21 00:40:46 +00005380 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5381 NewTL.setNameLoc(TL.getNameLoc());
5382
5383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005384}
John McCallfcc33b02009-09-05 00:15:47 +00005385
John McCalle78aac42010-03-10 03:28:59 +00005386template<typename Derived>
5387QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5388 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005389 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005390 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5391 TL.getTypePtr()->getDecl());
5392 if (!D) return QualType();
5393
5394 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5395 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5396 return T;
5397}
5398
Douglas Gregord6ff3322009-08-04 16:50:30 +00005399template<typename Derived>
5400QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005401 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005402 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005403 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005404}
5405
Mike Stump11289f42009-09-09 15:08:12 +00005406template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005407QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005408 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005409 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005410 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005411
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005412 // Substitute into the replacement type, which itself might involve something
5413 // that needs to be transformed. This only tends to occur with default
5414 // template arguments of template template parameters.
5415 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5416 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5417 if (Replacement.isNull())
5418 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005419
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005420 // Always canonicalize the replacement type.
5421 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5422 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005423 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005424 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005425
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005426 // Propagate type-source information.
5427 SubstTemplateTypeParmTypeLoc NewTL
5428 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5429 NewTL.setNameLoc(TL.getNameLoc());
5430 return Result;
5431
John McCallcebee162009-10-18 09:09:24 +00005432}
5433
5434template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005435QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5436 TypeLocBuilder &TLB,
5437 SubstTemplateTypeParmPackTypeLoc TL) {
5438 return TransformTypeSpecType(TLB, TL);
5439}
5440
5441template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005442QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005443 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005444 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005445 const TemplateSpecializationType *T = TL.getTypePtr();
5446
Douglas Gregordf846d12011-03-02 18:46:51 +00005447 // The nested-name-specifier never matters in a TemplateSpecializationType,
5448 // because we can't have a dependent nested-name-specifier anyway.
5449 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005450 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005451 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5452 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005453 if (Template.isNull())
5454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005455
John McCall31f82722010-11-12 08:19:04 +00005456 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5457}
5458
Eli Friedman0dfb8892011-10-06 23:00:33 +00005459template<typename Derived>
5460QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5461 AtomicTypeLoc TL) {
5462 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5463 if (ValueType.isNull())
5464 return QualType();
5465
5466 QualType Result = TL.getType();
5467 if (getDerived().AlwaysRebuild() ||
5468 ValueType != TL.getValueLoc().getType()) {
5469 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5470 if (Result.isNull())
5471 return QualType();
5472 }
5473
5474 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5475 NewTL.setKWLoc(TL.getKWLoc());
5476 NewTL.setLParenLoc(TL.getLParenLoc());
5477 NewTL.setRParenLoc(TL.getRParenLoc());
5478
5479 return Result;
5480}
5481
Xiuli Pan9c14e282016-01-09 12:53:17 +00005482template <typename Derived>
5483QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5484 PipeTypeLoc TL) {
5485 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5486 if (ValueType.isNull())
5487 return QualType();
5488
5489 QualType Result = TL.getType();
5490 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005491 const PipeType *PT = Result->getAs<PipeType>();
5492 bool isReadPipe = PT->isReadOnly();
5493 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005494 if (Result.isNull())
5495 return QualType();
5496 }
5497
5498 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5499 NewTL.setKWLoc(TL.getKWLoc());
5500
5501 return Result;
5502}
5503
Chad Rosier1dcde962012-08-08 18:46:20 +00005504 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005505 /// container that provides a \c getArgLoc() member function.
5506 ///
5507 /// This iterator is intended to be used with the iterator form of
5508 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5509 template<typename ArgLocContainer>
5510 class TemplateArgumentLocContainerIterator {
5511 ArgLocContainer *Container;
5512 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005513
Douglas Gregorfe921a72010-12-20 23:36:19 +00005514 public:
5515 typedef TemplateArgumentLoc value_type;
5516 typedef TemplateArgumentLoc reference;
5517 typedef int difference_type;
5518 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005519
Douglas Gregorfe921a72010-12-20 23:36:19 +00005520 class pointer {
5521 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005522
Douglas Gregorfe921a72010-12-20 23:36:19 +00005523 public:
5524 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005525
Douglas Gregorfe921a72010-12-20 23:36:19 +00005526 const TemplateArgumentLoc *operator->() const {
5527 return &Arg;
5528 }
5529 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005530
5531
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005532 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005533
Douglas Gregorfe921a72010-12-20 23:36:19 +00005534 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5535 unsigned Index)
5536 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005537
Douglas Gregorfe921a72010-12-20 23:36:19 +00005538 TemplateArgumentLocContainerIterator &operator++() {
5539 ++Index;
5540 return *this;
5541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005542
Douglas Gregorfe921a72010-12-20 23:36:19 +00005543 TemplateArgumentLocContainerIterator operator++(int) {
5544 TemplateArgumentLocContainerIterator Old(*this);
5545 ++(*this);
5546 return Old;
5547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005548
Douglas Gregorfe921a72010-12-20 23:36:19 +00005549 TemplateArgumentLoc operator*() const {
5550 return Container->getArgLoc(Index);
5551 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005552
Douglas Gregorfe921a72010-12-20 23:36:19 +00005553 pointer operator->() const {
5554 return pointer(Container->getArgLoc(Index));
5555 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005556
Douglas Gregorfe921a72010-12-20 23:36:19 +00005557 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005558 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005559 return X.Container == Y.Container && X.Index == Y.Index;
5560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005561
Douglas Gregorfe921a72010-12-20 23:36:19 +00005562 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005563 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005564 return !(X == Y);
5565 }
5566 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005567
5568
John McCall31f82722010-11-12 08:19:04 +00005569template <typename Derived>
5570QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5571 TypeLocBuilder &TLB,
5572 TemplateSpecializationTypeLoc TL,
5573 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005574 TemplateArgumentListInfo NewTemplateArgs;
5575 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5576 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005577 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5578 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005579 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005580 ArgIterator(TL, TL.getNumArgs()),
5581 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005582 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005583
John McCall0ad16662009-10-29 08:12:44 +00005584 // FIXME: maybe don't rebuild if all the template arguments are the same.
5585
5586 QualType Result =
5587 getDerived().RebuildTemplateSpecializationType(Template,
5588 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005589 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005590
5591 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005592 // Specializations of template template parameters are represented as
5593 // TemplateSpecializationTypes, and substitution of type alias templates
5594 // within a dependent context can transform them into
5595 // DependentTemplateSpecializationTypes.
5596 if (isa<DependentTemplateSpecializationType>(Result)) {
5597 DependentTemplateSpecializationTypeLoc NewTL
5598 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005599 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005600 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005601 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005602 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005603 NewTL.setLAngleLoc(TL.getLAngleLoc());
5604 NewTL.setRAngleLoc(TL.getRAngleLoc());
5605 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5606 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5607 return Result;
5608 }
5609
John McCall0ad16662009-10-29 08:12:44 +00005610 TemplateSpecializationTypeLoc NewTL
5611 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005612 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005613 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5614 NewTL.setLAngleLoc(TL.getLAngleLoc());
5615 NewTL.setRAngleLoc(TL.getRAngleLoc());
5616 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5617 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618 }
Mike Stump11289f42009-09-09 15:08:12 +00005619
John McCall0ad16662009-10-29 08:12:44 +00005620 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005621}
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregor5a064722011-02-28 17:23:35 +00005623template <typename Derived>
5624QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5625 TypeLocBuilder &TLB,
5626 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005627 TemplateName Template,
5628 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005629 TemplateArgumentListInfo NewTemplateArgs;
5630 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5631 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5632 typedef TemplateArgumentLocContainerIterator<
5633 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005634 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005635 ArgIterator(TL, TL.getNumArgs()),
5636 NewTemplateArgs))
5637 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005638
Douglas Gregor5a064722011-02-28 17:23:35 +00005639 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005640
Douglas Gregor5a064722011-02-28 17:23:35 +00005641 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5642 QualType Result
5643 = getSema().Context.getDependentTemplateSpecializationType(
5644 TL.getTypePtr()->getKeyword(),
5645 DTN->getQualifier(),
5646 DTN->getIdentifier(),
5647 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005648
Douglas Gregor5a064722011-02-28 17:23:35 +00005649 DependentTemplateSpecializationTypeLoc NewTL
5650 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005651 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005652 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005653 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005654 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005655 NewTL.setLAngleLoc(TL.getLAngleLoc());
5656 NewTL.setRAngleLoc(TL.getRAngleLoc());
5657 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5658 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5659 return Result;
5660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005661
5662 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005663 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005664 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005665 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005666
Douglas Gregor5a064722011-02-28 17:23:35 +00005667 if (!Result.isNull()) {
5668 /// FIXME: Wrap this in an elaborated-type-specifier?
5669 TemplateSpecializationTypeLoc NewTL
5670 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005671 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005672 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005673 NewTL.setLAngleLoc(TL.getLAngleLoc());
5674 NewTL.setRAngleLoc(TL.getRAngleLoc());
5675 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5676 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5677 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005678
Douglas Gregor5a064722011-02-28 17:23:35 +00005679 return Result;
5680}
5681
Mike Stump11289f42009-09-09 15:08:12 +00005682template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005683QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005684TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005685 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005686 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005687
Douglas Gregor844cb502011-03-01 18:12:44 +00005688 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005689 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005690 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005691 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005692 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5693 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005694 return QualType();
5695 }
Mike Stump11289f42009-09-09 15:08:12 +00005696
John McCall31f82722010-11-12 08:19:04 +00005697 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5698 if (NamedT.isNull())
5699 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005700
Richard Smith3f1b5d02011-05-05 21:57:07 +00005701 // C++0x [dcl.type.elab]p2:
5702 // If the identifier resolves to a typedef-name or the simple-template-id
5703 // resolves to an alias template specialization, the
5704 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005705 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5706 if (const TemplateSpecializationType *TST =
5707 NamedT->getAs<TemplateSpecializationType>()) {
5708 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005709 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5710 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005711 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005712 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005713 << TAT << Sema::NTK_TypeAliasTemplate
5714 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005715 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5716 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005717 }
5718 }
5719
John McCall550e0c22009-10-21 00:40:46 +00005720 QualType Result = TL.getType();
5721 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005722 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005723 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005724 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005725 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005726 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005727 if (Result.isNull())
5728 return QualType();
5729 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005730
Abramo Bagnara6150c882010-05-11 21:36:43 +00005731 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005732 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005733 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005734 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005735}
Mike Stump11289f42009-09-09 15:08:12 +00005736
5737template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005738QualType TreeTransform<Derived>::TransformAttributedType(
5739 TypeLocBuilder &TLB,
5740 AttributedTypeLoc TL) {
5741 const AttributedType *oldType = TL.getTypePtr();
5742 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5743 if (modifiedType.isNull())
5744 return QualType();
5745
5746 QualType result = TL.getType();
5747
5748 // FIXME: dependent operand expressions?
5749 if (getDerived().AlwaysRebuild() ||
5750 modifiedType != oldType->getModifiedType()) {
5751 // TODO: this is really lame; we should really be rebuilding the
5752 // equivalent type from first principles.
5753 QualType equivalentType
5754 = getDerived().TransformType(oldType->getEquivalentType());
5755 if (equivalentType.isNull())
5756 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005757
5758 // Check whether we can add nullability; it is only represented as
5759 // type sugar, and therefore cannot be diagnosed in any other way.
5760 if (auto nullability = oldType->getImmediateNullability()) {
5761 if (!modifiedType->canHaveNullability()) {
5762 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005763 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005764 return QualType();
5765 }
5766 }
5767
John McCall81904512011-01-06 01:58:22 +00005768 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5769 modifiedType,
5770 equivalentType);
5771 }
5772
5773 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5774 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5775 if (TL.hasAttrOperand())
5776 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5777 if (TL.hasAttrExprOperand())
5778 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5779 else if (TL.hasAttrEnumOperand())
5780 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5781
5782 return result;
5783}
5784
5785template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005786QualType
5787TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5788 ParenTypeLoc TL) {
5789 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5790 if (Inner.isNull())
5791 return QualType();
5792
5793 QualType Result = TL.getType();
5794 if (getDerived().AlwaysRebuild() ||
5795 Inner != TL.getInnerLoc().getType()) {
5796 Result = getDerived().RebuildParenType(Inner);
5797 if (Result.isNull())
5798 return QualType();
5799 }
5800
5801 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5802 NewTL.setLParenLoc(TL.getLParenLoc());
5803 NewTL.setRParenLoc(TL.getRParenLoc());
5804 return Result;
5805}
5806
5807template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005808QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005809 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005810 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005811
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005812 NestedNameSpecifierLoc QualifierLoc
5813 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5814 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005815 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005816
John McCallc392f372010-06-11 00:33:02 +00005817 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005818 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005819 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005820 QualifierLoc,
5821 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005822 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005823 if (Result.isNull())
5824 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005825
Abramo Bagnarad7548482010-05-19 21:37:53 +00005826 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5827 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005828 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5829
Abramo Bagnarad7548482010-05-19 21:37:53 +00005830 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005831 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005832 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005833 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005834 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005835 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005836 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005837 NewTL.setNameLoc(TL.getNameLoc());
5838 }
John McCall550e0c22009-10-21 00:40:46 +00005839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005840}
Mike Stump11289f42009-09-09 15:08:12 +00005841
Douglas Gregord6ff3322009-08-04 16:50:30 +00005842template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005843QualType TreeTransform<Derived>::
5844 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005845 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005846 NestedNameSpecifierLoc QualifierLoc;
5847 if (TL.getQualifierLoc()) {
5848 QualifierLoc
5849 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5850 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005851 return QualType();
5852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005853
John McCall31f82722010-11-12 08:19:04 +00005854 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005855 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005856}
5857
5858template<typename Derived>
5859QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005860TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5861 DependentTemplateSpecializationTypeLoc TL,
5862 NestedNameSpecifierLoc QualifierLoc) {
5863 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005864
Douglas Gregora7a795b2011-03-01 20:11:18 +00005865 TemplateArgumentListInfo NewTemplateArgs;
5866 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5867 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005868
Douglas Gregora7a795b2011-03-01 20:11:18 +00005869 typedef TemplateArgumentLocContainerIterator<
5870 DependentTemplateSpecializationTypeLoc> ArgIterator;
5871 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5872 ArgIterator(TL, TL.getNumArgs()),
5873 NewTemplateArgs))
5874 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005875
Douglas Gregora7a795b2011-03-01 20:11:18 +00005876 QualType Result
5877 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5878 QualifierLoc,
5879 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005880 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005881 NewTemplateArgs);
5882 if (Result.isNull())
5883 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005884
Douglas Gregora7a795b2011-03-01 20:11:18 +00005885 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5886 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
Douglas Gregora7a795b2011-03-01 20:11:18 +00005888 // Copy information relevant to the template specialization.
5889 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005890 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005891 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005892 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005893 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5894 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005895 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005896 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005897
Douglas Gregora7a795b2011-03-01 20:11:18 +00005898 // Copy information relevant to the elaborated type.
5899 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005900 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005901 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005902 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5903 DependentTemplateSpecializationTypeLoc SpecTL
5904 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005905 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005906 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005907 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005908 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005909 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5910 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005911 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005912 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005913 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005914 TemplateSpecializationTypeLoc SpecTL
5915 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005916 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005917 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005918 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5919 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005920 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005921 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005922 }
5923 return Result;
5924}
5925
5926template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005927QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5928 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005929 QualType Pattern
5930 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005931 if (Pattern.isNull())
5932 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005933
5934 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005935 if (getDerived().AlwaysRebuild() ||
5936 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005937 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005938 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005939 TL.getEllipsisLoc(),
5940 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005941 if (Result.isNull())
5942 return QualType();
5943 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005944
Douglas Gregor822d0302011-01-12 17:07:58 +00005945 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5946 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5947 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005948}
5949
5950template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005951QualType
5952TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005953 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005954 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005955 TLB.pushFullCopy(TL);
5956 return TL.getType();
5957}
5958
5959template<typename Derived>
5960QualType
Manman Rene6be26c2016-09-13 17:25:08 +00005961TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
5962 ObjCTypeParamTypeLoc TL) {
5963 const ObjCTypeParamType *T = TL.getTypePtr();
5964 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
5965 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
5966 if (!OTP)
5967 return QualType();
5968
5969 QualType Result = TL.getType();
5970 if (getDerived().AlwaysRebuild() ||
5971 OTP != T->getDecl()) {
5972 Result = getDerived().RebuildObjCTypeParamType(OTP,
5973 TL.getProtocolLAngleLoc(),
5974 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5975 TL.getNumProtocols()),
5976 TL.getProtocolLocs(),
5977 TL.getProtocolRAngleLoc());
5978 if (Result.isNull())
5979 return QualType();
5980 }
5981
5982 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
5983 if (TL.getNumProtocols()) {
5984 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5985 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5986 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
5987 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5988 }
5989 return Result;
5990}
5991
5992template<typename Derived>
5993QualType
John McCall8b07ec22010-05-15 11:32:37 +00005994TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005995 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005996 // Transform base type.
5997 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5998 if (BaseType.isNull())
5999 return QualType();
6000
6001 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6002
6003 // Transform type arguments.
6004 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6005 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6006 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6007 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6008 QualType TypeArg = TypeArgInfo->getType();
6009 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6010 AnyChanged = true;
6011
6012 // We have a pack expansion. Instantiate it.
6013 const auto *PackExpansion = PackExpansionLoc.getType()
6014 ->castAs<PackExpansionType>();
6015 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6016 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6017 Unexpanded);
6018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6019
6020 // Determine whether the set of unexpanded parameter packs can
6021 // and should be expanded.
6022 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6023 bool Expand = false;
6024 bool RetainExpansion = false;
6025 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6026 if (getDerived().TryExpandParameterPacks(
6027 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6028 Unexpanded, Expand, RetainExpansion, NumExpansions))
6029 return QualType();
6030
6031 if (!Expand) {
6032 // We can't expand this pack expansion into separate arguments yet;
6033 // just substitute into the pattern and create a new pack expansion
6034 // type.
6035 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6036
6037 TypeLocBuilder TypeArgBuilder;
6038 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6039 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6040 PatternLoc);
6041 if (NewPatternType.isNull())
6042 return QualType();
6043
6044 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6045 NewPatternType, NumExpansions);
6046 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6047 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6048 NewTypeArgInfos.push_back(
6049 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6050 continue;
6051 }
6052
6053 // Substitute into the pack expansion pattern for each slice of the
6054 // pack.
6055 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6056 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6057
6058 TypeLocBuilder TypeArgBuilder;
6059 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6060
6061 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6062 PatternLoc);
6063 if (NewTypeArg.isNull())
6064 return QualType();
6065
6066 NewTypeArgInfos.push_back(
6067 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6068 }
6069
6070 continue;
6071 }
6072
6073 TypeLocBuilder TypeArgBuilder;
6074 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6075 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6076 if (NewTypeArg.isNull())
6077 return QualType();
6078
6079 // If nothing changed, just keep the old TypeSourceInfo.
6080 if (NewTypeArg == TypeArg) {
6081 NewTypeArgInfos.push_back(TypeArgInfo);
6082 continue;
6083 }
6084
6085 NewTypeArgInfos.push_back(
6086 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6087 AnyChanged = true;
6088 }
6089
6090 QualType Result = TL.getType();
6091 if (getDerived().AlwaysRebuild() || AnyChanged) {
6092 // Rebuild the type.
6093 Result = getDerived().RebuildObjCObjectType(
6094 BaseType,
6095 TL.getLocStart(),
6096 TL.getTypeArgsLAngleLoc(),
6097 NewTypeArgInfos,
6098 TL.getTypeArgsRAngleLoc(),
6099 TL.getProtocolLAngleLoc(),
6100 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6101 TL.getNumProtocols()),
6102 TL.getProtocolLocs(),
6103 TL.getProtocolRAngleLoc());
6104
6105 if (Result.isNull())
6106 return QualType();
6107 }
6108
6109 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006110 NewT.setHasBaseTypeAsWritten(true);
6111 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6112 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6113 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6114 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6115 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6116 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6117 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6118 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6119 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006120}
Mike Stump11289f42009-09-09 15:08:12 +00006121
6122template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006123QualType
6124TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006125 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006126 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6127 if (PointeeType.isNull())
6128 return QualType();
6129
6130 QualType Result = TL.getType();
6131 if (getDerived().AlwaysRebuild() ||
6132 PointeeType != TL.getPointeeLoc().getType()) {
6133 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6134 TL.getStarLoc());
6135 if (Result.isNull())
6136 return QualType();
6137 }
6138
6139 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6140 NewT.setStarLoc(TL.getStarLoc());
6141 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006142}
6143
Douglas Gregord6ff3322009-08-04 16:50:30 +00006144//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006145// Statement transformation
6146//===----------------------------------------------------------------------===//
6147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006148StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006149TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006150 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006151}
6152
6153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006155TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6156 return getDerived().TransformCompoundStmt(S, false);
6157}
6158
6159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006161TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006163 Sema::CompoundScopeRAII CompoundScope(getSema());
6164
John McCall1ababa62010-08-27 19:56:05 +00006165 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006166 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006167 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006168 for (auto *B : S->body()) {
6169 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006170 if (Result.isInvalid()) {
6171 // Immediately fail if this was a DeclStmt, since it's very
6172 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006173 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006174 return StmtError();
6175
6176 // Otherwise, just keep processing substatements and fail later.
6177 SubStmtInvalid = true;
6178 continue;
6179 }
Mike Stump11289f42009-09-09 15:08:12 +00006180
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006181 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006182 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006183 }
Mike Stump11289f42009-09-09 15:08:12 +00006184
John McCall1ababa62010-08-27 19:56:05 +00006185 if (SubStmtInvalid)
6186 return StmtError();
6187
Douglas Gregorebe10102009-08-20 07:17:43 +00006188 if (!getDerived().AlwaysRebuild() &&
6189 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006190 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006191
6192 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006193 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006194 S->getRBracLoc(),
6195 IsStmtExpr);
6196}
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregorebe10102009-08-20 07:17:43 +00006198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006200TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006201 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006202 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006203 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6204 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006205
Eli Friedman06577382009-11-19 03:14:00 +00006206 // Transform the left-hand case value.
6207 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006208 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006209 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006211
Eli Friedman06577382009-11-19 03:14:00 +00006212 // Transform the right-hand case value (for the GNU case-range extension).
6213 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006214 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006215 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006216 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006217 }
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregorebe10102009-08-20 07:17:43 +00006219 // Build the case statement.
6220 // Case statements are always rebuilt so that they will attached to their
6221 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006222 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006223 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006224 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006225 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006226 S->getColonLoc());
6227 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006228 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006229
Douglas Gregorebe10102009-08-20 07:17:43 +00006230 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006231 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregorebe10102009-08-20 07:17:43 +00006235 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006236 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006237}
6238
6239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006240StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006241TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006242 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006243 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006244 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006245 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregorebe10102009-08-20 07:17:43 +00006247 // Default statements are always rebuilt
6248 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006249 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006250}
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregorebe10102009-08-20 07:17:43 +00006252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006253StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006254TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006255 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006256 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006257 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006258
Chris Lattnercab02a62011-02-17 20:34:02 +00006259 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6260 S->getDecl());
6261 if (!LD)
6262 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006263
6264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006266 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006267 cast<LabelDecl>(LD), SourceLocation(),
6268 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006269}
Mike Stump11289f42009-09-09 15:08:12 +00006270
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006271template <typename Derived>
6272const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6273 if (!R)
6274 return R;
6275
6276 switch (R->getKind()) {
6277// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6278#define ATTR(X)
6279#define PRAGMA_SPELLING_ATTR(X) \
6280 case attr::X: \
6281 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6282#include "clang/Basic/AttrList.inc"
6283 default:
6284 return R;
6285 }
6286}
6287
6288template <typename Derived>
6289StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6290 bool AttrsChanged = false;
6291 SmallVector<const Attr *, 1> Attrs;
6292
6293 // Visit attributes and keep track if any are transformed.
6294 for (const auto *I : S->getAttrs()) {
6295 const Attr *R = getDerived().TransformAttr(I);
6296 AttrsChanged |= (I != R);
6297 Attrs.push_back(R);
6298 }
6299
Richard Smithc202b282012-04-14 00:33:13 +00006300 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6301 if (SubStmt.isInvalid())
6302 return StmtError();
6303
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006304 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006305 return S;
6306
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006307 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006308 SubStmt.get());
6309}
6310
6311template<typename Derived>
6312StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006313TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006314 // Transform the initialization statement
6315 StmtResult Init = getDerived().TransformStmt(S->getInit());
6316 if (Init.isInvalid())
6317 return StmtError();
6318
Douglas Gregorebe10102009-08-20 07:17:43 +00006319 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006320 Sema::ConditionResult Cond = getDerived().TransformCondition(
6321 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006322 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6323 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006324 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006325 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006326
Richard Smithb130fe72016-06-23 19:16:49 +00006327 // If this is a constexpr if, determine which arm we should instantiate.
6328 llvm::Optional<bool> ConstexprConditionValue;
6329 if (S->isConstexpr())
6330 ConstexprConditionValue = Cond.getKnownValue();
6331
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006333 StmtResult Then;
6334 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6335 Then = getDerived().TransformStmt(S->getThen());
6336 if (Then.isInvalid())
6337 return StmtError();
6338 } else {
6339 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6340 }
Mike Stump11289f42009-09-09 15:08:12 +00006341
Douglas Gregorebe10102009-08-20 07:17:43 +00006342 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006343 StmtResult Else;
6344 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6345 Else = getDerived().TransformStmt(S->getElse());
6346 if (Else.isInvalid())
6347 return StmtError();
6348 }
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregorebe10102009-08-20 07:17:43 +00006350 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006351 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006352 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 Then.get() == S->getThen() &&
6354 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006355 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006356
Richard Smithb130fe72016-06-23 19:16:49 +00006357 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006358 Init.get(), Then.get(), S->getElseLoc(),
6359 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006360}
6361
6362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006364TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006365 // Transform the initialization statement
6366 StmtResult Init = getDerived().TransformStmt(S->getInit());
6367 if (Init.isInvalid())
6368 return StmtError();
6369
Douglas Gregorebe10102009-08-20 07:17:43 +00006370 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006371 Sema::ConditionResult Cond = getDerived().TransformCondition(
6372 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6373 Sema::ConditionKind::Switch);
6374 if (Cond.isInvalid())
6375 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregorebe10102009-08-20 07:17:43 +00006377 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006378 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006379 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6380 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006381 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorebe10102009-08-20 07:17:43 +00006384 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006385 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006386 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006387 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregorebe10102009-08-20 07:17:43 +00006389 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006390 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6391 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006392}
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregorebe10102009-08-20 07:17:43 +00006394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006396TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006397 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006398 Sema::ConditionResult Cond = getDerived().TransformCondition(
6399 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6400 Sema::ConditionKind::Boolean);
6401 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006402 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006403
Douglas Gregorebe10102009-08-20 07:17:43 +00006404 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006405 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006406 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006407 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006408
Douglas Gregorebe10102009-08-20 07:17:43 +00006409 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006410 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006411 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006412 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006413
Richard Smith03a4aa32016-06-23 19:02:52 +00006414 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006415}
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregorebe10102009-08-20 07:17:43 +00006417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006418StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006419TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006420 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006421 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006422 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006425 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006426 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006427 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006428 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006429
Douglas Gregorebe10102009-08-20 07:17:43 +00006430 if (!getDerived().AlwaysRebuild() &&
6431 Cond.get() == S->getCond() &&
6432 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006433 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006434
John McCallb268a282010-08-23 23:25:46 +00006435 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6436 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006437 S->getRParenLoc());
6438}
Mike Stump11289f42009-09-09 15:08:12 +00006439
Douglas Gregorebe10102009-08-20 07:17:43 +00006440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006442TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006443 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006444 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006445 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006446 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006447
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006448 // In OpenMP loop region loop control variable must be captured and be
6449 // private. Perform analysis of first part (if any).
6450 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6451 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6452
Douglas Gregorebe10102009-08-20 07:17:43 +00006453 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006454 Sema::ConditionResult Cond = getDerived().TransformCondition(
6455 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6456 Sema::ConditionKind::Boolean);
6457 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006458 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006459
Douglas Gregorebe10102009-08-20 07:17:43 +00006460 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006461 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006462 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006463 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006464
Richard Smith945f8d32013-01-14 22:39:08 +00006465 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006466 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006468
Douglas Gregorebe10102009-08-20 07:17:43 +00006469 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006470 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006471 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006472 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006473
Douglas Gregorebe10102009-08-20 07:17:43 +00006474 if (!getDerived().AlwaysRebuild() &&
6475 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006476 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006477 Inc.get() == S->getInc() &&
6478 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006479 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregorebe10102009-08-20 07:17:43 +00006481 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006482 Init.get(), Cond, FullInc,
6483 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006484}
6485
6486template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006487StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006488TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006489 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6490 S->getLabel());
6491 if (!LD)
6492 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006493
Douglas Gregorebe10102009-08-20 07:17:43 +00006494 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006495 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006496 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006497}
6498
6499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006500StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006501TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006502 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006503 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006504 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006505 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006506
Douglas Gregorebe10102009-08-20 07:17:43 +00006507 if (!getDerived().AlwaysRebuild() &&
6508 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006509 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006510
6511 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006512 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006513}
6514
6515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006517TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006518 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006519}
Mike Stump11289f42009-09-09 15:08:12 +00006520
Douglas Gregorebe10102009-08-20 07:17:43 +00006521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006522StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006523TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006524 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006525}
Mike Stump11289f42009-09-09 15:08:12 +00006526
Douglas Gregorebe10102009-08-20 07:17:43 +00006527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006528StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006529TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006530 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6531 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006532 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006533 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006534
Mike Stump11289f42009-09-09 15:08:12 +00006535 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006536 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006537 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006538}
Mike Stump11289f42009-09-09 15:08:12 +00006539
Douglas Gregorebe10102009-08-20 07:17:43 +00006540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006541StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006542TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006543 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006544 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006545 for (auto *D : S->decls()) {
6546 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006547 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006549
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006550 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006551 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006552
Douglas Gregorebe10102009-08-20 07:17:43 +00006553 Decls.push_back(Transformed);
6554 }
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregorebe10102009-08-20 07:17:43 +00006556 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006557 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006558
Rafael Espindolaab417692013-07-09 12:05:01 +00006559 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006560}
Mike Stump11289f42009-09-09 15:08:12 +00006561
Douglas Gregorebe10102009-08-20 07:17:43 +00006562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006563StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006564TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006565
Benjamin Kramerf0623432012-08-23 22:51:59 +00006566 SmallVector<Expr*, 8> Constraints;
6567 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006568 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006569
John McCalldadc5752010-08-24 06:29:42 +00006570 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006571 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006572
6573 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006574
Anders Carlssonaaeef072010-01-24 05:50:09 +00006575 // Go through the outputs.
6576 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006577 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006578
Anders Carlssonaaeef072010-01-24 05:50:09 +00006579 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006580 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006581
Anders Carlssonaaeef072010-01-24 05:50:09 +00006582 // Transform the output expr.
6583 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006584 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006585 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006587
Anders Carlssonaaeef072010-01-24 05:50:09 +00006588 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006589
John McCallb268a282010-08-23 23:25:46 +00006590 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006591 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006592
Anders Carlssonaaeef072010-01-24 05:50:09 +00006593 // Go through the inputs.
6594 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006595 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006596
Anders Carlssonaaeef072010-01-24 05:50:09 +00006597 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006598 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006599
Anders Carlssonaaeef072010-01-24 05:50:09 +00006600 // Transform the input expr.
6601 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006602 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006603 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006604 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006605
Anders Carlssonaaeef072010-01-24 05:50:09 +00006606 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006607
John McCallb268a282010-08-23 23:25:46 +00006608 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006610
Anders Carlssonaaeef072010-01-24 05:50:09 +00006611 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006612 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006613
6614 // Go through the clobbers.
6615 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006616 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006617
6618 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006619 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006620 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6621 S->isVolatile(), S->getNumOutputs(),
6622 S->getNumInputs(), Names.data(),
6623 Constraints, Exprs, AsmString.get(),
6624 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006625}
6626
Chad Rosier32503022012-06-11 20:47:18 +00006627template<typename Derived>
6628StmtResult
6629TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006630 ArrayRef<Token> AsmToks =
6631 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006632
John McCallf413f5e2013-05-03 00:10:13 +00006633 bool HadError = false, HadChange = false;
6634
6635 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6636 SmallVector<Expr*, 8> TransformedExprs;
6637 TransformedExprs.reserve(SrcExprs.size());
6638 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6639 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6640 if (!Result.isUsable()) {
6641 HadError = true;
6642 } else {
6643 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006644 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006645 }
6646 }
6647
6648 if (HadError) return StmtError();
6649 if (!HadChange && !getDerived().AlwaysRebuild())
6650 return Owned(S);
6651
Chad Rosierb6f46c12012-08-15 16:53:30 +00006652 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006653 AsmToks, S->getAsmString(),
6654 S->getNumOutputs(), S->getNumInputs(),
6655 S->getAllConstraints(), S->getClobbers(),
6656 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006657}
Douglas Gregorebe10102009-08-20 07:17:43 +00006658
Richard Smith9f690bd2015-10-27 06:02:45 +00006659// C++ Coroutines TS
6660
6661template<typename Derived>
6662StmtResult
6663TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6664 // The coroutine body should be re-formed by the caller if necessary.
Eric Fiselier709d1b32016-10-27 07:30:31 +00006665 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
Richard Smith9f690bd2015-10-27 06:02:45 +00006666 return getDerived().TransformStmt(S->getBody());
6667}
6668
6669template<typename Derived>
6670StmtResult
6671TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6672 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6673 /*NotCopyInit*/false);
6674 if (Result.isInvalid())
6675 return StmtError();
6676
6677 // Always rebuild; we don't know if this needs to be injected into a new
6678 // context or if the promise type has changed.
6679 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6680}
6681
6682template<typename Derived>
6683ExprResult
6684TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6685 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6686 /*NotCopyInit*/false);
6687 if (Result.isInvalid())
6688 return ExprError();
6689
6690 // Always rebuild; we don't know if this needs to be injected into a new
6691 // context or if the promise type has changed.
6692 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6693}
6694
6695template<typename Derived>
6696ExprResult
6697TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6698 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6699 /*NotCopyInit*/false);
6700 if (Result.isInvalid())
6701 return ExprError();
6702
6703 // Always rebuild; we don't know if this needs to be injected into a new
6704 // context or if the promise type has changed.
6705 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6706}
6707
6708// Objective-C Statements.
6709
Douglas Gregorebe10102009-08-20 07:17:43 +00006710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006711StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006712TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006713 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006714 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006715 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006717
Douglas Gregor96c79492010-04-23 22:50:49 +00006718 // Transform the @catch statements (if present).
6719 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006720 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006721 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006722 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006723 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006725 if (Catch.get() != S->getCatchStmt(I))
6726 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006727 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006728 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006729
Douglas Gregor306de2f2010-04-22 23:59:56 +00006730 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006731 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006732 if (S->getFinallyStmt()) {
6733 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6734 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006735 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006736 }
6737
6738 // If nothing changed, just retain this statement.
6739 if (!getDerived().AlwaysRebuild() &&
6740 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006741 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006742 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006743 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006744
Douglas Gregor306de2f2010-04-22 23:59:56 +00006745 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006746 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006747 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006748}
Mike Stump11289f42009-09-09 15:08:12 +00006749
Douglas Gregorebe10102009-08-20 07:17:43 +00006750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006751StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006752TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006753 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006754 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006755 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006756 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006757 if (FromVar->getTypeSourceInfo()) {
6758 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6759 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006760 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006762
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006763 QualType T;
6764 if (TSInfo)
6765 T = TSInfo->getType();
6766 else {
6767 T = getDerived().TransformType(FromVar->getType());
6768 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006769 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006770 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006771
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006772 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6773 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006776
John McCalldadc5752010-08-24 06:29:42 +00006777 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006778 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006779 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
6781 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006782 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006783 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006784}
Mike Stump11289f42009-09-09 15:08:12 +00006785
Douglas Gregorebe10102009-08-20 07:17:43 +00006786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006787StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006788TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006789 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006790 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006791 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006792 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006793
Douglas Gregor306de2f2010-04-22 23:59:56 +00006794 // If nothing changed, just retain this statement.
6795 if (!getDerived().AlwaysRebuild() &&
6796 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006797 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006798
6799 // Build a new statement.
6800 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006801 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006802}
Mike Stump11289f42009-09-09 15:08:12 +00006803
Douglas Gregorebe10102009-08-20 07:17:43 +00006804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006805StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006806TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006807 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006808 if (S->getThrowExpr()) {
6809 Operand = getDerived().TransformExpr(S->getThrowExpr());
6810 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006811 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006813
Douglas Gregor2900c162010-04-22 21:44:01 +00006814 if (!getDerived().AlwaysRebuild() &&
6815 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006816 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006817
John McCallb268a282010-08-23 23:25:46 +00006818 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006819}
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregorebe10102009-08-20 07:17:43 +00006821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006822StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006823TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006824 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006825 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006826 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006827 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006829 Object =
6830 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6831 Object.get());
6832 if (Object.isInvalid())
6833 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006834
Douglas Gregor6148de72010-04-22 22:01:21 +00006835 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006836 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006837 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006838 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006839
Douglas Gregor6148de72010-04-22 22:01:21 +00006840 // If nothing change, just retain the current statement.
6841 if (!getDerived().AlwaysRebuild() &&
6842 Object.get() == S->getSynchExpr() &&
6843 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006844 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006845
6846 // Build a new statement.
6847 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006848 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006849}
6850
6851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006852StmtResult
John McCall31168b02011-06-15 23:02:42 +00006853TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6854 ObjCAutoreleasePoolStmt *S) {
6855 // Transform the body.
6856 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6857 if (Body.isInvalid())
6858 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006859
John McCall31168b02011-06-15 23:02:42 +00006860 // If nothing changed, just retain this statement.
6861 if (!getDerived().AlwaysRebuild() &&
6862 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006863 return S;
John McCall31168b02011-06-15 23:02:42 +00006864
6865 // Build a new statement.
6866 return getDerived().RebuildObjCAutoreleasePoolStmt(
6867 S->getAtLoc(), Body.get());
6868}
6869
6870template<typename Derived>
6871StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006872TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006873 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006874 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006875 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006876 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006878
Douglas Gregorf68a5082010-04-22 23:10:45 +00006879 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006880 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006881 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006882 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006883
Douglas Gregorf68a5082010-04-22 23:10:45 +00006884 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006885 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006886 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006888
Douglas Gregorf68a5082010-04-22 23:10:45 +00006889 // If nothing changed, just retain this statement.
6890 if (!getDerived().AlwaysRebuild() &&
6891 Element.get() == S->getElement() &&
6892 Collection.get() == S->getCollection() &&
6893 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006894 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006895
Douglas Gregorf68a5082010-04-22 23:10:45 +00006896 // Build a new statement.
6897 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006898 Element.get(),
6899 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006900 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006901 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006902}
6903
David Majnemer5f7efef2013-10-15 09:50:08 +00006904template <typename Derived>
6905StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006906 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006907 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006908 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6909 TypeSourceInfo *T =
6910 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006911 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006912 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006913
David Majnemer5f7efef2013-10-15 09:50:08 +00006914 Var = getDerived().RebuildExceptionDecl(
6915 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6916 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006917 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006919 }
Mike Stump11289f42009-09-09 15:08:12 +00006920
Douglas Gregorebe10102009-08-20 07:17:43 +00006921 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006922 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006923 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006924 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006925
David Majnemer5f7efef2013-10-15 09:50:08 +00006926 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006927 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006928 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006929
David Majnemer5f7efef2013-10-15 09:50:08 +00006930 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006931}
Mike Stump11289f42009-09-09 15:08:12 +00006932
David Majnemer5f7efef2013-10-15 09:50:08 +00006933template <typename Derived>
6934StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006935 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006936 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006937 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006938 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregorebe10102009-08-20 07:17:43 +00006940 // Transform the handlers.
6941 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006942 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006943 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006944 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006945 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006946 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregorebe10102009-08-20 07:17:43 +00006948 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006949 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006950 }
Mike Stump11289f42009-09-09 15:08:12 +00006951
David Majnemer5f7efef2013-10-15 09:50:08 +00006952 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006953 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006954 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006955
John McCallb268a282010-08-23 23:25:46 +00006956 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006957 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006958}
Mike Stump11289f42009-09-09 15:08:12 +00006959
Richard Smith02e85f32011-04-14 22:09:26 +00006960template<typename Derived>
6961StmtResult
6962TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6963 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6964 if (Range.isInvalid())
6965 return StmtError();
6966
Richard Smith01694c32016-03-20 10:33:40 +00006967 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
6968 if (Begin.isInvalid())
6969 return StmtError();
6970 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
6971 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00006972 return StmtError();
6973
6974 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6975 if (Cond.isInvalid())
6976 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006977 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00006978 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00006979 if (Cond.isInvalid())
6980 return StmtError();
6981 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006982 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006983
6984 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6985 if (Inc.isInvalid())
6986 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006987 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006988 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006989
6990 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6991 if (LoopVar.isInvalid())
6992 return StmtError();
6993
6994 StmtResult NewStmt = S;
6995 if (getDerived().AlwaysRebuild() ||
6996 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00006997 Begin.get() != S->getBeginStmt() ||
6998 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00006999 Cond.get() != S->getCond() ||
7000 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007001 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007002 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007003 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007004 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007005 Begin.get(), End.get(),
7006 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007007 Inc.get(), LoopVar.get(),
7008 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007009 if (NewStmt.isInvalid())
7010 return StmtError();
7011 }
Richard Smith02e85f32011-04-14 22:09:26 +00007012
7013 StmtResult Body = getDerived().TransformStmt(S->getBody());
7014 if (Body.isInvalid())
7015 return StmtError();
7016
7017 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7018 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007019 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007020 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007021 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007022 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007023 Begin.get(), End.get(),
7024 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007025 Inc.get(), LoopVar.get(),
7026 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007027 if (NewStmt.isInvalid())
7028 return StmtError();
7029 }
Richard Smith02e85f32011-04-14 22:09:26 +00007030
7031 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007032 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007033
7034 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7035}
7036
John Wiegley1c0675e2011-04-28 01:08:34 +00007037template<typename Derived>
7038StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007039TreeTransform<Derived>::TransformMSDependentExistsStmt(
7040 MSDependentExistsStmt *S) {
7041 // Transform the nested-name-specifier, if any.
7042 NestedNameSpecifierLoc QualifierLoc;
7043 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007044 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007045 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7046 if (!QualifierLoc)
7047 return StmtError();
7048 }
7049
7050 // Transform the declaration name.
7051 DeclarationNameInfo NameInfo = S->getNameInfo();
7052 if (NameInfo.getName()) {
7053 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7054 if (!NameInfo.getName())
7055 return StmtError();
7056 }
7057
7058 // Check whether anything changed.
7059 if (!getDerived().AlwaysRebuild() &&
7060 QualifierLoc == S->getQualifierLoc() &&
7061 NameInfo.getName() == S->getNameInfo().getName())
7062 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007063
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007064 // Determine whether this name exists, if we can.
7065 CXXScopeSpec SS;
7066 SS.Adopt(QualifierLoc);
7067 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007068 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007069 case Sema::IER_Exists:
7070 if (S->isIfExists())
7071 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007072
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007073 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7074
7075 case Sema::IER_DoesNotExist:
7076 if (S->isIfNotExists())
7077 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007078
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007079 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007080
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007081 case Sema::IER_Dependent:
7082 Dependent = true;
7083 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007085 case Sema::IER_Error:
7086 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007088
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007089 // We need to continue with the instantiation, so do so now.
7090 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7091 if (SubStmt.isInvalid())
7092 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007093
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007094 // If we have resolved the name, just transform to the substatement.
7095 if (!Dependent)
7096 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007097
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007098 // The name is still dependent, so build a dependent expression again.
7099 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7100 S->isIfExists(),
7101 QualifierLoc,
7102 NameInfo,
7103 SubStmt.get());
7104}
7105
7106template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007107ExprResult
7108TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7109 NestedNameSpecifierLoc QualifierLoc;
7110 if (E->getQualifierLoc()) {
7111 QualifierLoc
7112 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7113 if (!QualifierLoc)
7114 return ExprError();
7115 }
7116
7117 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7118 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7119 if (!PD)
7120 return ExprError();
7121
7122 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7123 if (Base.isInvalid())
7124 return ExprError();
7125
7126 return new (SemaRef.getASTContext())
7127 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7128 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7129 QualifierLoc, E->getMemberLoc());
7130}
7131
David Majnemerfad8f482013-10-15 09:33:02 +00007132template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007133ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7134 MSPropertySubscriptExpr *E) {
7135 auto BaseRes = getDerived().TransformExpr(E->getBase());
7136 if (BaseRes.isInvalid())
7137 return ExprError();
7138 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7139 if (IdxRes.isInvalid())
7140 return ExprError();
7141
7142 if (!getDerived().AlwaysRebuild() &&
7143 BaseRes.get() == E->getBase() &&
7144 IdxRes.get() == E->getIdx())
7145 return E;
7146
7147 return getDerived().RebuildArraySubscriptExpr(
7148 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7149}
7150
7151template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007152StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007153 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007154 if (TryBlock.isInvalid())
7155 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007156
7157 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007158 if (Handler.isInvalid())
7159 return StmtError();
7160
David Majnemerfad8f482013-10-15 09:33:02 +00007161 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7162 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007163 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007164
Warren Huntf6be4cb2014-07-25 20:52:51 +00007165 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7166 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007167}
7168
David Majnemerfad8f482013-10-15 09:33:02 +00007169template <typename Derived>
7170StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007171 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007172 if (Block.isInvalid())
7173 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007174
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007175 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007176}
7177
David Majnemerfad8f482013-10-15 09:33:02 +00007178template <typename Derived>
7179StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007180 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007181 if (FilterExpr.isInvalid())
7182 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007183
David Majnemer7e755502013-10-15 09:30:14 +00007184 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007185 if (Block.isInvalid())
7186 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007187
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007188 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7189 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007190}
7191
David Majnemerfad8f482013-10-15 09:33:02 +00007192template <typename Derived>
7193StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7194 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007195 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7196 else
7197 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7198}
7199
Nico Weber9b982072014-07-07 00:12:30 +00007200template<typename Derived>
7201StmtResult
7202TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7203 return S;
7204}
7205
Alexander Musman64d33f12014-06-04 07:53:32 +00007206//===----------------------------------------------------------------------===//
7207// OpenMP directive transformation
7208//===----------------------------------------------------------------------===//
7209template <typename Derived>
7210StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7211 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007212
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007213 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007214 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007215 ArrayRef<OMPClause *> Clauses = D->clauses();
7216 TClauses.reserve(Clauses.size());
7217 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7218 I != E; ++I) {
7219 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007220 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007221 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007222 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007223 if (Clause)
7224 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007225 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007226 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007227 }
7228 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007229 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007230 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007231 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7232 /*CurScope=*/nullptr);
7233 StmtResult Body;
7234 {
7235 Sema::CompoundScopeRAII CompoundScope(getSema());
7236 Body = getDerived().TransformStmt(
7237 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
7238 }
7239 AssociatedStmt =
7240 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007241 if (AssociatedStmt.isInvalid()) {
7242 return StmtError();
7243 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007244 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007245 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007246 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007247 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007248
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007249 // Transform directive name for 'omp critical' directive.
7250 DeclarationNameInfo DirName;
7251 if (D->getDirectiveKind() == OMPD_critical) {
7252 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7253 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7254 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007255 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7256 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7257 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007258 } else if (D->getDirectiveKind() == OMPD_cancel) {
7259 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007260 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007261
Alexander Musman64d33f12014-06-04 07:53:32 +00007262 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007263 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7264 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007265}
7266
Alexander Musman64d33f12014-06-04 07:53:32 +00007267template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007268StmtResult
7269TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7270 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007271 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7272 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007273 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7274 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7275 return Res;
7276}
7277
Alexander Musman64d33f12014-06-04 07:53:32 +00007278template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007279StmtResult
7280TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7281 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007282 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7283 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007284 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7285 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007286 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007287}
7288
Alexey Bataevf29276e2014-06-18 04:14:57 +00007289template <typename Derived>
7290StmtResult
7291TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7292 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007293 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7294 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007295 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7296 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7297 return Res;
7298}
7299
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007300template <typename Derived>
7301StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007302TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7303 DeclarationNameInfo DirName;
7304 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7305 D->getLocStart());
7306 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7307 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7308 return Res;
7309}
7310
7311template <typename Derived>
7312StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007313TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7314 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007315 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7316 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007317 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7318 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7319 return Res;
7320}
7321
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007322template <typename Derived>
7323StmtResult
7324TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7325 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007326 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7327 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007328 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7329 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7330 return Res;
7331}
7332
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007333template <typename Derived>
7334StmtResult
7335TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7336 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007337 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7338 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007339 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7340 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7341 return Res;
7342}
7343
Alexey Bataev4acb8592014-07-07 13:01:15 +00007344template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007345StmtResult
7346TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7347 DeclarationNameInfo DirName;
7348 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7349 D->getLocStart());
7350 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7351 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7352 return Res;
7353}
7354
7355template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007356StmtResult
7357TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7358 getDerived().getSema().StartOpenMPDSABlock(
7359 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7360 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7361 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7362 return Res;
7363}
7364
7365template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007366StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7367 OMPParallelForDirective *D) {
7368 DeclarationNameInfo DirName;
7369 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7370 nullptr, D->getLocStart());
7371 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7372 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7373 return Res;
7374}
7375
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007376template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007377StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7378 OMPParallelForSimdDirective *D) {
7379 DeclarationNameInfo DirName;
7380 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7381 nullptr, D->getLocStart());
7382 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7383 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7384 return Res;
7385}
7386
7387template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007388StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7389 OMPParallelSectionsDirective *D) {
7390 DeclarationNameInfo DirName;
7391 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7392 nullptr, D->getLocStart());
7393 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7394 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7395 return Res;
7396}
7397
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007398template <typename Derived>
7399StmtResult
7400TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7401 DeclarationNameInfo DirName;
7402 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7403 D->getLocStart());
7404 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7405 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7406 return Res;
7407}
7408
Alexey Bataev68446b72014-07-18 07:47:19 +00007409template <typename Derived>
7410StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7411 OMPTaskyieldDirective *D) {
7412 DeclarationNameInfo DirName;
7413 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7414 D->getLocStart());
7415 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7416 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7417 return Res;
7418}
7419
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007420template <typename Derived>
7421StmtResult
7422TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7423 DeclarationNameInfo DirName;
7424 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7425 D->getLocStart());
7426 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7427 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7428 return Res;
7429}
7430
Alexey Bataev2df347a2014-07-18 10:17:07 +00007431template <typename Derived>
7432StmtResult
7433TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7434 DeclarationNameInfo DirName;
7435 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7436 D->getLocStart());
7437 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7438 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7439 return Res;
7440}
7441
Alexey Bataev6125da92014-07-21 11:26:11 +00007442template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007443StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7444 OMPTaskgroupDirective *D) {
7445 DeclarationNameInfo DirName;
7446 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7447 D->getLocStart());
7448 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7449 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7450 return Res;
7451}
7452
7453template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007454StmtResult
7455TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7456 DeclarationNameInfo DirName;
7457 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7458 D->getLocStart());
7459 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7460 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7461 return Res;
7462}
7463
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007464template <typename Derived>
7465StmtResult
7466TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7467 DeclarationNameInfo DirName;
7468 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7469 D->getLocStart());
7470 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7471 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7472 return Res;
7473}
7474
Alexey Bataev0162e452014-07-22 10:10:35 +00007475template <typename Derived>
7476StmtResult
7477TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7478 DeclarationNameInfo DirName;
7479 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7480 D->getLocStart());
7481 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7482 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7483 return Res;
7484}
7485
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007486template <typename Derived>
7487StmtResult
7488TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7489 DeclarationNameInfo DirName;
7490 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7491 D->getLocStart());
7492 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7493 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7494 return Res;
7495}
7496
Alexey Bataev13314bf2014-10-09 04:18:56 +00007497template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007498StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7499 OMPTargetDataDirective *D) {
7500 DeclarationNameInfo DirName;
7501 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7502 D->getLocStart());
7503 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7504 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7505 return Res;
7506}
7507
7508template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007509StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7510 OMPTargetEnterDataDirective *D) {
7511 DeclarationNameInfo DirName;
7512 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7513 nullptr, D->getLocStart());
7514 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7515 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7516 return Res;
7517}
7518
7519template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007520StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7521 OMPTargetExitDataDirective *D) {
7522 DeclarationNameInfo DirName;
7523 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7524 nullptr, D->getLocStart());
7525 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7526 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7527 return Res;
7528}
7529
7530template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007531StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7532 OMPTargetParallelDirective *D) {
7533 DeclarationNameInfo DirName;
7534 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7535 nullptr, D->getLocStart());
7536 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7537 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7538 return Res;
7539}
7540
7541template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007542StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7543 OMPTargetParallelForDirective *D) {
7544 DeclarationNameInfo DirName;
7545 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7546 nullptr, D->getLocStart());
7547 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7548 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7549 return Res;
7550}
7551
7552template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007553StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7554 OMPTargetUpdateDirective *D) {
7555 DeclarationNameInfo DirName;
7556 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7557 nullptr, D->getLocStart());
7558 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7559 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7560 return Res;
7561}
7562
7563template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007564StmtResult
7565TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7566 DeclarationNameInfo DirName;
7567 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7568 D->getLocStart());
7569 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7570 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7571 return Res;
7572}
7573
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007574template <typename Derived>
7575StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7576 OMPCancellationPointDirective *D) {
7577 DeclarationNameInfo DirName;
7578 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7579 nullptr, D->getLocStart());
7580 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7581 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7582 return Res;
7583}
7584
Alexey Bataev80909872015-07-02 11:25:17 +00007585template <typename Derived>
7586StmtResult
7587TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7588 DeclarationNameInfo DirName;
7589 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7590 D->getLocStart());
7591 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7592 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7593 return Res;
7594}
7595
Alexey Bataev49f6e782015-12-01 04:18:41 +00007596template <typename Derived>
7597StmtResult
7598TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7599 DeclarationNameInfo DirName;
7600 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7601 D->getLocStart());
7602 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7603 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7604 return Res;
7605}
7606
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007607template <typename Derived>
7608StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7609 OMPTaskLoopSimdDirective *D) {
7610 DeclarationNameInfo DirName;
7611 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7612 nullptr, D->getLocStart());
7613 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7614 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7615 return Res;
7616}
7617
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007618template <typename Derived>
7619StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7620 OMPDistributeDirective *D) {
7621 DeclarationNameInfo DirName;
7622 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7623 D->getLocStart());
7624 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7625 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7626 return Res;
7627}
7628
Carlo Bertolli9925f152016-06-27 14:55:37 +00007629template <typename Derived>
7630StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7631 OMPDistributeParallelForDirective *D) {
7632 DeclarationNameInfo DirName;
7633 getDerived().getSema().StartOpenMPDSABlock(
7634 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7635 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7636 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7637 return Res;
7638}
7639
Kelvin Li4a39add2016-07-05 05:00:15 +00007640template <typename Derived>
7641StmtResult
7642TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7643 OMPDistributeParallelForSimdDirective *D) {
7644 DeclarationNameInfo DirName;
7645 getDerived().getSema().StartOpenMPDSABlock(
7646 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7649 return Res;
7650}
7651
Kelvin Li787f3fc2016-07-06 04:45:38 +00007652template <typename Derived>
7653StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7654 OMPDistributeSimdDirective *D) {
7655 DeclarationNameInfo DirName;
7656 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7657 nullptr, D->getLocStart());
7658 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7659 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7660 return Res;
7661}
7662
Kelvin Lia579b912016-07-14 02:54:56 +00007663template <typename Derived>
7664StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7665 OMPTargetParallelForSimdDirective *D) {
7666 DeclarationNameInfo DirName;
7667 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7668 DirName, nullptr,
7669 D->getLocStart());
7670 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7671 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7672 return Res;
7673}
7674
Kelvin Li986330c2016-07-20 22:57:10 +00007675template <typename Derived>
7676StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7677 OMPTargetSimdDirective *D) {
7678 DeclarationNameInfo DirName;
7679 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7680 D->getLocStart());
7681 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7682 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7683 return Res;
7684}
7685
Kelvin Li02532872016-08-05 14:37:37 +00007686template <typename Derived>
7687StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7688 OMPTeamsDistributeDirective *D) {
7689 DeclarationNameInfo DirName;
7690 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7691 nullptr, D->getLocStart());
7692 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7693 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7694 return Res;
7695}
7696
Kelvin Li4e325f72016-10-25 12:50:55 +00007697template <typename Derived>
7698StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7699 OMPTeamsDistributeSimdDirective *D) {
7700 DeclarationNameInfo DirName;
7701 getDerived().getSema().StartOpenMPDSABlock(
7702 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7703 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7704 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7705 return Res;
7706}
7707
Kelvin Li579e41c2016-11-30 23:51:03 +00007708template <typename Derived>
7709StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
7710 OMPTeamsDistributeParallelForSimdDirective *D) {
7711 DeclarationNameInfo DirName;
7712 getDerived().getSema().StartOpenMPDSABlock(
7713 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7714 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7715 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7716 return Res;
7717}
7718
Kelvin Li7ade93f2016-12-09 03:24:30 +00007719template <typename Derived>
7720StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
7721 OMPTeamsDistributeParallelForDirective *D) {
7722 DeclarationNameInfo DirName;
7723 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
7724 DirName, nullptr, D->getLocStart());
7725 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7726 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7727 return Res;
7728}
7729
Kelvin Li579e41c2016-11-30 23:51:03 +00007730
Alexander Musman64d33f12014-06-04 07:53:32 +00007731//===----------------------------------------------------------------------===//
7732// OpenMP clause transformation
7733//===----------------------------------------------------------------------===//
7734template <typename Derived>
7735OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007736 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7737 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007738 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007739 return getDerived().RebuildOMPIfClause(
7740 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7741 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007742}
7743
Alexander Musman64d33f12014-06-04 07:53:32 +00007744template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007745OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7746 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7747 if (Cond.isInvalid())
7748 return nullptr;
7749 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7750 C->getLParenLoc(), C->getLocEnd());
7751}
7752
7753template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007754OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007755TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7756 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7757 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007758 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007759 return getDerived().RebuildOMPNumThreadsClause(
7760 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007761}
7762
Alexey Bataev62c87d22014-03-21 04:51:18 +00007763template <typename Derived>
7764OMPClause *
7765TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7766 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7767 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007768 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007769 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007770 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007771}
7772
Alexander Musman8bd31e62014-05-27 15:12:19 +00007773template <typename Derived>
7774OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007775TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7776 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7777 if (E.isInvalid())
7778 return nullptr;
7779 return getDerived().RebuildOMPSimdlenClause(
7780 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7781}
7782
7783template <typename Derived>
7784OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007785TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7786 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7787 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007788 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007789 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007790 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007791}
7792
Alexander Musman64d33f12014-06-04 07:53:32 +00007793template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007794OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007795TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007796 return getDerived().RebuildOMPDefaultClause(
7797 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7798 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007799}
7800
Alexander Musman64d33f12014-06-04 07:53:32 +00007801template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007802OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007803TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007804 return getDerived().RebuildOMPProcBindClause(
7805 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7806 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007807}
7808
Alexander Musman64d33f12014-06-04 07:53:32 +00007809template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007810OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007811TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7812 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7813 if (E.isInvalid())
7814 return nullptr;
7815 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007816 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007817 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007818 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007819 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7820}
7821
7822template <typename Derived>
7823OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007824TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007825 ExprResult E;
7826 if (auto *Num = C->getNumForLoops()) {
7827 E = getDerived().TransformExpr(Num);
7828 if (E.isInvalid())
7829 return nullptr;
7830 }
7831 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7832 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007833}
7834
7835template <typename Derived>
7836OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007837TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7838 // No need to rebuild this clause, no template-dependent parameters.
7839 return C;
7840}
7841
7842template <typename Derived>
7843OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007844TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7845 // No need to rebuild this clause, no template-dependent parameters.
7846 return C;
7847}
7848
7849template <typename Derived>
7850OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007851TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7852 // No need to rebuild this clause, no template-dependent parameters.
7853 return C;
7854}
7855
7856template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007857OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7858 // No need to rebuild this clause, no template-dependent parameters.
7859 return C;
7860}
7861
7862template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007863OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7864 // No need to rebuild this clause, no template-dependent parameters.
7865 return C;
7866}
7867
7868template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007869OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007870TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7871 // No need to rebuild this clause, no template-dependent parameters.
7872 return C;
7873}
7874
7875template <typename Derived>
7876OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007877TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7878 // No need to rebuild this clause, no template-dependent parameters.
7879 return C;
7880}
7881
7882template <typename Derived>
7883OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007884TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7885 // No need to rebuild this clause, no template-dependent parameters.
7886 return C;
7887}
7888
7889template <typename Derived>
7890OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007891TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7892 // No need to rebuild this clause, no template-dependent parameters.
7893 return C;
7894}
7895
7896template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007897OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7898 // No need to rebuild this clause, no template-dependent parameters.
7899 return C;
7900}
7901
7902template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007903OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007904TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7905 // No need to rebuild this clause, no template-dependent parameters.
7906 return C;
7907}
7908
7909template <typename Derived>
7910OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007911TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007912 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007913 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007914 for (auto *VE : C->varlists()) {
7915 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007916 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007917 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007918 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007919 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007920 return getDerived().RebuildOMPPrivateClause(
7921 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007922}
7923
Alexander Musman64d33f12014-06-04 07:53:32 +00007924template <typename Derived>
7925OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7926 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007927 llvm::SmallVector<Expr *, 16> Vars;
7928 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007929 for (auto *VE : C->varlists()) {
7930 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007931 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007932 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007933 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007934 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007935 return getDerived().RebuildOMPFirstprivateClause(
7936 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007937}
7938
Alexander Musman64d33f12014-06-04 07:53:32 +00007939template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007940OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007941TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7942 llvm::SmallVector<Expr *, 16> Vars;
7943 Vars.reserve(C->varlist_size());
7944 for (auto *VE : C->varlists()) {
7945 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7946 if (EVar.isInvalid())
7947 return nullptr;
7948 Vars.push_back(EVar.get());
7949 }
7950 return getDerived().RebuildOMPLastprivateClause(
7951 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7952}
7953
7954template <typename Derived>
7955OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007956TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7957 llvm::SmallVector<Expr *, 16> Vars;
7958 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007959 for (auto *VE : C->varlists()) {
7960 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007961 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007962 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007963 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007964 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007965 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7966 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007967}
7968
Alexander Musman64d33f12014-06-04 07:53:32 +00007969template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007970OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007971TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7972 llvm::SmallVector<Expr *, 16> Vars;
7973 Vars.reserve(C->varlist_size());
7974 for (auto *VE : C->varlists()) {
7975 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7976 if (EVar.isInvalid())
7977 return nullptr;
7978 Vars.push_back(EVar.get());
7979 }
7980 CXXScopeSpec ReductionIdScopeSpec;
7981 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7982
7983 DeclarationNameInfo NameInfo = C->getNameInfo();
7984 if (NameInfo.getName()) {
7985 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7986 if (!NameInfo.getName())
7987 return nullptr;
7988 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007989 // Build a list of all UDR decls with the same names ranged by the Scopes.
7990 // The Scope boundary is a duplication of the previous decl.
7991 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
7992 for (auto *E : C->reduction_ops()) {
7993 // Transform all the decls.
7994 if (E) {
7995 auto *ULE = cast<UnresolvedLookupExpr>(E);
7996 UnresolvedSet<8> Decls;
7997 for (auto *D : ULE->decls()) {
7998 NamedDecl *InstD =
7999 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8000 Decls.addDecl(InstD, InstD->getAccess());
8001 }
8002 UnresolvedReductions.push_back(
8003 UnresolvedLookupExpr::Create(
8004 SemaRef.Context, /*NamingClass=*/nullptr,
8005 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8006 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8007 Decls.begin(), Decls.end()));
8008 } else
8009 UnresolvedReductions.push_back(nullptr);
8010 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008011 return getDerived().RebuildOMPReductionClause(
8012 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008013 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008014}
8015
8016template <typename Derived>
8017OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008018TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8019 llvm::SmallVector<Expr *, 16> Vars;
8020 Vars.reserve(C->varlist_size());
8021 for (auto *VE : C->varlists()) {
8022 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8023 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008024 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008025 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008026 }
8027 ExprResult Step = getDerived().TransformExpr(C->getStep());
8028 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008029 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008030 return getDerived().RebuildOMPLinearClause(
8031 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8032 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008033}
8034
Alexander Musman64d33f12014-06-04 07:53:32 +00008035template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008036OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008037TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8038 llvm::SmallVector<Expr *, 16> Vars;
8039 Vars.reserve(C->varlist_size());
8040 for (auto *VE : C->varlists()) {
8041 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8042 if (EVar.isInvalid())
8043 return nullptr;
8044 Vars.push_back(EVar.get());
8045 }
8046 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8047 if (Alignment.isInvalid())
8048 return nullptr;
8049 return getDerived().RebuildOMPAlignedClause(
8050 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8051 C->getColonLoc(), C->getLocEnd());
8052}
8053
Alexander Musman64d33f12014-06-04 07:53:32 +00008054template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008055OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008056TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8057 llvm::SmallVector<Expr *, 16> Vars;
8058 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008059 for (auto *VE : C->varlists()) {
8060 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008061 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008062 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008063 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008064 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008065 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8066 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008067}
8068
Alexey Bataevbae9a792014-06-27 10:37:06 +00008069template <typename Derived>
8070OMPClause *
8071TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8072 llvm::SmallVector<Expr *, 16> Vars;
8073 Vars.reserve(C->varlist_size());
8074 for (auto *VE : C->varlists()) {
8075 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8076 if (EVar.isInvalid())
8077 return nullptr;
8078 Vars.push_back(EVar.get());
8079 }
8080 return getDerived().RebuildOMPCopyprivateClause(
8081 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8082}
8083
Alexey Bataev6125da92014-07-21 11:26:11 +00008084template <typename Derived>
8085OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8086 llvm::SmallVector<Expr *, 16> Vars;
8087 Vars.reserve(C->varlist_size());
8088 for (auto *VE : C->varlists()) {
8089 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8090 if (EVar.isInvalid())
8091 return nullptr;
8092 Vars.push_back(EVar.get());
8093 }
8094 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8095 C->getLParenLoc(), C->getLocEnd());
8096}
8097
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008098template <typename Derived>
8099OMPClause *
8100TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8101 llvm::SmallVector<Expr *, 16> Vars;
8102 Vars.reserve(C->varlist_size());
8103 for (auto *VE : C->varlists()) {
8104 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8105 if (EVar.isInvalid())
8106 return nullptr;
8107 Vars.push_back(EVar.get());
8108 }
8109 return getDerived().RebuildOMPDependClause(
8110 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8111 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8112}
8113
Michael Wonge710d542015-08-07 16:16:36 +00008114template <typename Derived>
8115OMPClause *
8116TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8117 ExprResult E = getDerived().TransformExpr(C->getDevice());
8118 if (E.isInvalid())
8119 return nullptr;
8120 return getDerived().RebuildOMPDeviceClause(
8121 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8122}
8123
Kelvin Li0bff7af2015-11-23 05:32:03 +00008124template <typename Derived>
8125OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8126 llvm::SmallVector<Expr *, 16> Vars;
8127 Vars.reserve(C->varlist_size());
8128 for (auto *VE : C->varlists()) {
8129 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8130 if (EVar.isInvalid())
8131 return nullptr;
8132 Vars.push_back(EVar.get());
8133 }
8134 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008135 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8136 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8137 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008138}
8139
Kelvin Li099bb8c2015-11-24 20:50:12 +00008140template <typename Derived>
8141OMPClause *
8142TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8143 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8144 if (E.isInvalid())
8145 return nullptr;
8146 return getDerived().RebuildOMPNumTeamsClause(
8147 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8148}
8149
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008150template <typename Derived>
8151OMPClause *
8152TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8153 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8154 if (E.isInvalid())
8155 return nullptr;
8156 return getDerived().RebuildOMPThreadLimitClause(
8157 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8158}
8159
Alexey Bataeva0569352015-12-01 10:17:31 +00008160template <typename Derived>
8161OMPClause *
8162TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8163 ExprResult E = getDerived().TransformExpr(C->getPriority());
8164 if (E.isInvalid())
8165 return nullptr;
8166 return getDerived().RebuildOMPPriorityClause(
8167 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8168}
8169
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008170template <typename Derived>
8171OMPClause *
8172TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8173 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8174 if (E.isInvalid())
8175 return nullptr;
8176 return getDerived().RebuildOMPGrainsizeClause(
8177 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8178}
8179
Alexey Bataev382967a2015-12-08 12:06:20 +00008180template <typename Derived>
8181OMPClause *
8182TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8183 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8184 if (E.isInvalid())
8185 return nullptr;
8186 return getDerived().RebuildOMPNumTasksClause(
8187 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8188}
8189
Alexey Bataev28c75412015-12-15 08:19:24 +00008190template <typename Derived>
8191OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8192 ExprResult E = getDerived().TransformExpr(C->getHint());
8193 if (E.isInvalid())
8194 return nullptr;
8195 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8196 C->getLParenLoc(), C->getLocEnd());
8197}
8198
Carlo Bertollib4adf552016-01-15 18:50:31 +00008199template <typename Derived>
8200OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8201 OMPDistScheduleClause *C) {
8202 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8203 if (E.isInvalid())
8204 return nullptr;
8205 return getDerived().RebuildOMPDistScheduleClause(
8206 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8207 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8208}
8209
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008210template <typename Derived>
8211OMPClause *
8212TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8213 return C;
8214}
8215
Samuel Antao661c0902016-05-26 17:39:58 +00008216template <typename Derived>
8217OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8218 llvm::SmallVector<Expr *, 16> Vars;
8219 Vars.reserve(C->varlist_size());
8220 for (auto *VE : C->varlists()) {
8221 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8222 if (EVar.isInvalid())
8223 return 0;
8224 Vars.push_back(EVar.get());
8225 }
8226 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8227 C->getLParenLoc(), C->getLocEnd());
8228}
8229
Samuel Antaoec172c62016-05-26 17:49:04 +00008230template <typename Derived>
8231OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8232 llvm::SmallVector<Expr *, 16> Vars;
8233 Vars.reserve(C->varlist_size());
8234 for (auto *VE : C->varlists()) {
8235 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8236 if (EVar.isInvalid())
8237 return 0;
8238 Vars.push_back(EVar.get());
8239 }
8240 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8241 C->getLParenLoc(), C->getLocEnd());
8242}
8243
Carlo Bertolli2404b172016-07-13 15:37:16 +00008244template <typename Derived>
8245OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8246 OMPUseDevicePtrClause *C) {
8247 llvm::SmallVector<Expr *, 16> Vars;
8248 Vars.reserve(C->varlist_size());
8249 for (auto *VE : C->varlists()) {
8250 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8251 if (EVar.isInvalid())
8252 return nullptr;
8253 Vars.push_back(EVar.get());
8254 }
8255 return getDerived().RebuildOMPUseDevicePtrClause(
8256 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8257}
8258
Carlo Bertolli70594e92016-07-13 17:16:49 +00008259template <typename Derived>
8260OMPClause *
8261TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8262 llvm::SmallVector<Expr *, 16> Vars;
8263 Vars.reserve(C->varlist_size());
8264 for (auto *VE : C->varlists()) {
8265 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8266 if (EVar.isInvalid())
8267 return nullptr;
8268 Vars.push_back(EVar.get());
8269 }
8270 return getDerived().RebuildOMPIsDevicePtrClause(
8271 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8272}
8273
Douglas Gregorebe10102009-08-20 07:17:43 +00008274//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008275// Expression transformation
8276//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008277template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008278ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008279TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008280 if (!E->isTypeDependent())
8281 return E;
8282
8283 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8284 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008285}
Mike Stump11289f42009-09-09 15:08:12 +00008286
8287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008289TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008290 NestedNameSpecifierLoc QualifierLoc;
8291 if (E->getQualifierLoc()) {
8292 QualifierLoc
8293 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8294 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008295 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008296 }
John McCallce546572009-12-08 09:08:17 +00008297
8298 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008299 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8300 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008301 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008302 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008303
John McCall815039a2010-08-17 21:27:17 +00008304 DeclarationNameInfo NameInfo = E->getNameInfo();
8305 if (NameInfo.getName()) {
8306 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8307 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008308 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008309 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008310
8311 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008312 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008313 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008314 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008315 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008316
8317 // Mark it referenced in the new context regardless.
8318 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008319 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008320
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008321 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008322 }
John McCallce546572009-12-08 09:08:17 +00008323
Craig Topperc3ec1492014-05-26 06:22:03 +00008324 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008325 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008326 TemplateArgs = &TransArgs;
8327 TransArgs.setLAngleLoc(E->getLAngleLoc());
8328 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008329 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8330 E->getNumTemplateArgs(),
8331 TransArgs))
8332 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008333 }
8334
Chad Rosier1dcde962012-08-08 18:46:20 +00008335 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008336 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008337}
Mike Stump11289f42009-09-09 15:08:12 +00008338
Douglas Gregora16548e2009-08-11 05:31:07 +00008339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008341TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008342 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008343}
Mike Stump11289f42009-09-09 15:08:12 +00008344
Douglas Gregora16548e2009-08-11 05:31:07 +00008345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008346ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008347TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008348 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008349}
Mike Stump11289f42009-09-09 15:08:12 +00008350
Douglas Gregora16548e2009-08-11 05:31:07 +00008351template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008352ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008353TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008354 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008355}
Mike Stump11289f42009-09-09 15:08:12 +00008356
Douglas Gregora16548e2009-08-11 05:31:07 +00008357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008359TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008360 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008361}
Mike Stump11289f42009-09-09 15:08:12 +00008362
Douglas Gregora16548e2009-08-11 05:31:07 +00008363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008365TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008366 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008367}
8368
8369template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008370ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008371TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008372 if (FunctionDecl *FD = E->getDirectCallee())
8373 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008374 return SemaRef.MaybeBindToTemporary(E);
8375}
8376
8377template<typename Derived>
8378ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008379TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8380 ExprResult ControllingExpr =
8381 getDerived().TransformExpr(E->getControllingExpr());
8382 if (ControllingExpr.isInvalid())
8383 return ExprError();
8384
Chris Lattner01cf8db2011-07-20 06:58:45 +00008385 SmallVector<Expr *, 4> AssocExprs;
8386 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008387 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8388 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8389 if (TS) {
8390 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8391 if (!AssocType)
8392 return ExprError();
8393 AssocTypes.push_back(AssocType);
8394 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008395 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008396 }
8397
8398 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8399 if (AssocExpr.isInvalid())
8400 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008401 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008402 }
8403
8404 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8405 E->getDefaultLoc(),
8406 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008407 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008408 AssocTypes,
8409 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008410}
8411
8412template<typename Derived>
8413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008414TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008415 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008416 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008418
Douglas Gregora16548e2009-08-11 05:31:07 +00008419 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008420 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008421
John McCallb268a282010-08-23 23:25:46 +00008422 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 E->getRParen());
8424}
8425
Richard Smithdb2630f2012-10-21 03:28:35 +00008426/// \brief The operand of a unary address-of operator has special rules: it's
8427/// allowed to refer to a non-static member of a class even if there's no 'this'
8428/// object available.
8429template<typename Derived>
8430ExprResult
8431TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8432 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008433 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008434 else
8435 return getDerived().TransformExpr(E);
8436}
8437
Mike Stump11289f42009-09-09 15:08:12 +00008438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008440TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008441 ExprResult SubExpr;
8442 if (E->getOpcode() == UO_AddrOf)
8443 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8444 else
8445 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008446 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008448
Douglas Gregora16548e2009-08-11 05:31:07 +00008449 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008450 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008451
Douglas Gregora16548e2009-08-11 05:31:07 +00008452 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8453 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008454 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008455}
Mike Stump11289f42009-09-09 15:08:12 +00008456
Douglas Gregora16548e2009-08-11 05:31:07 +00008457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008458ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008459TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8460 // Transform the type.
8461 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8462 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008463 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008464
Douglas Gregor882211c2010-04-28 22:16:22 +00008465 // Transform all of the components into components similar to what the
8466 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008467 // FIXME: It would be slightly more efficient in the non-dependent case to
8468 // just map FieldDecls, rather than requiring the rebuilder to look for
8469 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008470 // template code that we don't care.
8471 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008472 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008473 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008474 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008475 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008476 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008477 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008478 Comp.LocStart = ON.getSourceRange().getBegin();
8479 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008480 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008481 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008482 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008483 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008484 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008485 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008486
Douglas Gregor882211c2010-04-28 22:16:22 +00008487 ExprChanged = ExprChanged || Index.get() != FromIndex;
8488 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008489 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008490 break;
8491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008492
James Y Knight7281c352015-12-29 22:31:18 +00008493 case OffsetOfNode::Field:
8494 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008495 Comp.isBrackets = false;
8496 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008497 if (!Comp.U.IdentInfo)
8498 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008499
Douglas Gregor882211c2010-04-28 22:16:22 +00008500 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008501
James Y Knight7281c352015-12-29 22:31:18 +00008502 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008503 // Will be recomputed during the rebuild.
8504 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008505 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008506
Douglas Gregor882211c2010-04-28 22:16:22 +00008507 Components.push_back(Comp);
8508 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
Douglas Gregor882211c2010-04-28 22:16:22 +00008510 // If nothing changed, retain the existing expression.
8511 if (!getDerived().AlwaysRebuild() &&
8512 Type == E->getTypeSourceInfo() &&
8513 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008514 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008515
Douglas Gregor882211c2010-04-28 22:16:22 +00008516 // Build a new offsetof expression.
8517 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008518 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008519}
8520
8521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008522ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008523TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008524 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008525 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008526 return E;
John McCall8d69a212010-11-15 23:31:06 +00008527}
8528
8529template<typename Derived>
8530ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008531TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8532 return E;
8533}
8534
8535template<typename Derived>
8536ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008537TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008538 // Rebuild the syntactic form. The original syntactic form has
8539 // opaque-value expressions in it, so strip those away and rebuild
8540 // the result. This is a really awful way of doing this, but the
8541 // better solution (rebuilding the semantic expressions and
8542 // rebinding OVEs as necessary) doesn't work; we'd need
8543 // TreeTransform to not strip away implicit conversions.
8544 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8545 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008546 if (result.isInvalid()) return ExprError();
8547
8548 // If that gives us a pseudo-object result back, the pseudo-object
8549 // expression must have been an lvalue-to-rvalue conversion which we
8550 // should reapply.
8551 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008552 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008553
8554 return result;
8555}
8556
8557template<typename Derived>
8558ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008559TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8560 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008561 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008562 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008563
John McCallbcd03502009-12-07 02:54:59 +00008564 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008565 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008567
John McCall4c98fd82009-11-04 07:28:41 +00008568 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008569 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008570
Peter Collingbournee190dee2011-03-11 19:24:49 +00008571 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8572 E->getKind(),
8573 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008574 }
Mike Stump11289f42009-09-09 15:08:12 +00008575
Eli Friedmane4f22df2012-02-29 04:03:55 +00008576 // C++0x [expr.sizeof]p1:
8577 // The operand is either an expression, which is an unevaluated operand
8578 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008579 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8580 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008581
Reid Kleckner32506ed2014-06-12 23:03:48 +00008582 // Try to recover if we have something like sizeof(T::X) where X is a type.
8583 // Notably, there must be *exactly* one set of parens if X is a type.
8584 TypeSourceInfo *RecoveryTSI = nullptr;
8585 ExprResult SubExpr;
8586 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8587 if (auto *DRE =
8588 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8589 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8590 PE, DRE, false, &RecoveryTSI);
8591 else
8592 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8593
8594 if (RecoveryTSI) {
8595 return getDerived().RebuildUnaryExprOrTypeTrait(
8596 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8597 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008599
Eli Friedmane4f22df2012-02-29 04:03:55 +00008600 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008601 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008602
Peter Collingbournee190dee2011-03-11 19:24:49 +00008603 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8604 E->getOperatorLoc(),
8605 E->getKind(),
8606 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008607}
Mike Stump11289f42009-09-09 15:08:12 +00008608
Douglas Gregora16548e2009-08-11 05:31:07 +00008609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008610ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008611TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008612 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008613 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008615
John McCalldadc5752010-08-24 06:29:42 +00008616 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008617 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008619
8620
Douglas Gregora16548e2009-08-11 05:31:07 +00008621 if (!getDerived().AlwaysRebuild() &&
8622 LHS.get() == E->getLHS() &&
8623 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008624 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008625
John McCallb268a282010-08-23 23:25:46 +00008626 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008627 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008628 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008629 E->getRBracketLoc());
8630}
Mike Stump11289f42009-09-09 15:08:12 +00008631
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008632template <typename Derived>
8633ExprResult
8634TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8635 ExprResult Base = getDerived().TransformExpr(E->getBase());
8636 if (Base.isInvalid())
8637 return ExprError();
8638
8639 ExprResult LowerBound;
8640 if (E->getLowerBound()) {
8641 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8642 if (LowerBound.isInvalid())
8643 return ExprError();
8644 }
8645
8646 ExprResult Length;
8647 if (E->getLength()) {
8648 Length = getDerived().TransformExpr(E->getLength());
8649 if (Length.isInvalid())
8650 return ExprError();
8651 }
8652
8653 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8654 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8655 return E;
8656
8657 return getDerived().RebuildOMPArraySectionExpr(
8658 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8659 Length.get(), E->getRBracketLoc());
8660}
8661
Mike Stump11289f42009-09-09 15:08:12 +00008662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008664TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008665 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008666 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008667 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008668 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008669
8670 // Transform arguments.
8671 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008672 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008673 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008674 &ArgChanged))
8675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008676
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 if (!getDerived().AlwaysRebuild() &&
8678 Callee.get() == E->getCallee() &&
8679 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008680 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008681
Douglas Gregora16548e2009-08-11 05:31:07 +00008682 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008683 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008684 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008685 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008686 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008687 E->getRParenLoc());
8688}
Mike Stump11289f42009-09-09 15:08:12 +00008689
8690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008693 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008694 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008696
Douglas Gregorea972d32011-02-28 21:54:11 +00008697 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008698 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008699 QualifierLoc
8700 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008701
Douglas Gregorea972d32011-02-28 21:54:11 +00008702 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008703 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008704 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008705 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008706
Eli Friedman2cfcef62009-12-04 06:40:45 +00008707 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008708 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8709 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008710 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008711 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008712
John McCall16df1e52010-03-30 21:47:33 +00008713 NamedDecl *FoundDecl = E->getFoundDecl();
8714 if (FoundDecl == E->getMemberDecl()) {
8715 FoundDecl = Member;
8716 } else {
8717 FoundDecl = cast_or_null<NamedDecl>(
8718 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8719 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008720 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008721 }
8722
Douglas Gregora16548e2009-08-11 05:31:07 +00008723 if (!getDerived().AlwaysRebuild() &&
8724 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008725 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008726 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008727 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008728 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008729
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008730 // Mark it referenced in the new context regardless.
8731 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008732 SemaRef.MarkMemberReferenced(E);
8733
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008734 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008735 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008736
John McCall6b51f282009-11-23 01:53:49 +00008737 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008738 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008739 TransArgs.setLAngleLoc(E->getLAngleLoc());
8740 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008741 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8742 E->getNumTemplateArgs(),
8743 TransArgs))
8744 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008746
Douglas Gregora16548e2009-08-11 05:31:07 +00008747 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008748 SourceLocation FakeOperatorLoc =
8749 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008750
John McCall38836f02010-01-15 08:34:02 +00008751 // FIXME: to do this check properly, we will need to preserve the
8752 // first-qualifier-in-scope here, just in case we had a dependent
8753 // base (and therefore couldn't do the check) and a
8754 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008755 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008756
John McCallb268a282010-08-23 23:25:46 +00008757 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008758 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008759 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008760 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008761 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008762 Member,
John McCall16df1e52010-03-30 21:47:33 +00008763 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008764 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008765 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008766 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008767}
Mike Stump11289f42009-09-09 15:08:12 +00008768
Douglas Gregora16548e2009-08-11 05:31:07 +00008769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008771TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008772 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008773 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008775
John McCalldadc5752010-08-24 06:29:42 +00008776 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008777 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008779
Douglas Gregora16548e2009-08-11 05:31:07 +00008780 if (!getDerived().AlwaysRebuild() &&
8781 LHS.get() == E->getLHS() &&
8782 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008783 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008784
Lang Hames5de91cc2012-10-02 04:45:10 +00008785 Sema::FPContractStateRAII FPContractState(getSema());
8786 getSema().FPFeatures.fp_contract = E->isFPContractable();
8787
Douglas Gregora16548e2009-08-11 05:31:07 +00008788 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008789 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008790}
8791
Mike Stump11289f42009-09-09 15:08:12 +00008792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008793ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008794TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008795 CompoundAssignOperator *E) {
8796 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008797}
Mike Stump11289f42009-09-09 15:08:12 +00008798
Douglas Gregora16548e2009-08-11 05:31:07 +00008799template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008800ExprResult TreeTransform<Derived>::
8801TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8802 // Just rebuild the common and RHS expressions and see whether we
8803 // get any changes.
8804
8805 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8806 if (commonExpr.isInvalid())
8807 return ExprError();
8808
8809 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8810 if (rhs.isInvalid())
8811 return ExprError();
8812
8813 if (!getDerived().AlwaysRebuild() &&
8814 commonExpr.get() == e->getCommon() &&
8815 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008816 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008817
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008818 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008819 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008820 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008821 e->getColonLoc(),
8822 rhs.get());
8823}
8824
8825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008826ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008827TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008828 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008829 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008831
John McCalldadc5752010-08-24 06:29:42 +00008832 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008833 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008835
John McCalldadc5752010-08-24 06:29:42 +00008836 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008837 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840 if (!getDerived().AlwaysRebuild() &&
8841 Cond.get() == E->getCond() &&
8842 LHS.get() == E->getLHS() &&
8843 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008844 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008845
John McCallb268a282010-08-23 23:25:46 +00008846 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008847 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008848 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008849 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008850 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008851}
Mike Stump11289f42009-09-09 15:08:12 +00008852
8853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008855TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008856 // Implicit casts are eliminated during transformation, since they
8857 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008858 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008859}
Mike Stump11289f42009-09-09 15:08:12 +00008860
Douglas Gregora16548e2009-08-11 05:31:07 +00008861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008862ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008863TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008864 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8865 if (!Type)
8866 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008867
John McCalldadc5752010-08-24 06:29:42 +00008868 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008869 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008870 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008872
Douglas Gregora16548e2009-08-11 05:31:07 +00008873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008874 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008875 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008876 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008877
John McCall97513962010-01-15 18:39:57 +00008878 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008879 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008881 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008882}
Mike Stump11289f42009-09-09 15:08:12 +00008883
Douglas Gregora16548e2009-08-11 05:31:07 +00008884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008887 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8888 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8889 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008891
John McCalldadc5752010-08-24 06:29:42 +00008892 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008893 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008895
Douglas Gregora16548e2009-08-11 05:31:07 +00008896 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008897 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008898 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008899 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008900
John McCall5d7aa7f2010-01-19 22:33:45 +00008901 // Note: the expression type doesn't necessarily match the
8902 // type-as-written, but that's okay, because it should always be
8903 // derivable from the initializer.
8904
John McCalle15bbff2010-01-18 19:35:47 +00008905 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008906 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008907 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
Douglas Gregora16548e2009-08-11 05:31:07 +00008910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008912TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008913 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008914 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008916
Douglas Gregora16548e2009-08-11 05:31:07 +00008917 if (!getDerived().AlwaysRebuild() &&
8918 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008919 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008920
Douglas Gregora16548e2009-08-11 05:31:07 +00008921 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008922 SourceLocation FakeOperatorLoc =
8923 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008924 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008925 E->getAccessorLoc(),
8926 E->getAccessor());
8927}
Mike Stump11289f42009-09-09 15:08:12 +00008928
Douglas Gregora16548e2009-08-11 05:31:07 +00008929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008931TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008932 if (InitListExpr *Syntactic = E->getSyntacticForm())
8933 E = Syntactic;
8934
Douglas Gregora16548e2009-08-11 05:31:07 +00008935 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008936
Benjamin Kramerf0623432012-08-23 22:51:59 +00008937 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008938 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008939 Inits, &InitChanged))
8940 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008941
Richard Smith520449d2015-02-05 06:15:50 +00008942 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8943 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8944 // in some cases. We can't reuse it in general, because the syntactic and
8945 // semantic forms are linked, and we can't know that semantic form will
8946 // match even if the syntactic form does.
8947 }
Mike Stump11289f42009-09-09 15:08:12 +00008948
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008949 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008950 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008951}
Mike Stump11289f42009-09-09 15:08:12 +00008952
Douglas Gregora16548e2009-08-11 05:31:07 +00008953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008955TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008956 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008957
Douglas Gregorebe10102009-08-20 07:17:43 +00008958 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008959 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008960 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008962
Douglas Gregorebe10102009-08-20 07:17:43 +00008963 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008964 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008965 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008966 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8967 if (D.isFieldDesignator()) {
8968 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8969 D.getDotLoc(),
8970 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00008971 if (D.getField()) {
8972 FieldDecl *Field = cast_or_null<FieldDecl>(
8973 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
8974 if (Field != D.getField())
8975 // Rebuild the expression when the transformed FieldDecl is
8976 // different to the already assigned FieldDecl.
8977 ExprChanged = true;
8978 } else {
8979 // Ensure that the designator expression is rebuilt when there isn't
8980 // a resolved FieldDecl in the designator as we don't want to assign
8981 // a FieldDecl to a pattern designator that will be instantiated again.
8982 ExprChanged = true;
8983 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008984 continue;
8985 }
Mike Stump11289f42009-09-09 15:08:12 +00008986
David Majnemerf7e36092016-06-23 00:15:04 +00008987 if (D.isArrayDesignator()) {
8988 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008989 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008991
David Majnemerf7e36092016-06-23 00:15:04 +00008992 Desig.AddDesignator(
8993 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008994
David Majnemerf7e36092016-06-23 00:15:04 +00008995 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008996 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008997 continue;
8998 }
Mike Stump11289f42009-09-09 15:08:12 +00008999
David Majnemerf7e36092016-06-23 00:15:04 +00009000 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009001 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009002 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009003 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009005
David Majnemerf7e36092016-06-23 00:15:04 +00009006 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009007 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009009
9010 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009011 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009012 D.getLBracketLoc(),
9013 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009014
David Majnemerf7e36092016-06-23 00:15:04 +00009015 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9016 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009017
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009018 ArrayExprs.push_back(Start.get());
9019 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009020 }
Mike Stump11289f42009-09-09 15:08:12 +00009021
Douglas Gregora16548e2009-08-11 05:31:07 +00009022 if (!getDerived().AlwaysRebuild() &&
9023 Init.get() == E->getInit() &&
9024 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009025 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009026
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009027 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009029 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009030}
Mike Stump11289f42009-09-09 15:08:12 +00009031
Yunzhong Gaocb779302015-06-10 00:27:52 +00009032// Seems that if TransformInitListExpr() only works on the syntactic form of an
9033// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9034template<typename Derived>
9035ExprResult
9036TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9037 DesignatedInitUpdateExpr *E) {
9038 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9039 "initializer");
9040 return ExprError();
9041}
9042
9043template<typename Derived>
9044ExprResult
9045TreeTransform<Derived>::TransformNoInitExpr(
9046 NoInitExpr *E) {
9047 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9048 return ExprError();
9049}
9050
Douglas Gregora16548e2009-08-11 05:31:07 +00009051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009052ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009053TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9054 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9055 return ExprError();
9056}
9057
9058template<typename Derived>
9059ExprResult
9060TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9061 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9062 return ExprError();
9063}
9064
9065template<typename Derived>
9066ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009067TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009068 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009069 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009070
Douglas Gregor3da3c062009-10-28 00:29:27 +00009071 // FIXME: Will we ever have proper type location here? Will we actually
9072 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009073 QualType T = getDerived().TransformType(E->getType());
9074 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009075 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009076
Douglas Gregora16548e2009-08-11 05:31:07 +00009077 if (!getDerived().AlwaysRebuild() &&
9078 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009079 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009080
Douglas Gregora16548e2009-08-11 05:31:07 +00009081 return getDerived().RebuildImplicitValueInitExpr(T);
9082}
Mike Stump11289f42009-09-09 15:08:12 +00009083
Douglas Gregora16548e2009-08-11 05:31:07 +00009084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009086TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009087 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9088 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009089 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009090
John McCalldadc5752010-08-24 06:29:42 +00009091 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009092 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009093 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009094
Douglas Gregora16548e2009-08-11 05:31:07 +00009095 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009096 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009097 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009098 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009099
John McCallb268a282010-08-23 23:25:46 +00009100 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009101 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009102}
9103
9104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009105ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009106TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009107 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009108 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009109 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9110 &ArgumentChanged))
9111 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009114 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009115 E->getRParenLoc());
9116}
Mike Stump11289f42009-09-09 15:08:12 +00009117
Douglas Gregora16548e2009-08-11 05:31:07 +00009118/// \brief Transform an address-of-label expression.
9119///
9120/// By default, the transformation of an address-of-label expression always
9121/// rebuilds the expression, so that the label identifier can be resolved to
9122/// the corresponding label statement by semantic analysis.
9123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009125TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009126 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9127 E->getLabel());
9128 if (!LD)
9129 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009130
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009132 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009133}
Mike Stump11289f42009-09-09 15:08:12 +00009134
9135template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009137TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009138 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009139 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009140 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009141 if (SubStmt.isInvalid()) {
9142 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009143 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009144 }
Mike Stump11289f42009-09-09 15:08:12 +00009145
Douglas Gregora16548e2009-08-11 05:31:07 +00009146 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009147 SubStmt.get() == E->getSubStmt()) {
9148 // Calling this an 'error' is unintuitive, but it does the right thing.
9149 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009150 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009151 }
Mike Stump11289f42009-09-09 15:08:12 +00009152
9153 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009154 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009155 E->getRParenLoc());
9156}
Mike Stump11289f42009-09-09 15:08:12 +00009157
Douglas Gregora16548e2009-08-11 05:31:07 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009160TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009161 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009162 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009164
John McCalldadc5752010-08-24 06:29:42 +00009165 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009166 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009168
John McCalldadc5752010-08-24 06:29:42 +00009169 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009172
Douglas Gregora16548e2009-08-11 05:31:07 +00009173 if (!getDerived().AlwaysRebuild() &&
9174 Cond.get() == E->getCond() &&
9175 LHS.get() == E->getLHS() &&
9176 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009177 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009178
Douglas Gregora16548e2009-08-11 05:31:07 +00009179 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009180 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009181 E->getRParenLoc());
9182}
Mike Stump11289f42009-09-09 15:08:12 +00009183
Douglas Gregora16548e2009-08-11 05:31:07 +00009184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009185ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009186TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009187 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009188}
9189
9190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009192TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009193 switch (E->getOperator()) {
9194 case OO_New:
9195 case OO_Delete:
9196 case OO_Array_New:
9197 case OO_Array_Delete:
9198 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009200 case OO_Call: {
9201 // This is a call to an object's operator().
9202 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9203
9204 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009205 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009206 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009207 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009208
9209 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009210 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9211 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009212
9213 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009214 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009215 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009216 Args))
9217 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009218
John McCallb268a282010-08-23 23:25:46 +00009219 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009220 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009221 E->getLocEnd());
9222 }
9223
9224#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9225 case OO_##Name:
9226#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9227#include "clang/Basic/OperatorKinds.def"
9228 case OO_Subscript:
9229 // Handled below.
9230 break;
9231
9232 case OO_Conditional:
9233 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009234
9235 case OO_None:
9236 case NUM_OVERLOADED_OPERATORS:
9237 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009238 }
9239
John McCalldadc5752010-08-24 06:29:42 +00009240 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009241 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009243
Richard Smithdb2630f2012-10-21 03:28:35 +00009244 ExprResult First;
9245 if (E->getOperator() == OO_Amp)
9246 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9247 else
9248 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009249 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009250 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009251
John McCalldadc5752010-08-24 06:29:42 +00009252 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009253 if (E->getNumArgs() == 2) {
9254 Second = getDerived().TransformExpr(E->getArg(1));
9255 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009256 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009257 }
Mike Stump11289f42009-09-09 15:08:12 +00009258
Douglas Gregora16548e2009-08-11 05:31:07 +00009259 if (!getDerived().AlwaysRebuild() &&
9260 Callee.get() == E->getCallee() &&
9261 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009262 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009263 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009264
Lang Hames5de91cc2012-10-02 04:45:10 +00009265 Sema::FPContractStateRAII FPContractState(getSema());
9266 getSema().FPFeatures.fp_contract = E->isFPContractable();
9267
Douglas Gregora16548e2009-08-11 05:31:07 +00009268 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9269 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009270 Callee.get(),
9271 First.get(),
9272 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009273}
Mike Stump11289f42009-09-09 15:08:12 +00009274
Douglas Gregora16548e2009-08-11 05:31:07 +00009275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009277TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9278 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009279}
Mike Stump11289f42009-09-09 15:08:12 +00009280
Douglas Gregora16548e2009-08-11 05:31:07 +00009281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009282ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009283TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9284 // Transform the callee.
9285 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9286 if (Callee.isInvalid())
9287 return ExprError();
9288
9289 // Transform exec config.
9290 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9291 if (EC.isInvalid())
9292 return ExprError();
9293
9294 // Transform arguments.
9295 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009296 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009297 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009298 &ArgChanged))
9299 return ExprError();
9300
9301 if (!getDerived().AlwaysRebuild() &&
9302 Callee.get() == E->getCallee() &&
9303 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009304 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009305
9306 // FIXME: Wrong source location information for the '('.
9307 SourceLocation FakeLParenLoc
9308 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9309 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009310 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009311 E->getRParenLoc(), EC.get());
9312}
9313
9314template<typename Derived>
9315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009316TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009317 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9318 if (!Type)
9319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
John McCalldadc5752010-08-24 06:29:42 +00009321 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009322 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009323 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009325
Douglas Gregora16548e2009-08-11 05:31:07 +00009326 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009327 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009328 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009329 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009330 return getDerived().RebuildCXXNamedCastExpr(
9331 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9332 Type, E->getAngleBrackets().getEnd(),
9333 // FIXME. this should be '(' location
9334 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009335}
Mike Stump11289f42009-09-09 15:08:12 +00009336
Douglas Gregora16548e2009-08-11 05:31:07 +00009337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009339TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9340 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009341}
Mike Stump11289f42009-09-09 15:08:12 +00009342
9343template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009344ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009345TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9346 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009347}
9348
Douglas Gregora16548e2009-08-11 05:31:07 +00009349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009350ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009351TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009352 CXXReinterpretCastExpr *E) {
9353 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009354}
Mike Stump11289f42009-09-09 15:08:12 +00009355
Douglas Gregora16548e2009-08-11 05:31:07 +00009356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009357ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009358TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9359 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009360}
Mike Stump11289f42009-09-09 15:08:12 +00009361
Douglas Gregora16548e2009-08-11 05:31:07 +00009362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009363ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009364TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009365 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009366 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9367 if (!Type)
9368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009369
John McCalldadc5752010-08-24 06:29:42 +00009370 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009371 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009372 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009373 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009374
Douglas Gregora16548e2009-08-11 05:31:07 +00009375 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009376 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009377 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009378 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009379
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009380 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009381 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009382 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 E->getRParenLoc());
9384}
Mike Stump11289f42009-09-09 15:08:12 +00009385
Douglas Gregora16548e2009-08-11 05:31:07 +00009386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009388TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009389 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009390 TypeSourceInfo *TInfo
9391 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9392 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009393 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009394
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009396 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009397 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009398
Douglas Gregor9da64192010-04-26 22:37:10 +00009399 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9400 E->getLocStart(),
9401 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009402 E->getLocEnd());
9403 }
Mike Stump11289f42009-09-09 15:08:12 +00009404
Eli Friedman456f0182012-01-20 01:26:23 +00009405 // We don't know whether the subexpression is potentially evaluated until
9406 // after we perform semantic analysis. We speculatively assume it is
9407 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009408 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009409 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9410 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009411
John McCalldadc5752010-08-24 06:29:42 +00009412 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009414 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009415
Douglas Gregora16548e2009-08-11 05:31:07 +00009416 if (!getDerived().AlwaysRebuild() &&
9417 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009418 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009419
Douglas Gregor9da64192010-04-26 22:37:10 +00009420 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9421 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009422 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009423 E->getLocEnd());
9424}
9425
9426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009427ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009428TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9429 if (E->isTypeOperand()) {
9430 TypeSourceInfo *TInfo
9431 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9432 if (!TInfo)
9433 return ExprError();
9434
9435 if (!getDerived().AlwaysRebuild() &&
9436 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009437 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009438
Douglas Gregor69735112011-03-06 17:40:41 +00009439 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009440 E->getLocStart(),
9441 TInfo,
9442 E->getLocEnd());
9443 }
9444
Francois Pichet9f4f2072010-09-08 12:20:18 +00009445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9446
9447 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9448 if (SubExpr.isInvalid())
9449 return ExprError();
9450
9451 if (!getDerived().AlwaysRebuild() &&
9452 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009453 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009454
9455 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9456 E->getLocStart(),
9457 SubExpr.get(),
9458 E->getLocEnd());
9459}
9460
9461template<typename Derived>
9462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009463TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009464 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009465}
Mike Stump11289f42009-09-09 15:08:12 +00009466
Douglas Gregora16548e2009-08-11 05:31:07 +00009467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009468ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009469TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009470 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009471 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009472}
Mike Stump11289f42009-09-09 15:08:12 +00009473
Douglas Gregora16548e2009-08-11 05:31:07 +00009474template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009476TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009477 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009478
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009479 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9480 // Make sure that we capture 'this'.
9481 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009482 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009483 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009484
Douglas Gregorb15af892010-01-07 23:12:05 +00009485 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009486}
Mike Stump11289f42009-09-09 15:08:12 +00009487
Douglas Gregora16548e2009-08-11 05:31:07 +00009488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009490TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009491 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009492 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009493 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009494
Douglas Gregora16548e2009-08-11 05:31:07 +00009495 if (!getDerived().AlwaysRebuild() &&
9496 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009497 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009498
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009499 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9500 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009501}
Mike Stump11289f42009-09-09 15:08:12 +00009502
Douglas Gregora16548e2009-08-11 05:31:07 +00009503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009504ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009505TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009506 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009507 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9508 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009509 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009511
Chandler Carruth794da4c2010-02-08 06:42:49 +00009512 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009513 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009514 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009515
Douglas Gregor033f6752009-12-23 23:03:06 +00009516 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009517}
Mike Stump11289f42009-09-09 15:08:12 +00009518
Douglas Gregora16548e2009-08-11 05:31:07 +00009519template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009520ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009521TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9522 FieldDecl *Field
9523 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9524 E->getField()));
9525 if (!Field)
9526 return ExprError();
9527
9528 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009529 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009530
9531 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9532}
9533
9534template<typename Derived>
9535ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009536TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9537 CXXScalarValueInitExpr *E) {
9538 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9539 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009540 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009541
Douglas Gregora16548e2009-08-11 05:31:07 +00009542 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009543 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009544 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009545
Chad Rosier1dcde962012-08-08 18:46:20 +00009546 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009547 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009548 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009549}
Mike Stump11289f42009-09-09 15:08:12 +00009550
Douglas Gregora16548e2009-08-11 05:31:07 +00009551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009553TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009555 TypeSourceInfo *AllocTypeInfo
9556 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9557 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009559
Douglas Gregora16548e2009-08-11 05:31:07 +00009560 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009561 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009562 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009564
Douglas Gregora16548e2009-08-11 05:31:07 +00009565 // Transform the placement arguments (if any).
9566 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009567 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009568 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009569 E->getNumPlacementArgs(), true,
9570 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009571 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009572
Sebastian Redl6047f072012-02-16 12:22:20 +00009573 // Transform the initializer (if any).
9574 Expr *OldInit = E->getInitializer();
9575 ExprResult NewInit;
9576 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009577 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009578 if (NewInit.isInvalid())
9579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009580
Sebastian Redl6047f072012-02-16 12:22:20 +00009581 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009582 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009583 if (E->getOperatorNew()) {
9584 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009585 getDerived().TransformDecl(E->getLocStart(),
9586 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009587 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009588 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009589 }
9590
Craig Topperc3ec1492014-05-26 06:22:03 +00009591 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009592 if (E->getOperatorDelete()) {
9593 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009594 getDerived().TransformDecl(E->getLocStart(),
9595 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009596 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009597 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009599
Douglas Gregora16548e2009-08-11 05:31:07 +00009600 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009601 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009602 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009603 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009604 OperatorNew == E->getOperatorNew() &&
9605 OperatorDelete == E->getOperatorDelete() &&
9606 !ArgumentChanged) {
9607 // Mark any declarations we need as referenced.
9608 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009609 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009610 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009611 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009612 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009613
Sebastian Redl6047f072012-02-16 12:22:20 +00009614 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009615 QualType ElementType
9616 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9617 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9618 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9619 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009620 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009621 }
9622 }
9623 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009624
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009625 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009626 }
Mike Stump11289f42009-09-09 15:08:12 +00009627
Douglas Gregor0744ef62010-09-07 21:49:58 +00009628 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009629 if (!ArraySize.get()) {
9630 // If no array size was specified, but the new expression was
9631 // instantiated with an array type (e.g., "new T" where T is
9632 // instantiated with "int[4]"), extract the outer bound from the
9633 // array type as our array size. We do this with constant and
9634 // dependently-sized array types.
9635 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9636 if (!ArrayT) {
9637 // Do nothing
9638 } else if (const ConstantArrayType *ConsArrayT
9639 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009640 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9641 SemaRef.Context.getSizeType(),
9642 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009643 AllocType = ConsArrayT->getElementType();
9644 } else if (const DependentSizedArrayType *DepArrayT
9645 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9646 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009647 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009648 AllocType = DepArrayT->getElementType();
9649 }
9650 }
9651 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009652
Douglas Gregora16548e2009-08-11 05:31:07 +00009653 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9654 E->isGlobalNew(),
9655 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009656 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009657 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009658 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009659 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009660 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009661 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009662 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009663 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009664}
Mike Stump11289f42009-09-09 15:08:12 +00009665
Douglas Gregora16548e2009-08-11 05:31:07 +00009666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009667ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009668TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009669 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009670 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009672
Douglas Gregord2d9da02010-02-26 00:38:10 +00009673 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009674 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009675 if (E->getOperatorDelete()) {
9676 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009677 getDerived().TransformDecl(E->getLocStart(),
9678 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009679 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009680 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009681 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009682
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009684 Operand.get() == E->getArgument() &&
9685 OperatorDelete == E->getOperatorDelete()) {
9686 // Mark any declarations we need as referenced.
9687 // FIXME: instantiation-specific.
9688 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009689 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009690
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009691 if (!E->getArgument()->isTypeDependent()) {
9692 QualType Destroyed = SemaRef.Context.getBaseElementType(
9693 E->getDestroyedType());
9694 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9695 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009696 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009697 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009698 }
9699 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009701 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009702 }
Mike Stump11289f42009-09-09 15:08:12 +00009703
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9705 E->isGlobalDelete(),
9706 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009707 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009708}
Mike Stump11289f42009-09-09 15:08:12 +00009709
Douglas Gregora16548e2009-08-11 05:31:07 +00009710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009711ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009712TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009713 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009714 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009715 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009717
John McCallba7bf592010-08-24 05:47:05 +00009718 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009719 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009720 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009721 E->getOperatorLoc(),
9722 E->isArrow()? tok::arrow : tok::period,
9723 ObjectTypePtr,
9724 MayBePseudoDestructor);
9725 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009726 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009727
John McCallba7bf592010-08-24 05:47:05 +00009728 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009729 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9730 if (QualifierLoc) {
9731 QualifierLoc
9732 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9733 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009734 return ExprError();
9735 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009736 CXXScopeSpec SS;
9737 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009738
Douglas Gregor678f90d2010-02-25 01:56:36 +00009739 PseudoDestructorTypeStorage Destroyed;
9740 if (E->getDestroyedTypeInfo()) {
9741 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009742 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009743 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009744 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009745 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009746 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009747 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009748 // We aren't likely to be able to resolve the identifier down to a type
9749 // now anyway, so just retain the identifier.
9750 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9751 E->getDestroyedTypeLoc());
9752 } else {
9753 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009754 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009755 *E->getDestroyedTypeIdentifier(),
9756 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009757 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009758 SS, ObjectTypePtr,
9759 false);
9760 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009761 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009762
Douglas Gregor678f90d2010-02-25 01:56:36 +00009763 Destroyed
9764 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9765 E->getDestroyedTypeLoc());
9766 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009767
Craig Topperc3ec1492014-05-26 06:22:03 +00009768 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009769 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009770 CXXScopeSpec EmptySS;
9771 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009772 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009773 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009774 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009775 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009776
John McCallb268a282010-08-23 23:25:46 +00009777 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009778 E->getOperatorLoc(),
9779 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009780 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009781 ScopeTypeInfo,
9782 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009783 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009784 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009785}
Mike Stump11289f42009-09-09 15:08:12 +00009786
Douglas Gregorad8a3362009-09-04 17:36:40 +00009787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009788ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009789TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009790 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009791 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9792 Sema::LookupOrdinaryName);
9793
9794 // Transform all the decls.
9795 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9796 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009797 NamedDecl *InstD = static_cast<NamedDecl*>(
9798 getDerived().TransformDecl(Old->getNameLoc(),
9799 *I));
John McCall84d87672009-12-10 09:41:52 +00009800 if (!InstD) {
9801 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9802 // This can happen because of dependent hiding.
9803 if (isa<UsingShadowDecl>(*I))
9804 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009805 else {
9806 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009807 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009808 }
John McCall84d87672009-12-10 09:41:52 +00009809 }
John McCalle66edc12009-11-24 19:00:30 +00009810
9811 // Expand using declarations.
9812 if (isa<UsingDecl>(InstD)) {
9813 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009814 for (auto *I : UD->shadows())
9815 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009816 continue;
9817 }
9818
9819 R.addDecl(InstD);
9820 }
9821
9822 // Resolve a kind, but don't do any further analysis. If it's
9823 // ambiguous, the callee needs to deal with it.
9824 R.resolveKind();
9825
9826 // Rebuild the nested-name qualifier, if present.
9827 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009828 if (Old->getQualifierLoc()) {
9829 NestedNameSpecifierLoc QualifierLoc
9830 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9831 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009832 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009833
Douglas Gregor0da1d432011-02-28 20:01:57 +00009834 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009835 }
9836
Douglas Gregor9262f472010-04-27 18:19:34 +00009837 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009838 CXXRecordDecl *NamingClass
9839 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9840 Old->getNameLoc(),
9841 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009842 if (!NamingClass) {
9843 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009844 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009845 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009846
Douglas Gregorda7be082010-04-27 16:10:10 +00009847 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009848 }
9849
Abramo Bagnara7945c982012-01-27 09:46:47 +00009850 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9851
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009852 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009853 // it's a normal declaration name or member reference.
9854 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9855 NamedDecl *D = R.getAsSingle<NamedDecl>();
9856 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9857 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9858 // give a good diagnostic.
9859 if (D && D->isCXXInstanceMember()) {
9860 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9861 /*TemplateArgs=*/nullptr,
9862 /*Scope=*/nullptr);
9863 }
9864
John McCalle66edc12009-11-24 19:00:30 +00009865 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009866 }
John McCalle66edc12009-11-24 19:00:30 +00009867
9868 // If we have template arguments, rebuild them, then rebuild the
9869 // templateid expression.
9870 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009871 if (Old->hasExplicitTemplateArgs() &&
9872 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009873 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009874 TransArgs)) {
9875 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009876 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009877 }
John McCalle66edc12009-11-24 19:00:30 +00009878
Abramo Bagnara7945c982012-01-27 09:46:47 +00009879 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009880 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009881}
Mike Stump11289f42009-09-09 15:08:12 +00009882
Douglas Gregora16548e2009-08-11 05:31:07 +00009883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009884ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009885TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9886 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009887 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009888 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9889 TypeSourceInfo *From = E->getArg(I);
9890 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009891 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009892 TypeLocBuilder TLB;
9893 TLB.reserve(FromTL.getFullDataSize());
9894 QualType To = getDerived().TransformType(TLB, FromTL);
9895 if (To.isNull())
9896 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009897
Douglas Gregor29c42f22012-02-24 07:38:34 +00009898 if (To == From->getType())
9899 Args.push_back(From);
9900 else {
9901 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9902 ArgChanged = true;
9903 }
9904 continue;
9905 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009906
Douglas Gregor29c42f22012-02-24 07:38:34 +00009907 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009908
Douglas Gregor29c42f22012-02-24 07:38:34 +00009909 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009910 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009911 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9912 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9913 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009914
Douglas Gregor29c42f22012-02-24 07:38:34 +00009915 // Determine whether the set of unexpanded parameter packs can and should
9916 // be expanded.
9917 bool Expand = true;
9918 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009919 Optional<unsigned> OrigNumExpansions =
9920 ExpansionTL.getTypePtr()->getNumExpansions();
9921 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009922 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9923 PatternTL.getSourceRange(),
9924 Unexpanded,
9925 Expand, RetainExpansion,
9926 NumExpansions))
9927 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009928
Douglas Gregor29c42f22012-02-24 07:38:34 +00009929 if (!Expand) {
9930 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009931 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009932 // expansion.
9933 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009934
Douglas Gregor29c42f22012-02-24 07:38:34 +00009935 TypeLocBuilder TLB;
9936 TLB.reserve(From->getTypeLoc().getFullDataSize());
9937
9938 QualType To = getDerived().TransformType(TLB, PatternTL);
9939 if (To.isNull())
9940 return ExprError();
9941
Chad Rosier1dcde962012-08-08 18:46:20 +00009942 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009943 PatternTL.getSourceRange(),
9944 ExpansionTL.getEllipsisLoc(),
9945 NumExpansions);
9946 if (To.isNull())
9947 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009948
Douglas Gregor29c42f22012-02-24 07:38:34 +00009949 PackExpansionTypeLoc ToExpansionTL
9950 = TLB.push<PackExpansionTypeLoc>(To);
9951 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9952 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9953 continue;
9954 }
9955
9956 // Expand the pack expansion by substituting for each argument in the
9957 // pack(s).
9958 for (unsigned I = 0; I != *NumExpansions; ++I) {
9959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9960 TypeLocBuilder TLB;
9961 TLB.reserve(PatternTL.getFullDataSize());
9962 QualType To = getDerived().TransformType(TLB, PatternTL);
9963 if (To.isNull())
9964 return ExprError();
9965
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009966 if (To->containsUnexpandedParameterPack()) {
9967 To = getDerived().RebuildPackExpansionType(To,
9968 PatternTL.getSourceRange(),
9969 ExpansionTL.getEllipsisLoc(),
9970 NumExpansions);
9971 if (To.isNull())
9972 return ExprError();
9973
9974 PackExpansionTypeLoc ToExpansionTL
9975 = TLB.push<PackExpansionTypeLoc>(To);
9976 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9977 }
9978
Douglas Gregor29c42f22012-02-24 07:38:34 +00009979 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009981
Douglas Gregor29c42f22012-02-24 07:38:34 +00009982 if (!RetainExpansion)
9983 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009984
Douglas Gregor29c42f22012-02-24 07:38:34 +00009985 // If we're supposed to retain a pack expansion, do so by temporarily
9986 // forgetting the partially-substituted parameter pack.
9987 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9988
9989 TypeLocBuilder TLB;
9990 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009991
Douglas Gregor29c42f22012-02-24 07:38:34 +00009992 QualType To = getDerived().TransformType(TLB, PatternTL);
9993 if (To.isNull())
9994 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009995
9996 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009997 PatternTL.getSourceRange(),
9998 ExpansionTL.getEllipsisLoc(),
9999 NumExpansions);
10000 if (To.isNull())
10001 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010002
Douglas Gregor29c42f22012-02-24 07:38:34 +000010003 PackExpansionTypeLoc ToExpansionTL
10004 = TLB.push<PackExpansionTypeLoc>(To);
10005 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10006 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10007 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010008
Douglas Gregor29c42f22012-02-24 07:38:34 +000010009 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010010 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010011
10012 return getDerived().RebuildTypeTrait(E->getTrait(),
10013 E->getLocStart(),
10014 Args,
10015 E->getLocEnd());
10016}
10017
10018template<typename Derived>
10019ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010020TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10021 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10022 if (!T)
10023 return ExprError();
10024
10025 if (!getDerived().AlwaysRebuild() &&
10026 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010027 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010028
10029 ExprResult SubExpr;
10030 {
10031 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10032 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10033 if (SubExpr.isInvalid())
10034 return ExprError();
10035
10036 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010037 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010038 }
10039
10040 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10041 E->getLocStart(),
10042 T,
10043 SubExpr.get(),
10044 E->getLocEnd());
10045}
10046
10047template<typename Derived>
10048ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010049TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10050 ExprResult SubExpr;
10051 {
10052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10053 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10054 if (SubExpr.isInvalid())
10055 return ExprError();
10056
10057 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010058 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010059 }
10060
10061 return getDerived().RebuildExpressionTrait(
10062 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10063}
10064
Reid Kleckner32506ed2014-06-12 23:03:48 +000010065template <typename Derived>
10066ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10067 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10068 TypeSourceInfo **RecoveryTSI) {
10069 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10070 DRE, AddrTaken, RecoveryTSI);
10071
10072 // Propagate both errors and recovered types, which return ExprEmpty.
10073 if (!NewDRE.isUsable())
10074 return NewDRE;
10075
10076 // We got an expr, wrap it up in parens.
10077 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10078 return PE;
10079 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10080 PE->getRParen());
10081}
10082
10083template <typename Derived>
10084ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10085 DependentScopeDeclRefExpr *E) {
10086 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10087 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010088}
10089
10090template<typename Derived>
10091ExprResult
10092TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10093 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010094 bool IsAddressOfOperand,
10095 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010096 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010097 NestedNameSpecifierLoc QualifierLoc
10098 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10099 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010100 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010101 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010102
John McCall31f82722010-11-12 08:19:04 +000010103 // TODO: If this is a conversion-function-id, verify that the
10104 // destination type name (if present) resolves the same way after
10105 // instantiation as it did in the local scope.
10106
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010107 DeclarationNameInfo NameInfo
10108 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10109 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010111
John McCalle66edc12009-11-24 19:00:30 +000010112 if (!E->hasExplicitTemplateArgs()) {
10113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010114 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010115 // Note: it is sufficient to compare the Name component of NameInfo:
10116 // if name has not changed, DNLoc has not changed either.
10117 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010118 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010119
Reid Kleckner32506ed2014-06-12 23:03:48 +000010120 return getDerived().RebuildDependentScopeDeclRefExpr(
10121 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10122 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010123 }
John McCall6b51f282009-11-23 01:53:49 +000010124
10125 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010126 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10127 E->getNumTemplateArgs(),
10128 TransArgs))
10129 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010130
Reid Kleckner32506ed2014-06-12 23:03:48 +000010131 return getDerived().RebuildDependentScopeDeclRefExpr(
10132 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10133 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010134}
10135
10136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010137ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010138TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010139 // CXXConstructExprs other than for list-initialization and
10140 // CXXTemporaryObjectExpr are always implicit, so when we have
10141 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010142 if ((E->getNumArgs() == 1 ||
10143 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010144 (!getDerived().DropCallArgument(E->getArg(0))) &&
10145 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010146 return getDerived().TransformExpr(E->getArg(0));
10147
Douglas Gregora16548e2009-08-11 05:31:07 +000010148 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10149
10150 QualType T = getDerived().TransformType(E->getType());
10151 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010152 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010153
10154 CXXConstructorDecl *Constructor
10155 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010156 getDerived().TransformDecl(E->getLocStart(),
10157 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010158 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010160
Douglas Gregora16548e2009-08-11 05:31:07 +000010161 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010162 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010163 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010164 &ArgumentChanged))
10165 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010166
Douglas Gregora16548e2009-08-11 05:31:07 +000010167 if (!getDerived().AlwaysRebuild() &&
10168 T == E->getType() &&
10169 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010170 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010171 // Mark the constructor as referenced.
10172 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010173 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010174 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010175 }
Mike Stump11289f42009-09-09 15:08:12 +000010176
Douglas Gregordb121ba2009-12-14 16:27:04 +000010177 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010178 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010179 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010180 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010181 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010182 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010183 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010184 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010185 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010186}
Mike Stump11289f42009-09-09 15:08:12 +000010187
Richard Smith5179eb72016-06-28 19:03:57 +000010188template<typename Derived>
10189ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10190 CXXInheritedCtorInitExpr *E) {
10191 QualType T = getDerived().TransformType(E->getType());
10192 if (T.isNull())
10193 return ExprError();
10194
10195 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10196 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10197 if (!Constructor)
10198 return ExprError();
10199
10200 if (!getDerived().AlwaysRebuild() &&
10201 T == E->getType() &&
10202 Constructor == E->getConstructor()) {
10203 // Mark the constructor as referenced.
10204 // FIXME: Instantiation-specific
10205 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10206 return E;
10207 }
10208
10209 return getDerived().RebuildCXXInheritedCtorInitExpr(
10210 T, E->getLocation(), Constructor,
10211 E->constructsVBase(), E->inheritedFromVBase());
10212}
10213
Douglas Gregora16548e2009-08-11 05:31:07 +000010214/// \brief Transform a C++ temporary-binding expression.
10215///
Douglas Gregor363b1512009-12-24 18:51:59 +000010216/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10217/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010220TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010221 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010222}
Mike Stump11289f42009-09-09 15:08:12 +000010223
John McCall5d413782010-12-06 08:20:24 +000010224/// \brief Transform a C++ expression that contains cleanups that should
10225/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010226///
John McCall5d413782010-12-06 08:20:24 +000010227/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010228/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010230ExprResult
John McCall5d413782010-12-06 08:20:24 +000010231TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010232 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010233}
Mike Stump11289f42009-09-09 15:08:12 +000010234
Douglas Gregora16548e2009-08-11 05:31:07 +000010235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010236ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010237TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010238 CXXTemporaryObjectExpr *E) {
10239 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10240 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010242
Douglas Gregora16548e2009-08-11 05:31:07 +000010243 CXXConstructorDecl *Constructor
10244 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010245 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010246 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010247 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010249
Douglas Gregora16548e2009-08-11 05:31:07 +000010250 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010251 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010252 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010253 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010254 &ArgumentChanged))
10255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010256
Douglas Gregora16548e2009-08-11 05:31:07 +000010257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010258 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010259 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010260 !ArgumentChanged) {
10261 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010262 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010263 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010264 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010265
Richard Smithd59b8322012-12-19 01:39:02 +000010266 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010267 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10268 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010269 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010270 E->getLocEnd());
10271}
Mike Stump11289f42009-09-09 15:08:12 +000010272
Douglas Gregora16548e2009-08-11 05:31:07 +000010273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010274ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010275TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010276 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010277 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010278 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010279 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10280 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010281 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010282 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010283 CEnd = E->capture_end();
10284 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010285 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010286 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010287 EnterExpressionEvaluationContext EEEC(getSema(),
10288 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010289 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10290 C->getCapturedVar()->getInit(),
10291 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010292
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010293 if (NewExprInitResult.isInvalid())
10294 return ExprError();
10295 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010296
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010297 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010298 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010299 getSema().buildLambdaInitCaptureInitialization(
10300 C->getLocation(), OldVD->getType()->isReferenceType(),
10301 OldVD->getIdentifier(),
10302 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010303 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010304 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10305 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010306 }
10307
Faisal Vali2cba1332013-10-23 06:44:28 +000010308 // Transform the template parameters, and add them to the current
10309 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010310 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010311 E->getTemplateParameterList());
10312
Richard Smith01014ce2014-11-20 23:53:14 +000010313 // Transform the type of the original lambda's call operator.
10314 // The transformation MUST be done in the CurrentInstantiationScope since
10315 // it introduces a mapping of the original to the newly created
10316 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010317 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010318 {
10319 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10320 FunctionProtoTypeLoc OldCallOpFPTL =
10321 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010322
10323 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010324 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010325 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010326 QualType NewCallOpType = TransformFunctionProtoType(
10327 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010328 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10329 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10330 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010331 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010332 if (NewCallOpType.isNull())
10333 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010334 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10335 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010336 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010337
Richard Smithc38498f2015-04-27 21:27:54 +000010338 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10339 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10340 LSI->GLTemplateParameterList = TPL;
10341
Eli Friedmand564afb2012-09-19 01:18:11 +000010342 // Create the local class that will describe the lambda.
10343 CXXRecordDecl *Class
10344 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010345 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010346 /*KnownDependent=*/false,
10347 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010348 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10349
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010350 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010351 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10352 Class, E->getIntroducerRange(), NewCallOpTSI,
10353 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010354 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10355 E->getCallOperator()->isConstexpr());
10356
Faisal Vali2cba1332013-10-23 06:44:28 +000010357 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010358
Akira Hatanaka402818462016-12-16 21:16:57 +000010359 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10360 I != NumParams; ++I) {
10361 auto *P = NewCallOperator->getParamDecl(I);
10362 if (P->hasUninstantiatedDefaultArg()) {
10363 EnterExpressionEvaluationContext Eval(
10364 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10365 ExprResult R = getDerived().TransformExpr(
10366 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10367 P->setDefaultArg(R.get());
10368 }
10369 }
10370
Faisal Vali2cba1332013-10-23 06:44:28 +000010371 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010372 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010373
Douglas Gregorb4328232012-02-14 00:00:48 +000010374 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010375 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010376 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010377
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010378 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010379 getSema().buildLambdaScope(LSI, NewCallOperator,
10380 E->getIntroducerRange(),
10381 E->getCaptureDefault(),
10382 E->getCaptureDefaultLoc(),
10383 E->hasExplicitParameters(),
10384 E->hasExplicitResultType(),
10385 E->isMutable());
10386
10387 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010388
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010389 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010390 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010391 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010392 CEnd = E->capture_end();
10393 C != CEnd; ++C) {
10394 // When we hit the first implicit capture, tell Sema that we've finished
10395 // the list of explicit captures.
10396 if (!FinishedExplicitCaptures && C->isImplicit()) {
10397 getSema().finishLambdaExplicitCaptures(LSI);
10398 FinishedExplicitCaptures = true;
10399 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010400
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010401 // Capturing 'this' is trivial.
10402 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010403 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10404 /*BuildAndDiagnose*/ true, nullptr,
10405 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010406 continue;
10407 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010408 // Captured expression will be recaptured during captured variables
10409 // rebuilding.
10410 if (C->capturesVLAType())
10411 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010412
Richard Smithba71c082013-05-16 06:20:58 +000010413 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010414 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010415 InitCaptureInfoTy InitExprTypePair =
10416 InitCaptureExprsAndTypes[C - E->capture_begin()];
10417 ExprResult Init = InitExprTypePair.first;
10418 QualType InitQualType = InitExprTypePair.second;
10419 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010420 Invalid = true;
10421 continue;
10422 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010423 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010424 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010425 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10426 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010427 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010428 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010429 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010430 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010431 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010432 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010433 continue;
10434 }
10435
10436 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10437
Douglas Gregor3e308b12012-02-14 19:27:52 +000010438 // Determine the capture kind for Sema.
10439 Sema::TryCaptureKind Kind
10440 = C->isImplicit()? Sema::TryCapture_Implicit
10441 : C->getCaptureKind() == LCK_ByCopy
10442 ? Sema::TryCapture_ExplicitByVal
10443 : Sema::TryCapture_ExplicitByRef;
10444 SourceLocation EllipsisLoc;
10445 if (C->isPackExpansion()) {
10446 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10447 bool ShouldExpand = false;
10448 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010449 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010450 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10451 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010452 Unexpanded,
10453 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010454 NumExpansions)) {
10455 Invalid = true;
10456 continue;
10457 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010458
Douglas Gregor3e308b12012-02-14 19:27:52 +000010459 if (ShouldExpand) {
10460 // The transform has determined that we should perform an expansion;
10461 // transform and capture each of the arguments.
10462 // expansion of the pattern. Do so.
10463 VarDecl *Pack = C->getCapturedVar();
10464 for (unsigned I = 0; I != *NumExpansions; ++I) {
10465 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10466 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010467 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010468 Pack));
10469 if (!CapturedVar) {
10470 Invalid = true;
10471 continue;
10472 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010473
Douglas Gregor3e308b12012-02-14 19:27:52 +000010474 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010475 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10476 }
Richard Smith9467be42014-06-06 17:33:35 +000010477
10478 // FIXME: Retain a pack expansion if RetainExpansion is true.
10479
Douglas Gregor3e308b12012-02-14 19:27:52 +000010480 continue;
10481 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010482
Douglas Gregor3e308b12012-02-14 19:27:52 +000010483 EllipsisLoc = C->getEllipsisLoc();
10484 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010485
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010486 // Transform the captured variable.
10487 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010488 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010489 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010490 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010491 Invalid = true;
10492 continue;
10493 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010494
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010495 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010496 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10497 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010498 }
10499 if (!FinishedExplicitCaptures)
10500 getSema().finishLambdaExplicitCaptures(LSI);
10501
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010502 // Enter a new evaluation context to insulate the lambda from any
10503 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010504 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010505
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010506 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010507 StmtResult Body =
10508 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10509
10510 // ActOnLambda* will pop the function scope for us.
10511 FuncScopeCleanup.disable();
10512
Douglas Gregorb4328232012-02-14 00:00:48 +000010513 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010514 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010515 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010516 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010517 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010518 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010519
Richard Smithc38498f2015-04-27 21:27:54 +000010520 // Copy the LSI before ActOnFinishFunctionBody removes it.
10521 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10522 // the call operator.
10523 auto LSICopy = *LSI;
10524 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10525 /*IsInstantiation*/ true);
10526 SavedContext.pop();
10527
10528 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10529 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010530}
10531
10532template<typename Derived>
10533ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010534TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010535 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010536 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10537 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010539
Douglas Gregora16548e2009-08-11 05:31:07 +000010540 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010541 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010542 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010543 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010544 &ArgumentChanged))
10545 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010546
Douglas Gregora16548e2009-08-11 05:31:07 +000010547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010548 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010549 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010550 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010551
Douglas Gregora16548e2009-08-11 05:31:07 +000010552 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010553 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010554 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010555 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010556 E->getRParenLoc());
10557}
Mike Stump11289f42009-09-09 15:08:12 +000010558
Douglas Gregora16548e2009-08-11 05:31:07 +000010559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010560ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010561TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010562 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010563 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010564 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010565 Expr *OldBase;
10566 QualType BaseType;
10567 QualType ObjectType;
10568 if (!E->isImplicitAccess()) {
10569 OldBase = E->getBase();
10570 Base = getDerived().TransformExpr(OldBase);
10571 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010572 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010573
John McCall2d74de92009-12-01 22:10:20 +000010574 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010575 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010576 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010577 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010578 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010579 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010580 ObjectTy,
10581 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010582 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010583 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010584
John McCallba7bf592010-08-24 05:47:05 +000010585 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010586 BaseType = ((Expr*) Base.get())->getType();
10587 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010588 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010589 BaseType = getDerived().TransformType(E->getBaseType());
10590 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10591 }
Mike Stump11289f42009-09-09 15:08:12 +000010592
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010593 // Transform the first part of the nested-name-specifier that qualifies
10594 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010595 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010596 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010597 E->getFirstQualifierFoundInScope(),
10598 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010599
Douglas Gregore16af532011-02-28 18:50:33 +000010600 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010601 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010602 QualifierLoc
10603 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10604 ObjectType,
10605 FirstQualifierInScope);
10606 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010607 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010608 }
Mike Stump11289f42009-09-09 15:08:12 +000010609
Abramo Bagnara7945c982012-01-27 09:46:47 +000010610 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10611
John McCall31f82722010-11-12 08:19:04 +000010612 // TODO: If this is a conversion-function-id, verify that the
10613 // destination type name (if present) resolves the same way after
10614 // instantiation as it did in the local scope.
10615
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010616 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010617 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010618 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010620
John McCall2d74de92009-12-01 22:10:20 +000010621 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010622 // This is a reference to a member without an explicitly-specified
10623 // template argument list. Optimize for this common case.
10624 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010625 Base.get() == OldBase &&
10626 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010627 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010628 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010629 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010630 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010631
John McCallb268a282010-08-23 23:25:46 +000010632 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010633 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010634 E->isArrow(),
10635 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010636 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010637 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010638 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010639 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010640 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010641 }
10642
John McCall6b51f282009-11-23 01:53:49 +000010643 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010644 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10645 E->getNumTemplateArgs(),
10646 TransArgs))
10647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010648
John McCallb268a282010-08-23 23:25:46 +000010649 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010650 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010651 E->isArrow(),
10652 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010653 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010654 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010655 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010656 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010657 &TransArgs);
10658}
10659
10660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010661ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010662TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010663 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010664 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010665 QualType BaseType;
10666 if (!Old->isImplicitAccess()) {
10667 Base = getDerived().TransformExpr(Old->getBase());
10668 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010669 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010670 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010671 Old->isArrow());
10672 if (Base.isInvalid())
10673 return ExprError();
10674 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010675 } else {
10676 BaseType = getDerived().TransformType(Old->getBaseType());
10677 }
John McCall10eae182009-11-30 22:42:35 +000010678
Douglas Gregor0da1d432011-02-28 20:01:57 +000010679 NestedNameSpecifierLoc QualifierLoc;
10680 if (Old->getQualifierLoc()) {
10681 QualifierLoc
10682 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10683 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010684 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010685 }
10686
Abramo Bagnara7945c982012-01-27 09:46:47 +000010687 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10688
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010689 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010690 Sema::LookupOrdinaryName);
10691
10692 // Transform all the decls.
10693 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10694 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010695 NamedDecl *InstD = static_cast<NamedDecl*>(
10696 getDerived().TransformDecl(Old->getMemberLoc(),
10697 *I));
John McCall84d87672009-12-10 09:41:52 +000010698 if (!InstD) {
10699 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10700 // This can happen because of dependent hiding.
10701 if (isa<UsingShadowDecl>(*I))
10702 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010703 else {
10704 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010705 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010706 }
John McCall84d87672009-12-10 09:41:52 +000010707 }
John McCall10eae182009-11-30 22:42:35 +000010708
10709 // Expand using declarations.
10710 if (isa<UsingDecl>(InstD)) {
10711 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010712 for (auto *I : UD->shadows())
10713 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010714 continue;
10715 }
10716
10717 R.addDecl(InstD);
10718 }
10719
10720 R.resolveKind();
10721
Douglas Gregor9262f472010-04-27 18:19:34 +000010722 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010723 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010724 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010725 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010726 Old->getMemberLoc(),
10727 Old->getNamingClass()));
10728 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010729 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010730
Douglas Gregorda7be082010-04-27 16:10:10 +000010731 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010732 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010733
John McCall10eae182009-11-30 22:42:35 +000010734 TemplateArgumentListInfo TransArgs;
10735 if (Old->hasExplicitTemplateArgs()) {
10736 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10737 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010738 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10739 Old->getNumTemplateArgs(),
10740 TransArgs))
10741 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010742 }
John McCall38836f02010-01-15 08:34:02 +000010743
10744 // FIXME: to do this check properly, we will need to preserve the
10745 // first-qualifier-in-scope here, just in case we had a dependent
10746 // base (and therefore couldn't do the check) and a
10747 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010748 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010749
John McCallb268a282010-08-23 23:25:46 +000010750 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010751 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010752 Old->getOperatorLoc(),
10753 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010754 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010755 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010756 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010757 R,
10758 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010759 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010760}
10761
10762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010763ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010764TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010765 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010766 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10767 if (SubExpr.isInvalid())
10768 return ExprError();
10769
10770 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010771 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010772
10773 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10774}
10775
10776template<typename Derived>
10777ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010778TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010779 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10780 if (Pattern.isInvalid())
10781 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010782
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010783 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010784 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010785
Douglas Gregorb8840002011-01-14 21:20:45 +000010786 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10787 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010788}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010789
10790template<typename Derived>
10791ExprResult
10792TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10793 // If E is not value-dependent, then nothing will change when we transform it.
10794 // Note: This is an instantiation-centric view.
10795 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010796 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010797
Richard Smithd784e682015-09-23 21:41:42 +000010798 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010799
Richard Smithd784e682015-09-23 21:41:42 +000010800 ArrayRef<TemplateArgument> PackArgs;
10801 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010802
Richard Smithd784e682015-09-23 21:41:42 +000010803 // Find the argument list to transform.
10804 if (E->isPartiallySubstituted()) {
10805 PackArgs = E->getPartialArguments();
10806 } else if (E->isValueDependent()) {
10807 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10808 bool ShouldExpand = false;
10809 bool RetainExpansion = false;
10810 Optional<unsigned> NumExpansions;
10811 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10812 Unexpanded,
10813 ShouldExpand, RetainExpansion,
10814 NumExpansions))
10815 return ExprError();
10816
10817 // If we need to expand the pack, build a template argument from it and
10818 // expand that.
10819 if (ShouldExpand) {
10820 auto *Pack = E->getPack();
10821 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10822 ArgStorage = getSema().Context.getPackExpansionType(
10823 getSema().Context.getTypeDeclType(TTPD), None);
10824 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10825 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10826 } else {
10827 auto *VD = cast<ValueDecl>(Pack);
10828 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10829 VK_RValue, E->getPackLoc());
10830 if (DRE.isInvalid())
10831 return ExprError();
10832 ArgStorage = new (getSema().Context) PackExpansionExpr(
10833 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10834 }
10835 PackArgs = ArgStorage;
10836 }
10837 }
10838
10839 // If we're not expanding the pack, just transform the decl.
10840 if (!PackArgs.size()) {
10841 auto *Pack = cast_or_null<NamedDecl>(
10842 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010843 if (!Pack)
10844 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010845 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10846 E->getPackLoc(),
10847 E->getRParenLoc(), None, None);
10848 }
10849
Richard Smithc5452ed2016-10-19 22:18:42 +000010850 // Try to compute the result without performing a partial substitution.
10851 Optional<unsigned> Result = 0;
10852 for (const TemplateArgument &Arg : PackArgs) {
10853 if (!Arg.isPackExpansion()) {
10854 Result = *Result + 1;
10855 continue;
10856 }
10857
10858 TemplateArgumentLoc ArgLoc;
10859 InventTemplateArgumentLoc(Arg, ArgLoc);
10860
10861 // Find the pattern of the pack expansion.
10862 SourceLocation Ellipsis;
10863 Optional<unsigned> OrigNumExpansions;
10864 TemplateArgumentLoc Pattern =
10865 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10866 OrigNumExpansions);
10867
10868 // Substitute under the pack expansion. Do not expand the pack (yet).
10869 TemplateArgumentLoc OutPattern;
10870 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10871 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10872 /*Uneval*/ true))
10873 return true;
10874
10875 // See if we can determine the number of arguments from the result.
10876 Optional<unsigned> NumExpansions =
10877 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10878 if (!NumExpansions) {
10879 // No: we must be in an alias template expansion, and we're going to need
10880 // to actually expand the packs.
10881 Result = None;
10882 break;
10883 }
10884
10885 Result = *Result + *NumExpansions;
10886 }
10887
10888 // Common case: we could determine the number of expansions without
10889 // substituting.
10890 if (Result)
10891 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10892 E->getPackLoc(),
10893 E->getRParenLoc(), *Result, None);
10894
Richard Smithd784e682015-09-23 21:41:42 +000010895 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10896 E->getPackLoc());
10897 {
10898 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10899 typedef TemplateArgumentLocInventIterator<
10900 Derived, const TemplateArgument*> PackLocIterator;
10901 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10902 PackLocIterator(*this, PackArgs.end()),
10903 TransformedPackArgs, /*Uneval*/true))
10904 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010905 }
10906
Richard Smithc5452ed2016-10-19 22:18:42 +000010907 // Check whether we managed to fully-expand the pack.
10908 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000010909 SmallVector<TemplateArgument, 8> Args;
10910 bool PartialSubstitution = false;
10911 for (auto &Loc : TransformedPackArgs.arguments()) {
10912 Args.push_back(Loc.getArgument());
10913 if (Loc.getArgument().isPackExpansion())
10914 PartialSubstitution = true;
10915 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010916
Richard Smithd784e682015-09-23 21:41:42 +000010917 if (PartialSubstitution)
10918 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10919 E->getPackLoc(),
10920 E->getRParenLoc(), None, Args);
10921
10922 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010923 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010924 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010925}
10926
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010927template<typename Derived>
10928ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010929TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10930 SubstNonTypeTemplateParmPackExpr *E) {
10931 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010932 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010933}
10934
10935template<typename Derived>
10936ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010937TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10938 SubstNonTypeTemplateParmExpr *E) {
10939 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010940 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010941}
10942
10943template<typename Derived>
10944ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010945TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10946 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010947 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010948}
10949
10950template<typename Derived>
10951ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010952TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10953 MaterializeTemporaryExpr *E) {
10954 return getDerived().TransformExpr(E->GetTemporaryExpr());
10955}
Chad Rosier1dcde962012-08-08 18:46:20 +000010956
Douglas Gregorfe314812011-06-21 17:03:29 +000010957template<typename Derived>
10958ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010959TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10960 Expr *Pattern = E->getPattern();
10961
10962 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10963 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10964 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10965
10966 // Determine whether the set of unexpanded parameter packs can and should
10967 // be expanded.
10968 bool Expand = true;
10969 bool RetainExpansion = false;
10970 Optional<unsigned> NumExpansions;
10971 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10972 Pattern->getSourceRange(),
10973 Unexpanded,
10974 Expand, RetainExpansion,
10975 NumExpansions))
10976 return true;
10977
10978 if (!Expand) {
10979 // Do not expand any packs here, just transform and rebuild a fold
10980 // expression.
10981 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10982
10983 ExprResult LHS =
10984 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10985 if (LHS.isInvalid())
10986 return true;
10987
10988 ExprResult RHS =
10989 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10990 if (RHS.isInvalid())
10991 return true;
10992
10993 if (!getDerived().AlwaysRebuild() &&
10994 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10995 return E;
10996
10997 return getDerived().RebuildCXXFoldExpr(
10998 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10999 RHS.get(), E->getLocEnd());
11000 }
11001
11002 // The transform has determined that we should perform an elementwise
11003 // expansion of the pattern. Do so.
11004 ExprResult Result = getDerived().TransformExpr(E->getInit());
11005 if (Result.isInvalid())
11006 return true;
11007 bool LeftFold = E->isLeftFold();
11008
11009 // If we're retaining an expansion for a right fold, it is the innermost
11010 // component and takes the init (if any).
11011 if (!LeftFold && RetainExpansion) {
11012 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11013
11014 ExprResult Out = getDerived().TransformExpr(Pattern);
11015 if (Out.isInvalid())
11016 return true;
11017
11018 Result = getDerived().RebuildCXXFoldExpr(
11019 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11020 Result.get(), E->getLocEnd());
11021 if (Result.isInvalid())
11022 return true;
11023 }
11024
11025 for (unsigned I = 0; I != *NumExpansions; ++I) {
11026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11027 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11028 ExprResult Out = getDerived().TransformExpr(Pattern);
11029 if (Out.isInvalid())
11030 return true;
11031
11032 if (Out.get()->containsUnexpandedParameterPack()) {
11033 // We still have a pack; retain a pack expansion for this slice.
11034 Result = getDerived().RebuildCXXFoldExpr(
11035 E->getLocStart(),
11036 LeftFold ? Result.get() : Out.get(),
11037 E->getOperator(), E->getEllipsisLoc(),
11038 LeftFold ? Out.get() : Result.get(),
11039 E->getLocEnd());
11040 } else if (Result.isUsable()) {
11041 // We've got down to a single element; build a binary operator.
11042 Result = getDerived().RebuildBinaryOperator(
11043 E->getEllipsisLoc(), E->getOperator(),
11044 LeftFold ? Result.get() : Out.get(),
11045 LeftFold ? Out.get() : Result.get());
11046 } else
11047 Result = Out;
11048
11049 if (Result.isInvalid())
11050 return true;
11051 }
11052
11053 // If we're retaining an expansion for a left fold, it is the outermost
11054 // component and takes the complete expansion so far as its init (if any).
11055 if (LeftFold && RetainExpansion) {
11056 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11057
11058 ExprResult Out = getDerived().TransformExpr(Pattern);
11059 if (Out.isInvalid())
11060 return true;
11061
11062 Result = getDerived().RebuildCXXFoldExpr(
11063 E->getLocStart(), Result.get(),
11064 E->getOperator(), E->getEllipsisLoc(),
11065 Out.get(), E->getLocEnd());
11066 if (Result.isInvalid())
11067 return true;
11068 }
11069
11070 // If we had no init and an empty pack, and we're not retaining an expansion,
11071 // then produce a fallback value or error.
11072 if (Result.isUnset())
11073 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11074 E->getOperator());
11075
11076 return Result;
11077}
11078
11079template<typename Derived>
11080ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011081TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11082 CXXStdInitializerListExpr *E) {
11083 return getDerived().TransformExpr(E->getSubExpr());
11084}
11085
11086template<typename Derived>
11087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011088TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011089 return SemaRef.MaybeBindToTemporary(E);
11090}
11091
11092template<typename Derived>
11093ExprResult
11094TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011095 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011096}
11097
11098template<typename Derived>
11099ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011100TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11102 if (SubExpr.isInvalid())
11103 return ExprError();
11104
11105 if (!getDerived().AlwaysRebuild() &&
11106 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011107 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011108
11109 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011110}
11111
11112template<typename Derived>
11113ExprResult
11114TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11115 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011116 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011117 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011118 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011119 /*IsCall=*/false, Elements, &ArgChanged))
11120 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011121
Ted Kremeneke65b0862012-03-06 20:05:56 +000011122 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11123 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011124
Ted Kremeneke65b0862012-03-06 20:05:56 +000011125 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11126 Elements.data(),
11127 Elements.size());
11128}
11129
11130template<typename Derived>
11131ExprResult
11132TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011133 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011134 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011135 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011136 bool ArgChanged = false;
11137 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11138 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011139
Ted Kremeneke65b0862012-03-06 20:05:56 +000011140 if (OrigElement.isPackExpansion()) {
11141 // This key/value element is a pack expansion.
11142 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11143 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11144 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11145 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11146
11147 // Determine whether the set of unexpanded parameter packs can
11148 // and should be expanded.
11149 bool Expand = true;
11150 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011151 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11152 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011153 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11154 OrigElement.Value->getLocEnd());
11155 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11156 PatternRange,
11157 Unexpanded,
11158 Expand, RetainExpansion,
11159 NumExpansions))
11160 return ExprError();
11161
11162 if (!Expand) {
11163 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011164 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011165 // expansion.
11166 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11167 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11168 if (Key.isInvalid())
11169 return ExprError();
11170
11171 if (Key.get() != OrigElement.Key)
11172 ArgChanged = true;
11173
11174 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11175 if (Value.isInvalid())
11176 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011177
Ted Kremeneke65b0862012-03-06 20:05:56 +000011178 if (Value.get() != OrigElement.Value)
11179 ArgChanged = true;
11180
Chad Rosier1dcde962012-08-08 18:46:20 +000011181 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011182 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11183 };
11184 Elements.push_back(Expansion);
11185 continue;
11186 }
11187
11188 // Record right away that the argument was changed. This needs
11189 // to happen even if the array expands to nothing.
11190 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011191
Ted Kremeneke65b0862012-03-06 20:05:56 +000011192 // The transform has determined that we should perform an elementwise
11193 // expansion of the pattern. Do so.
11194 for (unsigned I = 0; I != *NumExpansions; ++I) {
11195 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11196 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11197 if (Key.isInvalid())
11198 return ExprError();
11199
11200 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11201 if (Value.isInvalid())
11202 return ExprError();
11203
Chad Rosier1dcde962012-08-08 18:46:20 +000011204 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011205 Key.get(), Value.get(), SourceLocation(), NumExpansions
11206 };
11207
11208 // If any unexpanded parameter packs remain, we still have a
11209 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011210 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011211 if (Key.get()->containsUnexpandedParameterPack() ||
11212 Value.get()->containsUnexpandedParameterPack())
11213 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011214
Ted Kremeneke65b0862012-03-06 20:05:56 +000011215 Elements.push_back(Element);
11216 }
11217
Richard Smith9467be42014-06-06 17:33:35 +000011218 // FIXME: Retain a pack expansion if RetainExpansion is true.
11219
Ted Kremeneke65b0862012-03-06 20:05:56 +000011220 // We've finished with this pack expansion.
11221 continue;
11222 }
11223
11224 // Transform and check key.
11225 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11226 if (Key.isInvalid())
11227 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011228
Ted Kremeneke65b0862012-03-06 20:05:56 +000011229 if (Key.get() != OrigElement.Key)
11230 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011231
Ted Kremeneke65b0862012-03-06 20:05:56 +000011232 // Transform and check value.
11233 ExprResult Value
11234 = getDerived().TransformExpr(OrigElement.Value);
11235 if (Value.isInvalid())
11236 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011237
Ted Kremeneke65b0862012-03-06 20:05:56 +000011238 if (Value.get() != OrigElement.Value)
11239 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011240
11241 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011242 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011243 };
11244 Elements.push_back(Element);
11245 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011246
Ted Kremeneke65b0862012-03-06 20:05:56 +000011247 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11248 return SemaRef.MaybeBindToTemporary(E);
11249
11250 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011251 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011252}
11253
Mike Stump11289f42009-09-09 15:08:12 +000011254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011256TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011257 TypeSourceInfo *EncodedTypeInfo
11258 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11259 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011261
Douglas Gregora16548e2009-08-11 05:31:07 +000011262 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011263 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011264 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011265
11266 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011267 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011268 E->getRParenLoc());
11269}
Mike Stump11289f42009-09-09 15:08:12 +000011270
Douglas Gregora16548e2009-08-11 05:31:07 +000011271template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011272ExprResult TreeTransform<Derived>::
11273TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011274 // This is a kind of implicit conversion, and it needs to get dropped
11275 // and recomputed for the same general reasons that ImplicitCastExprs
11276 // do, as well a more specific one: this expression is only valid when
11277 // it appears *immediately* as an argument expression.
11278 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011279}
11280
11281template<typename Derived>
11282ExprResult TreeTransform<Derived>::
11283TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011284 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011285 = getDerived().TransformType(E->getTypeInfoAsWritten());
11286 if (!TSInfo)
11287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011288
John McCall31168b02011-06-15 23:02:42 +000011289 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011290 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011291 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011292
John McCall31168b02011-06-15 23:02:42 +000011293 if (!getDerived().AlwaysRebuild() &&
11294 TSInfo == E->getTypeInfoAsWritten() &&
11295 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011296 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011297
John McCall31168b02011-06-15 23:02:42 +000011298 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011299 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011300 Result.get());
11301}
11302
Erik Pilkington29099de2016-07-16 00:35:23 +000011303template <typename Derived>
11304ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11305 ObjCAvailabilityCheckExpr *E) {
11306 return E;
11307}
11308
John McCall31168b02011-06-15 23:02:42 +000011309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011310ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011311TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011312 // Transform arguments.
11313 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011314 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011315 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011316 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011317 &ArgChanged))
11318 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011319
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011320 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11321 // Class message: transform the receiver type.
11322 TypeSourceInfo *ReceiverTypeInfo
11323 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11324 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011325 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011326
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011327 // If nothing changed, just retain the existing message send.
11328 if (!getDerived().AlwaysRebuild() &&
11329 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011330 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011331
11332 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011333 SmallVector<SourceLocation, 16> SelLocs;
11334 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011335 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11336 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011337 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011338 E->getMethodDecl(),
11339 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011340 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011341 E->getRightLoc());
11342 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011343 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11344 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011345 if (!E->getMethodDecl())
11346 return ExprError();
11347
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011348 // Build a new class message send to 'super'.
11349 SmallVector<SourceLocation, 16> SelLocs;
11350 E->getSelectorLocs(SelLocs);
11351 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11352 E->getSelector(),
11353 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011354 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011355 E->getMethodDecl(),
11356 E->getLeftLoc(),
11357 Args,
11358 E->getRightLoc());
11359 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011360
11361 // Instance message: transform the receiver
11362 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11363 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011364 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011365 = getDerived().TransformExpr(E->getInstanceReceiver());
11366 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011367 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011368
11369 // If nothing changed, just retain the existing message send.
11370 if (!getDerived().AlwaysRebuild() &&
11371 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011372 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011373
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011374 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011375 SmallVector<SourceLocation, 16> SelLocs;
11376 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011377 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011378 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011379 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011380 E->getMethodDecl(),
11381 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011382 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011383 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011384}
11385
Mike Stump11289f42009-09-09 15:08:12 +000011386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011387ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011388TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011389 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011390}
11391
Mike Stump11289f42009-09-09 15:08:12 +000011392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011393ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011394TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011395 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011396}
11397
Mike Stump11289f42009-09-09 15:08:12 +000011398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011400TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011401 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011402 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011403 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011404 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011405
11406 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011407
Douglas Gregord51d90d2010-04-26 20:11:03 +000011408 // If nothing changed, just retain the existing expression.
11409 if (!getDerived().AlwaysRebuild() &&
11410 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011411 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011412
John McCallb268a282010-08-23 23:25:46 +000011413 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011414 E->getLocation(),
11415 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011416}
11417
Mike Stump11289f42009-09-09 15:08:12 +000011418template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011419ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011420TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011421 // 'super' and types never change. Property never changes. Just
11422 // retain the existing expression.
11423 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011424 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011425
Douglas Gregor9faee212010-04-26 20:47:02 +000011426 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011427 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011428 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011429 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011430
Douglas Gregor9faee212010-04-26 20:47:02 +000011431 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011432
Douglas Gregor9faee212010-04-26 20:47:02 +000011433 // If nothing changed, just retain the existing expression.
11434 if (!getDerived().AlwaysRebuild() &&
11435 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011436 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011437
John McCallb7bd14f2010-12-02 01:19:52 +000011438 if (E->isExplicitProperty())
11439 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11440 E->getExplicitProperty(),
11441 E->getLocation());
11442
11443 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011444 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011445 E->getImplicitPropertyGetter(),
11446 E->getImplicitPropertySetter(),
11447 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011448}
11449
Mike Stump11289f42009-09-09 15:08:12 +000011450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011451ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011452TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11453 // Transform the base expression.
11454 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11455 if (Base.isInvalid())
11456 return ExprError();
11457
11458 // Transform the key expression.
11459 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11460 if (Key.isInvalid())
11461 return ExprError();
11462
11463 // If nothing changed, just retain the existing expression.
11464 if (!getDerived().AlwaysRebuild() &&
11465 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011466 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011467
Chad Rosier1dcde962012-08-08 18:46:20 +000011468 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011469 Base.get(), Key.get(),
11470 E->getAtIndexMethodDecl(),
11471 E->setAtIndexMethodDecl());
11472}
11473
11474template<typename Derived>
11475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011476TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011477 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011478 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011479 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011480 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011481
Douglas Gregord51d90d2010-04-26 20:11:03 +000011482 // If nothing changed, just retain the existing expression.
11483 if (!getDerived().AlwaysRebuild() &&
11484 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011485 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011486
John McCallb268a282010-08-23 23:25:46 +000011487 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011488 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011489 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011490}
11491
Mike Stump11289f42009-09-09 15:08:12 +000011492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011493ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011494TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011495 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011496 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011497 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011498 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011499 SubExprs, &ArgumentChanged))
11500 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011501
Douglas Gregora16548e2009-08-11 05:31:07 +000011502 if (!getDerived().AlwaysRebuild() &&
11503 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011504 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011505
Douglas Gregora16548e2009-08-11 05:31:07 +000011506 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011507 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011508 E->getRParenLoc());
11509}
11510
Mike Stump11289f42009-09-09 15:08:12 +000011511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011512ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011513TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11514 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11515 if (SrcExpr.isInvalid())
11516 return ExprError();
11517
11518 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11519 if (!Type)
11520 return ExprError();
11521
11522 if (!getDerived().AlwaysRebuild() &&
11523 Type == E->getTypeSourceInfo() &&
11524 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011525 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011526
11527 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11528 SrcExpr.get(), Type,
11529 E->getRParenLoc());
11530}
11531
11532template<typename Derived>
11533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011534TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011535 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011536
Craig Topperc3ec1492014-05-26 06:22:03 +000011537 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011538 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11539
11540 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011541 blockScope->TheDecl->setBlockMissingReturnType(
11542 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011543
Chris Lattner01cf8db2011-07-20 06:58:45 +000011544 SmallVector<ParmVarDecl*, 4> params;
11545 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011546
John McCallc8e321d2016-03-01 02:09:25 +000011547 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11548
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011549 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011550 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011551 if (getDerived().TransformFunctionTypeParams(
11552 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11553 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11554 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011555 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011556 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011557 }
John McCall490112f2011-02-04 18:33:18 +000011558
Eli Friedman34b49062012-01-26 03:00:14 +000011559 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011560 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011561
John McCallc8e321d2016-03-01 02:09:25 +000011562 auto epi = exprFunctionType->getExtProtoInfo();
11563 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11564
Jordan Rose5c382722013-03-08 21:51:21 +000011565 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011566 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011567 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011568
11569 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011570 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011571 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011572
11573 if (!oldBlock->blockMissingReturnType()) {
11574 blockScope->HasImplicitReturnType = false;
11575 blockScope->ReturnType = exprResultType;
11576 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011577
John McCall3882ace2011-01-05 12:14:39 +000011578 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011579 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011580 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011581 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011582 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011583 }
John McCall3882ace2011-01-05 12:14:39 +000011584
John McCall490112f2011-02-04 18:33:18 +000011585#ifndef NDEBUG
11586 // In builds with assertions, make sure that we captured everything we
11587 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011588 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011589 for (const auto &I : oldBlock->captures()) {
11590 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011591
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011592 // Ignore parameter packs.
11593 if (isa<ParmVarDecl>(oldCapture) &&
11594 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11595 continue;
John McCall490112f2011-02-04 18:33:18 +000011596
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011597 VarDecl *newCapture =
11598 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11599 oldCapture));
11600 assert(blockScope->CaptureMap.count(newCapture));
11601 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011602 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011603 }
11604#endif
11605
11606 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011607 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011608}
11609
Mike Stump11289f42009-09-09 15:08:12 +000011610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011611ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011612TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011613 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011614}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011615
11616template<typename Derived>
11617ExprResult
11618TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011619 QualType RetTy = getDerived().TransformType(E->getType());
11620 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011621 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011622 SubExprs.reserve(E->getNumSubExprs());
11623 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11624 SubExprs, &ArgumentChanged))
11625 return ExprError();
11626
11627 if (!getDerived().AlwaysRebuild() &&
11628 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011629 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011630
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011631 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011632 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011633}
Chad Rosier1dcde962012-08-08 18:46:20 +000011634
Douglas Gregora16548e2009-08-11 05:31:07 +000011635//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011636// Type reconstruction
11637//===----------------------------------------------------------------------===//
11638
Mike Stump11289f42009-09-09 15:08:12 +000011639template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011640QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11641 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011642 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011643 getDerived().getBaseEntity());
11644}
11645
Mike Stump11289f42009-09-09 15:08:12 +000011646template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011647QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11648 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011649 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011650 getDerived().getBaseEntity());
11651}
11652
Mike Stump11289f42009-09-09 15:08:12 +000011653template<typename Derived>
11654QualType
John McCall70dd5f62009-10-30 00:06:24 +000011655TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11656 bool WrittenAsLValue,
11657 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011658 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011659 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011660}
11661
11662template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011663QualType
John McCall70dd5f62009-10-30 00:06:24 +000011664TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11665 QualType ClassType,
11666 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011667 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11668 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011669}
11670
11671template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011672QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11673 const ObjCTypeParamDecl *Decl,
11674 SourceLocation ProtocolLAngleLoc,
11675 ArrayRef<ObjCProtocolDecl *> Protocols,
11676 ArrayRef<SourceLocation> ProtocolLocs,
11677 SourceLocation ProtocolRAngleLoc) {
11678 return SemaRef.BuildObjCTypeParamType(Decl,
11679 ProtocolLAngleLoc, Protocols,
11680 ProtocolLocs, ProtocolRAngleLoc,
11681 /*FailOnError=*/true);
11682}
11683
11684template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011685QualType TreeTransform<Derived>::RebuildObjCObjectType(
11686 QualType BaseType,
11687 SourceLocation Loc,
11688 SourceLocation TypeArgsLAngleLoc,
11689 ArrayRef<TypeSourceInfo *> TypeArgs,
11690 SourceLocation TypeArgsRAngleLoc,
11691 SourceLocation ProtocolLAngleLoc,
11692 ArrayRef<ObjCProtocolDecl *> Protocols,
11693 ArrayRef<SourceLocation> ProtocolLocs,
11694 SourceLocation ProtocolRAngleLoc) {
11695 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11696 TypeArgs, TypeArgsRAngleLoc,
11697 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11698 ProtocolRAngleLoc,
11699 /*FailOnError=*/true);
11700}
11701
11702template<typename Derived>
11703QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11704 QualType PointeeType,
11705 SourceLocation Star) {
11706 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11707}
11708
11709template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011710QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011711TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11712 ArrayType::ArraySizeModifier SizeMod,
11713 const llvm::APInt *Size,
11714 Expr *SizeExpr,
11715 unsigned IndexTypeQuals,
11716 SourceRange BracketsRange) {
11717 if (SizeExpr || !Size)
11718 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11719 IndexTypeQuals, BracketsRange,
11720 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011721
11722 QualType Types[] = {
11723 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11724 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11725 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011726 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011727 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011728 QualType SizeType;
11729 for (unsigned I = 0; I != NumTypes; ++I)
11730 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11731 SizeType = Types[I];
11732 break;
11733 }
Mike Stump11289f42009-09-09 15:08:12 +000011734
Eli Friedman9562f392012-01-25 23:20:27 +000011735 // Note that we can return a VariableArrayType here in the case where
11736 // the element type was a dependent VariableArrayType.
11737 IntegerLiteral *ArraySize
11738 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11739 /*FIXME*/BracketsRange.getBegin());
11740 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011741 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011742 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011743}
Mike Stump11289f42009-09-09 15:08:12 +000011744
Douglas Gregord6ff3322009-08-04 16:50:30 +000011745template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011746QualType
11747TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011748 ArrayType::ArraySizeModifier SizeMod,
11749 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011750 unsigned IndexTypeQuals,
11751 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011752 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011753 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011754}
11755
11756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011757QualType
Mike Stump11289f42009-09-09 15:08:12 +000011758TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011759 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011760 unsigned IndexTypeQuals,
11761 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011762 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011763 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011764}
Mike Stump11289f42009-09-09 15:08:12 +000011765
Douglas Gregord6ff3322009-08-04 16:50:30 +000011766template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011767QualType
11768TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011769 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011770 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011771 unsigned IndexTypeQuals,
11772 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011773 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011774 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011775 IndexTypeQuals, BracketsRange);
11776}
11777
11778template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011779QualType
11780TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011781 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011782 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011783 unsigned IndexTypeQuals,
11784 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011785 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011786 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011787 IndexTypeQuals, BracketsRange);
11788}
11789
11790template<typename Derived>
11791QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011792 unsigned NumElements,
11793 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011794 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011795 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011796}
Mike Stump11289f42009-09-09 15:08:12 +000011797
Douglas Gregord6ff3322009-08-04 16:50:30 +000011798template<typename Derived>
11799QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11800 unsigned NumElements,
11801 SourceLocation AttributeLoc) {
11802 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11803 NumElements, true);
11804 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011805 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11806 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011807 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011808}
Mike Stump11289f42009-09-09 15:08:12 +000011809
Douglas Gregord6ff3322009-08-04 16:50:30 +000011810template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011811QualType
11812TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011813 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011814 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011815 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011816}
Mike Stump11289f42009-09-09 15:08:12 +000011817
Douglas Gregord6ff3322009-08-04 16:50:30 +000011818template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011819QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11820 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011821 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011822 const FunctionProtoType::ExtProtoInfo &EPI) {
11823 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011824 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011825 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011826 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011827}
Mike Stump11289f42009-09-09 15:08:12 +000011828
Douglas Gregord6ff3322009-08-04 16:50:30 +000011829template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011830QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11831 return SemaRef.Context.getFunctionNoProtoType(T);
11832}
11833
11834template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011835QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11836 assert(D && "no decl found");
11837 if (D->isInvalidDecl()) return QualType();
11838
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011839 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011840 TypeDecl *Ty;
11841 if (isa<UsingDecl>(D)) {
11842 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011843 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011844 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11845
11846 // A valid resolved using typename decl points to exactly one type decl.
11847 assert(++Using->shadow_begin() == Using->shadow_end());
11848 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011849
John McCallb96ec562009-12-04 22:46:56 +000011850 } else {
11851 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11852 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11853 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11854 }
11855
11856 return SemaRef.Context.getTypeDeclType(Ty);
11857}
11858
11859template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011860QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11861 SourceLocation Loc) {
11862 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011863}
11864
11865template<typename Derived>
11866QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11867 return SemaRef.Context.getTypeOfType(Underlying);
11868}
11869
11870template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011871QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11872 SourceLocation Loc) {
11873 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011874}
11875
11876template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011877QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11878 UnaryTransformType::UTTKind UKind,
11879 SourceLocation Loc) {
11880 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11881}
11882
11883template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011884QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011885 TemplateName Template,
11886 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011887 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011888 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011889}
Mike Stump11289f42009-09-09 15:08:12 +000011890
Douglas Gregor1135c352009-08-06 05:28:30 +000011891template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011892QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11893 SourceLocation KWLoc) {
11894 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11895}
11896
11897template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011898QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000011899 SourceLocation KWLoc,
11900 bool isReadPipe) {
11901 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11902 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000011903}
11904
11905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011906TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011907TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011908 bool TemplateKW,
11909 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011910 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011911 Template);
11912}
11913
11914template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011915TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011916TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11917 const IdentifierInfo &Name,
11918 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011919 QualType ObjectType,
11920 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011921 UnqualifiedId TemplateName;
11922 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011923 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011924 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011925 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011926 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011927 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011928 /*EnteringContext=*/false,
11929 Template);
John McCall31f82722010-11-12 08:19:04 +000011930 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011931}
Mike Stump11289f42009-09-09 15:08:12 +000011932
Douglas Gregora16548e2009-08-11 05:31:07 +000011933template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011934TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011935TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011936 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011937 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011938 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011939 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011940 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011941 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011942 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011943 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011944 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011945 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011946 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011947 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011948 /*EnteringContext=*/false,
11949 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011950 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011951}
Chad Rosier1dcde962012-08-08 18:46:20 +000011952
Douglas Gregor71395fa2009-11-04 00:56:37 +000011953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011954ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011955TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11956 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011957 Expr *OrigCallee,
11958 Expr *First,
11959 Expr *Second) {
11960 Expr *Callee = OrigCallee->IgnoreParenCasts();
11961 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011962
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011963 if (First->getObjectKind() == OK_ObjCProperty) {
11964 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11965 if (BinaryOperator::isAssignmentOp(Opc))
11966 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11967 First, Second);
11968 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11969 if (Result.isInvalid())
11970 return ExprError();
11971 First = Result.get();
11972 }
11973
11974 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11975 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11976 if (Result.isInvalid())
11977 return ExprError();
11978 Second = Result.get();
11979 }
11980
Douglas Gregora16548e2009-08-11 05:31:07 +000011981 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011982 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011983 if (!First->getType()->isOverloadableType() &&
11984 !Second->getType()->isOverloadableType())
11985 return getSema().CreateBuiltinArraySubscriptExpr(First,
11986 Callee->getLocStart(),
11987 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011988 } else if (Op == OO_Arrow) {
11989 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011990 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11991 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011992 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011993 // The argument is not of overloadable type, so try to create a
11994 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011995 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011996 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011997
John McCallb268a282010-08-23 23:25:46 +000011998 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011999 }
12000 } else {
John McCallb268a282010-08-23 23:25:46 +000012001 if (!First->getType()->isOverloadableType() &&
12002 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012003 // Neither of the arguments is an overloadable type, so try to
12004 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012005 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012006 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012007 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012008 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012010
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012011 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012012 }
12013 }
Mike Stump11289f42009-09-09 15:08:12 +000012014
12015 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012016 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012017 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012018
John McCallb268a282010-08-23 23:25:46 +000012019 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012020 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012021 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012022 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012023 // If we've resolved this to a particular non-member function, just call
12024 // that function. If we resolved it to a member function,
12025 // CreateOverloaded* will find that function for us.
12026 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12027 if (!isa<CXXMethodDecl>(ND))
12028 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012029 }
Mike Stump11289f42009-09-09 15:08:12 +000012030
Douglas Gregora16548e2009-08-11 05:31:07 +000012031 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012032 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012033 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012034
Douglas Gregora16548e2009-08-11 05:31:07 +000012035 // Create the overloaded operator invocation for unary operators.
12036 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012037 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012038 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012039 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012040 }
Mike Stump11289f42009-09-09 15:08:12 +000012041
Douglas Gregore9d62932011-07-15 16:25:15 +000012042 if (Op == OO_Subscript) {
12043 SourceLocation LBrace;
12044 SourceLocation RBrace;
12045
12046 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012047 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012048 LBrace = SourceLocation::getFromRawEncoding(
12049 NameLoc.CXXOperatorName.BeginOpNameLoc);
12050 RBrace = SourceLocation::getFromRawEncoding(
12051 NameLoc.CXXOperatorName.EndOpNameLoc);
12052 } else {
12053 LBrace = Callee->getLocStart();
12054 RBrace = OpLoc;
12055 }
12056
12057 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12058 First, Second);
12059 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012060
Douglas Gregora16548e2009-08-11 05:31:07 +000012061 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012062 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012063 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012064 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12065 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012067
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012068 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012069}
Mike Stump11289f42009-09-09 15:08:12 +000012070
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012071template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012072ExprResult
John McCallb268a282010-08-23 23:25:46 +000012073TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012074 SourceLocation OperatorLoc,
12075 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012076 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012077 TypeSourceInfo *ScopeType,
12078 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012079 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012080 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012081 QualType BaseType = Base->getType();
12082 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012083 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012084 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012085 !BaseType->getAs<PointerType>()->getPointeeType()
12086 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012087 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012088 return SemaRef.BuildPseudoDestructorExpr(
12089 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12090 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012091 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012092
Douglas Gregor678f90d2010-02-25 01:56:36 +000012093 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012094 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12095 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12096 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12097 NameInfo.setNamedTypeInfo(DestroyedType);
12098
Richard Smith8e4a3862012-05-15 06:15:11 +000012099 // The scope type is now known to be a valid nested name specifier
12100 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012101 if (ScopeType) {
12102 if (!ScopeType->getType()->getAs<TagType>()) {
12103 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12104 diag::err_expected_class_or_namespace)
12105 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12106 return ExprError();
12107 }
12108 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12109 CCLoc);
12110 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012111
Abramo Bagnara7945c982012-01-27 09:46:47 +000012112 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012113 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012114 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012115 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012116 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012117 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012118 /*TemplateArgs*/ nullptr,
12119 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012120}
12121
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012122template<typename Derived>
12123StmtResult
12124TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012125 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012126 CapturedDecl *CD = S->getCapturedDecl();
12127 unsigned NumParams = CD->getNumParams();
12128 unsigned ContextParamPos = CD->getContextParamPosition();
12129 SmallVector<Sema::CapturedParamNameType, 4> Params;
12130 for (unsigned I = 0; I < NumParams; ++I) {
12131 if (I != ContextParamPos) {
12132 Params.push_back(
12133 std::make_pair(
12134 CD->getParam(I)->getName(),
12135 getDerived().TransformType(CD->getParam(I)->getType())));
12136 } else {
12137 Params.push_back(std::make_pair(StringRef(), QualType()));
12138 }
12139 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012140 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012141 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012142 StmtResult Body;
12143 {
12144 Sema::CompoundScopeRAII CompoundScope(getSema());
12145 Body = getDerived().TransformStmt(S->getCapturedStmt());
12146 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012147
12148 if (Body.isInvalid()) {
12149 getSema().ActOnCapturedRegionError();
12150 return StmtError();
12151 }
12152
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012153 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012154}
12155
Douglas Gregord6ff3322009-08-04 16:50:30 +000012156} // end namespace clang
12157
Hans Wennborg59dbe862015-09-29 20:56:43 +000012158#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H