blob: a76a078fd006b742944f3d77b259cb257f88f4ce [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 Libf594a52016-12-17 05:48:59 +00007730template <typename Derived>
7731StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
7732 OMPTargetTeamsDirective *D) {
7733 DeclarationNameInfo DirName;
7734 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
7735 nullptr, D->getLocStart());
7736 auto Res = getDerived().TransformOMPExecutableDirective(D);
7737 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7738 return Res;
7739}
Kelvin Li579e41c2016-11-30 23:51:03 +00007740
Alexander Musman64d33f12014-06-04 07:53:32 +00007741//===----------------------------------------------------------------------===//
7742// OpenMP clause transformation
7743//===----------------------------------------------------------------------===//
7744template <typename Derived>
7745OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007746 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7747 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007748 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007749 return getDerived().RebuildOMPIfClause(
7750 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7751 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007752}
7753
Alexander Musman64d33f12014-06-04 07:53:32 +00007754template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007755OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7756 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7757 if (Cond.isInvalid())
7758 return nullptr;
7759 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7760 C->getLParenLoc(), C->getLocEnd());
7761}
7762
7763template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007764OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007765TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7766 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7767 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007768 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007769 return getDerived().RebuildOMPNumThreadsClause(
7770 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007771}
7772
Alexey Bataev62c87d22014-03-21 04:51:18 +00007773template <typename Derived>
7774OMPClause *
7775TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7776 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7777 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007778 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007779 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007780 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007781}
7782
Alexander Musman8bd31e62014-05-27 15:12:19 +00007783template <typename Derived>
7784OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007785TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7786 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7787 if (E.isInvalid())
7788 return nullptr;
7789 return getDerived().RebuildOMPSimdlenClause(
7790 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7791}
7792
7793template <typename Derived>
7794OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007795TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7796 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7797 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007798 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007799 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007800 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007801}
7802
Alexander Musman64d33f12014-06-04 07:53:32 +00007803template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007804OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007805TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007806 return getDerived().RebuildOMPDefaultClause(
7807 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7808 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007809}
7810
Alexander Musman64d33f12014-06-04 07:53:32 +00007811template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007812OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007813TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007814 return getDerived().RebuildOMPProcBindClause(
7815 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7816 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007817}
7818
Alexander Musman64d33f12014-06-04 07:53:32 +00007819template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007820OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007821TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7822 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7823 if (E.isInvalid())
7824 return nullptr;
7825 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00007826 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007827 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00007828 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00007829 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7830}
7831
7832template <typename Derived>
7833OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007834TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007835 ExprResult E;
7836 if (auto *Num = C->getNumForLoops()) {
7837 E = getDerived().TransformExpr(Num);
7838 if (E.isInvalid())
7839 return nullptr;
7840 }
7841 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7842 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007843}
7844
7845template <typename Derived>
7846OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007847TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7848 // No need to rebuild this clause, no template-dependent parameters.
7849 return C;
7850}
7851
7852template <typename Derived>
7853OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007854TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7855 // No need to rebuild this clause, no template-dependent parameters.
7856 return C;
7857}
7858
7859template <typename Derived>
7860OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007861TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7862 // No need to rebuild this clause, no template-dependent parameters.
7863 return C;
7864}
7865
7866template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007867OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7868 // No need to rebuild this clause, no template-dependent parameters.
7869 return C;
7870}
7871
7872template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007873OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7874 // No need to rebuild this clause, no template-dependent parameters.
7875 return C;
7876}
7877
7878template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007879OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007880TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7881 // No need to rebuild this clause, no template-dependent parameters.
7882 return C;
7883}
7884
7885template <typename Derived>
7886OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007887TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7888 // No need to rebuild this clause, no template-dependent parameters.
7889 return C;
7890}
7891
7892template <typename Derived>
7893OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007894TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7895 // No need to rebuild this clause, no template-dependent parameters.
7896 return C;
7897}
7898
7899template <typename Derived>
7900OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007901TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7902 // No need to rebuild this clause, no template-dependent parameters.
7903 return C;
7904}
7905
7906template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007907OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7908 // No need to rebuild this clause, no template-dependent parameters.
7909 return C;
7910}
7911
7912template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007913OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00007914TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
7915 // No need to rebuild this clause, no template-dependent parameters.
7916 return C;
7917}
7918
7919template <typename Derived>
7920OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007921TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007922 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007923 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007924 for (auto *VE : C->varlists()) {
7925 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007926 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007927 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007928 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007929 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007930 return getDerived().RebuildOMPPrivateClause(
7931 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007932}
7933
Alexander Musman64d33f12014-06-04 07:53:32 +00007934template <typename Derived>
7935OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7936 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007937 llvm::SmallVector<Expr *, 16> Vars;
7938 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007939 for (auto *VE : C->varlists()) {
7940 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007941 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007942 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007943 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007944 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007945 return getDerived().RebuildOMPFirstprivateClause(
7946 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007947}
7948
Alexander Musman64d33f12014-06-04 07:53:32 +00007949template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007950OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007951TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7952 llvm::SmallVector<Expr *, 16> Vars;
7953 Vars.reserve(C->varlist_size());
7954 for (auto *VE : C->varlists()) {
7955 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7956 if (EVar.isInvalid())
7957 return nullptr;
7958 Vars.push_back(EVar.get());
7959 }
7960 return getDerived().RebuildOMPLastprivateClause(
7961 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7962}
7963
7964template <typename Derived>
7965OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007966TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7967 llvm::SmallVector<Expr *, 16> Vars;
7968 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007969 for (auto *VE : C->varlists()) {
7970 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007971 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007972 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007973 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007974 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007975 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7976 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007977}
7978
Alexander Musman64d33f12014-06-04 07:53:32 +00007979template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007980OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007981TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7982 llvm::SmallVector<Expr *, 16> Vars;
7983 Vars.reserve(C->varlist_size());
7984 for (auto *VE : C->varlists()) {
7985 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7986 if (EVar.isInvalid())
7987 return nullptr;
7988 Vars.push_back(EVar.get());
7989 }
7990 CXXScopeSpec ReductionIdScopeSpec;
7991 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7992
7993 DeclarationNameInfo NameInfo = C->getNameInfo();
7994 if (NameInfo.getName()) {
7995 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7996 if (!NameInfo.getName())
7997 return nullptr;
7998 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00007999 // Build a list of all UDR decls with the same names ranged by the Scopes.
8000 // The Scope boundary is a duplication of the previous decl.
8001 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8002 for (auto *E : C->reduction_ops()) {
8003 // Transform all the decls.
8004 if (E) {
8005 auto *ULE = cast<UnresolvedLookupExpr>(E);
8006 UnresolvedSet<8> Decls;
8007 for (auto *D : ULE->decls()) {
8008 NamedDecl *InstD =
8009 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8010 Decls.addDecl(InstD, InstD->getAccess());
8011 }
8012 UnresolvedReductions.push_back(
8013 UnresolvedLookupExpr::Create(
8014 SemaRef.Context, /*NamingClass=*/nullptr,
8015 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8016 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8017 Decls.begin(), Decls.end()));
8018 } else
8019 UnresolvedReductions.push_back(nullptr);
8020 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008021 return getDerived().RebuildOMPReductionClause(
8022 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008023 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008024}
8025
8026template <typename Derived>
8027OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008028TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8029 llvm::SmallVector<Expr *, 16> Vars;
8030 Vars.reserve(C->varlist_size());
8031 for (auto *VE : C->varlists()) {
8032 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8033 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008034 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008035 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008036 }
8037 ExprResult Step = getDerived().TransformExpr(C->getStep());
8038 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008039 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008040 return getDerived().RebuildOMPLinearClause(
8041 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8042 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008043}
8044
Alexander Musman64d33f12014-06-04 07:53:32 +00008045template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008046OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008047TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8048 llvm::SmallVector<Expr *, 16> Vars;
8049 Vars.reserve(C->varlist_size());
8050 for (auto *VE : C->varlists()) {
8051 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8052 if (EVar.isInvalid())
8053 return nullptr;
8054 Vars.push_back(EVar.get());
8055 }
8056 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8057 if (Alignment.isInvalid())
8058 return nullptr;
8059 return getDerived().RebuildOMPAlignedClause(
8060 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8061 C->getColonLoc(), C->getLocEnd());
8062}
8063
Alexander Musman64d33f12014-06-04 07:53:32 +00008064template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008065OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008066TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8067 llvm::SmallVector<Expr *, 16> Vars;
8068 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008069 for (auto *VE : C->varlists()) {
8070 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008071 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008072 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008073 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008074 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008075 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8076 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008077}
8078
Alexey Bataevbae9a792014-06-27 10:37:06 +00008079template <typename Derived>
8080OMPClause *
8081TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8082 llvm::SmallVector<Expr *, 16> Vars;
8083 Vars.reserve(C->varlist_size());
8084 for (auto *VE : C->varlists()) {
8085 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8086 if (EVar.isInvalid())
8087 return nullptr;
8088 Vars.push_back(EVar.get());
8089 }
8090 return getDerived().RebuildOMPCopyprivateClause(
8091 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8092}
8093
Alexey Bataev6125da92014-07-21 11:26:11 +00008094template <typename Derived>
8095OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8096 llvm::SmallVector<Expr *, 16> Vars;
8097 Vars.reserve(C->varlist_size());
8098 for (auto *VE : C->varlists()) {
8099 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8100 if (EVar.isInvalid())
8101 return nullptr;
8102 Vars.push_back(EVar.get());
8103 }
8104 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8105 C->getLParenLoc(), C->getLocEnd());
8106}
8107
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008108template <typename Derived>
8109OMPClause *
8110TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8111 llvm::SmallVector<Expr *, 16> Vars;
8112 Vars.reserve(C->varlist_size());
8113 for (auto *VE : C->varlists()) {
8114 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8115 if (EVar.isInvalid())
8116 return nullptr;
8117 Vars.push_back(EVar.get());
8118 }
8119 return getDerived().RebuildOMPDependClause(
8120 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8121 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8122}
8123
Michael Wonge710d542015-08-07 16:16:36 +00008124template <typename Derived>
8125OMPClause *
8126TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8127 ExprResult E = getDerived().TransformExpr(C->getDevice());
8128 if (E.isInvalid())
8129 return nullptr;
8130 return getDerived().RebuildOMPDeviceClause(
8131 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8132}
8133
Kelvin Li0bff7af2015-11-23 05:32:03 +00008134template <typename Derived>
8135OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8136 llvm::SmallVector<Expr *, 16> Vars;
8137 Vars.reserve(C->varlist_size());
8138 for (auto *VE : C->varlists()) {
8139 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8140 if (EVar.isInvalid())
8141 return nullptr;
8142 Vars.push_back(EVar.get());
8143 }
8144 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008145 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8146 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8147 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008148}
8149
Kelvin Li099bb8c2015-11-24 20:50:12 +00008150template <typename Derived>
8151OMPClause *
8152TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8153 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8154 if (E.isInvalid())
8155 return nullptr;
8156 return getDerived().RebuildOMPNumTeamsClause(
8157 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8158}
8159
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008160template <typename Derived>
8161OMPClause *
8162TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8163 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8164 if (E.isInvalid())
8165 return nullptr;
8166 return getDerived().RebuildOMPThreadLimitClause(
8167 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8168}
8169
Alexey Bataeva0569352015-12-01 10:17:31 +00008170template <typename Derived>
8171OMPClause *
8172TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8173 ExprResult E = getDerived().TransformExpr(C->getPriority());
8174 if (E.isInvalid())
8175 return nullptr;
8176 return getDerived().RebuildOMPPriorityClause(
8177 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8178}
8179
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008180template <typename Derived>
8181OMPClause *
8182TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8183 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8184 if (E.isInvalid())
8185 return nullptr;
8186 return getDerived().RebuildOMPGrainsizeClause(
8187 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8188}
8189
Alexey Bataev382967a2015-12-08 12:06:20 +00008190template <typename Derived>
8191OMPClause *
8192TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8193 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8194 if (E.isInvalid())
8195 return nullptr;
8196 return getDerived().RebuildOMPNumTasksClause(
8197 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8198}
8199
Alexey Bataev28c75412015-12-15 08:19:24 +00008200template <typename Derived>
8201OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8202 ExprResult E = getDerived().TransformExpr(C->getHint());
8203 if (E.isInvalid())
8204 return nullptr;
8205 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8206 C->getLParenLoc(), C->getLocEnd());
8207}
8208
Carlo Bertollib4adf552016-01-15 18:50:31 +00008209template <typename Derived>
8210OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8211 OMPDistScheduleClause *C) {
8212 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8213 if (E.isInvalid())
8214 return nullptr;
8215 return getDerived().RebuildOMPDistScheduleClause(
8216 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8217 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8218}
8219
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008220template <typename Derived>
8221OMPClause *
8222TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8223 return C;
8224}
8225
Samuel Antao661c0902016-05-26 17:39:58 +00008226template <typename Derived>
8227OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8228 llvm::SmallVector<Expr *, 16> Vars;
8229 Vars.reserve(C->varlist_size());
8230 for (auto *VE : C->varlists()) {
8231 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8232 if (EVar.isInvalid())
8233 return 0;
8234 Vars.push_back(EVar.get());
8235 }
8236 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8237 C->getLParenLoc(), C->getLocEnd());
8238}
8239
Samuel Antaoec172c62016-05-26 17:49:04 +00008240template <typename Derived>
8241OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8242 llvm::SmallVector<Expr *, 16> Vars;
8243 Vars.reserve(C->varlist_size());
8244 for (auto *VE : C->varlists()) {
8245 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8246 if (EVar.isInvalid())
8247 return 0;
8248 Vars.push_back(EVar.get());
8249 }
8250 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8251 C->getLParenLoc(), C->getLocEnd());
8252}
8253
Carlo Bertolli2404b172016-07-13 15:37:16 +00008254template <typename Derived>
8255OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8256 OMPUseDevicePtrClause *C) {
8257 llvm::SmallVector<Expr *, 16> Vars;
8258 Vars.reserve(C->varlist_size());
8259 for (auto *VE : C->varlists()) {
8260 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8261 if (EVar.isInvalid())
8262 return nullptr;
8263 Vars.push_back(EVar.get());
8264 }
8265 return getDerived().RebuildOMPUseDevicePtrClause(
8266 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8267}
8268
Carlo Bertolli70594e92016-07-13 17:16:49 +00008269template <typename Derived>
8270OMPClause *
8271TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8272 llvm::SmallVector<Expr *, 16> Vars;
8273 Vars.reserve(C->varlist_size());
8274 for (auto *VE : C->varlists()) {
8275 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8276 if (EVar.isInvalid())
8277 return nullptr;
8278 Vars.push_back(EVar.get());
8279 }
8280 return getDerived().RebuildOMPIsDevicePtrClause(
8281 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8282}
8283
Douglas Gregorebe10102009-08-20 07:17:43 +00008284//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008285// Expression transformation
8286//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008289TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008290 if (!E->isTypeDependent())
8291 return E;
8292
8293 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8294 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008295}
Mike Stump11289f42009-09-09 15:08:12 +00008296
8297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008298ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008299TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008300 NestedNameSpecifierLoc QualifierLoc;
8301 if (E->getQualifierLoc()) {
8302 QualifierLoc
8303 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8304 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008305 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008306 }
John McCallce546572009-12-08 09:08:17 +00008307
8308 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008309 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8310 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008313
John McCall815039a2010-08-17 21:27:17 +00008314 DeclarationNameInfo NameInfo = E->getNameInfo();
8315 if (NameInfo.getName()) {
8316 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8317 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008318 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008319 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008320
8321 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008322 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008323 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008324 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008325 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008326
8327 // Mark it referenced in the new context regardless.
8328 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008329 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008330
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008331 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008332 }
John McCallce546572009-12-08 09:08:17 +00008333
Craig Topperc3ec1492014-05-26 06:22:03 +00008334 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008335 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008336 TemplateArgs = &TransArgs;
8337 TransArgs.setLAngleLoc(E->getLAngleLoc());
8338 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008339 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8340 E->getNumTemplateArgs(),
8341 TransArgs))
8342 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008343 }
8344
Chad Rosier1dcde962012-08-08 18:46:20 +00008345 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008346 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008347}
Mike Stump11289f42009-09-09 15:08:12 +00008348
Douglas Gregora16548e2009-08-11 05:31:07 +00008349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008350ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008351TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008352 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008353}
Mike Stump11289f42009-09-09 15:08:12 +00008354
Douglas Gregora16548e2009-08-11 05:31:07 +00008355template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008357TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008358 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008359}
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008363TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008364 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008365}
Mike Stump11289f42009-09-09 15:08:12 +00008366
Douglas Gregora16548e2009-08-11 05:31:07 +00008367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008369TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008370 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008374ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008375TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008376 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008377}
8378
8379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008380ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008381TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008382 if (FunctionDecl *FD = E->getDirectCallee())
8383 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008384 return SemaRef.MaybeBindToTemporary(E);
8385}
8386
8387template<typename Derived>
8388ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008389TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8390 ExprResult ControllingExpr =
8391 getDerived().TransformExpr(E->getControllingExpr());
8392 if (ControllingExpr.isInvalid())
8393 return ExprError();
8394
Chris Lattner01cf8db2011-07-20 06:58:45 +00008395 SmallVector<Expr *, 4> AssocExprs;
8396 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008397 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8398 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8399 if (TS) {
8400 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8401 if (!AssocType)
8402 return ExprError();
8403 AssocTypes.push_back(AssocType);
8404 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008405 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008406 }
8407
8408 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8409 if (AssocExpr.isInvalid())
8410 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008411 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008412 }
8413
8414 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8415 E->getDefaultLoc(),
8416 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008417 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008418 AssocTypes,
8419 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008420}
8421
8422template<typename Derived>
8423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008424TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008425 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008426 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008427 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008428
Douglas Gregora16548e2009-08-11 05:31:07 +00008429 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008430 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008431
John McCallb268a282010-08-23 23:25:46 +00008432 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008433 E->getRParen());
8434}
8435
Richard Smithdb2630f2012-10-21 03:28:35 +00008436/// \brief The operand of a unary address-of operator has special rules: it's
8437/// allowed to refer to a non-static member of a class even if there's no 'this'
8438/// object available.
8439template<typename Derived>
8440ExprResult
8441TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8442 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008443 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008444 else
8445 return getDerived().TransformExpr(E);
8446}
8447
Mike Stump11289f42009-09-09 15:08:12 +00008448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008450TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008451 ExprResult SubExpr;
8452 if (E->getOpcode() == UO_AddrOf)
8453 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8454 else
8455 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008458
Douglas Gregora16548e2009-08-11 05:31:07 +00008459 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008460 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008461
Douglas Gregora16548e2009-08-11 05:31:07 +00008462 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8463 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008464 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008465}
Mike Stump11289f42009-09-09 15:08:12 +00008466
Douglas Gregora16548e2009-08-11 05:31:07 +00008467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008468ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008469TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8470 // Transform the type.
8471 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8472 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008473 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008474
Douglas Gregor882211c2010-04-28 22:16:22 +00008475 // Transform all of the components into components similar to what the
8476 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008477 // FIXME: It would be slightly more efficient in the non-dependent case to
8478 // just map FieldDecls, rather than requiring the rebuilder to look for
8479 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008480 // template code that we don't care.
8481 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008482 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008483 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008484 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008485 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008486 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008487 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008488 Comp.LocStart = ON.getSourceRange().getBegin();
8489 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008490 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008491 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008492 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008493 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008494 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008495 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008496
Douglas Gregor882211c2010-04-28 22:16:22 +00008497 ExprChanged = ExprChanged || Index.get() != FromIndex;
8498 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008499 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008500 break;
8501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008502
James Y Knight7281c352015-12-29 22:31:18 +00008503 case OffsetOfNode::Field:
8504 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008505 Comp.isBrackets = false;
8506 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008507 if (!Comp.U.IdentInfo)
8508 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008509
Douglas Gregor882211c2010-04-28 22:16:22 +00008510 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008511
James Y Knight7281c352015-12-29 22:31:18 +00008512 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008513 // Will be recomputed during the rebuild.
8514 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008516
Douglas Gregor882211c2010-04-28 22:16:22 +00008517 Components.push_back(Comp);
8518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008519
Douglas Gregor882211c2010-04-28 22:16:22 +00008520 // If nothing changed, retain the existing expression.
8521 if (!getDerived().AlwaysRebuild() &&
8522 Type == E->getTypeSourceInfo() &&
8523 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008524 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008525
Douglas Gregor882211c2010-04-28 22:16:22 +00008526 // Build a new offsetof expression.
8527 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008528 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008529}
8530
8531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008532ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008533TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008534 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008535 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008536 return E;
John McCall8d69a212010-11-15 23:31:06 +00008537}
8538
8539template<typename Derived>
8540ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008541TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8542 return E;
8543}
8544
8545template<typename Derived>
8546ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008547TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008548 // Rebuild the syntactic form. The original syntactic form has
8549 // opaque-value expressions in it, so strip those away and rebuild
8550 // the result. This is a really awful way of doing this, but the
8551 // better solution (rebuilding the semantic expressions and
8552 // rebinding OVEs as necessary) doesn't work; we'd need
8553 // TreeTransform to not strip away implicit conversions.
8554 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8555 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008556 if (result.isInvalid()) return ExprError();
8557
8558 // If that gives us a pseudo-object result back, the pseudo-object
8559 // expression must have been an lvalue-to-rvalue conversion which we
8560 // should reapply.
8561 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008562 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008563
8564 return result;
8565}
8566
8567template<typename Derived>
8568ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008569TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8570 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008571 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008572 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008573
John McCallbcd03502009-12-07 02:54:59 +00008574 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008575 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008577
John McCall4c98fd82009-11-04 07:28:41 +00008578 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008579 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008580
Peter Collingbournee190dee2011-03-11 19:24:49 +00008581 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8582 E->getKind(),
8583 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008584 }
Mike Stump11289f42009-09-09 15:08:12 +00008585
Eli Friedmane4f22df2012-02-29 04:03:55 +00008586 // C++0x [expr.sizeof]p1:
8587 // The operand is either an expression, which is an unevaluated operand
8588 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008589 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8590 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008591
Reid Kleckner32506ed2014-06-12 23:03:48 +00008592 // Try to recover if we have something like sizeof(T::X) where X is a type.
8593 // Notably, there must be *exactly* one set of parens if X is a type.
8594 TypeSourceInfo *RecoveryTSI = nullptr;
8595 ExprResult SubExpr;
8596 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8597 if (auto *DRE =
8598 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8599 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8600 PE, DRE, false, &RecoveryTSI);
8601 else
8602 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8603
8604 if (RecoveryTSI) {
8605 return getDerived().RebuildUnaryExprOrTypeTrait(
8606 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8607 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008608 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008609
Eli Friedmane4f22df2012-02-29 04:03:55 +00008610 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008611 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008612
Peter Collingbournee190dee2011-03-11 19:24:49 +00008613 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8614 E->getOperatorLoc(),
8615 E->getKind(),
8616 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008617}
Mike Stump11289f42009-09-09 15:08:12 +00008618
Douglas Gregora16548e2009-08-11 05:31:07 +00008619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008620ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008621TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008622 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008623 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008625
John McCalldadc5752010-08-24 06:29:42 +00008626 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008627 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008629
8630
Douglas Gregora16548e2009-08-11 05:31:07 +00008631 if (!getDerived().AlwaysRebuild() &&
8632 LHS.get() == E->getLHS() &&
8633 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008634 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008635
John McCallb268a282010-08-23 23:25:46 +00008636 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008637 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008638 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008639 E->getRBracketLoc());
8640}
Mike Stump11289f42009-09-09 15:08:12 +00008641
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008642template <typename Derived>
8643ExprResult
8644TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8645 ExprResult Base = getDerived().TransformExpr(E->getBase());
8646 if (Base.isInvalid())
8647 return ExprError();
8648
8649 ExprResult LowerBound;
8650 if (E->getLowerBound()) {
8651 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8652 if (LowerBound.isInvalid())
8653 return ExprError();
8654 }
8655
8656 ExprResult Length;
8657 if (E->getLength()) {
8658 Length = getDerived().TransformExpr(E->getLength());
8659 if (Length.isInvalid())
8660 return ExprError();
8661 }
8662
8663 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8664 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8665 return E;
8666
8667 return getDerived().RebuildOMPArraySectionExpr(
8668 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8669 Length.get(), E->getRBracketLoc());
8670}
8671
Mike Stump11289f42009-09-09 15:08:12 +00008672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008673ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008674TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008675 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008676 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008678 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008679
8680 // Transform arguments.
8681 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008682 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008683 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008684 &ArgChanged))
8685 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008686
Douglas Gregora16548e2009-08-11 05:31:07 +00008687 if (!getDerived().AlwaysRebuild() &&
8688 Callee.get() == E->getCallee() &&
8689 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008690 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008691
Douglas Gregora16548e2009-08-11 05:31:07 +00008692 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008693 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008694 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008695 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008696 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008697 E->getRParenLoc());
8698}
Mike Stump11289f42009-09-09 15:08:12 +00008699
8700template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008701ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008702TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008704 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregorea972d32011-02-28 21:54:11 +00008707 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008708 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008709 QualifierLoc
8710 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008711
Douglas Gregorea972d32011-02-28 21:54:11 +00008712 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008713 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008714 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008715 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008716
Eli Friedman2cfcef62009-12-04 06:40:45 +00008717 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008718 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8719 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008720 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008722
John McCall16df1e52010-03-30 21:47:33 +00008723 NamedDecl *FoundDecl = E->getFoundDecl();
8724 if (FoundDecl == E->getMemberDecl()) {
8725 FoundDecl = Member;
8726 } else {
8727 FoundDecl = cast_or_null<NamedDecl>(
8728 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8729 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008730 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008731 }
8732
Douglas Gregora16548e2009-08-11 05:31:07 +00008733 if (!getDerived().AlwaysRebuild() &&
8734 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008735 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008736 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008737 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008738 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008739
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008740 // Mark it referenced in the new context regardless.
8741 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008742 SemaRef.MarkMemberReferenced(E);
8743
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008744 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008745 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008746
John McCall6b51f282009-11-23 01:53:49 +00008747 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008748 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008749 TransArgs.setLAngleLoc(E->getLAngleLoc());
8750 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008751 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8752 E->getNumTemplateArgs(),
8753 TransArgs))
8754 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008756
Douglas Gregora16548e2009-08-11 05:31:07 +00008757 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008758 SourceLocation FakeOperatorLoc =
8759 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008760
John McCall38836f02010-01-15 08:34:02 +00008761 // FIXME: to do this check properly, we will need to preserve the
8762 // first-qualifier-in-scope here, just in case we had a dependent
8763 // base (and therefore couldn't do the check) and a
8764 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008765 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008766
John McCallb268a282010-08-23 23:25:46 +00008767 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008768 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008769 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008770 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008771 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008772 Member,
John McCall16df1e52010-03-30 21:47:33 +00008773 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008774 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008775 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008776 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008777}
Mike Stump11289f42009-09-09 15:08:12 +00008778
Douglas Gregora16548e2009-08-11 05:31:07 +00008779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008781TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008782 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008783 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008784 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008785
John McCalldadc5752010-08-24 06:29:42 +00008786 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008787 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008789
Douglas Gregora16548e2009-08-11 05:31:07 +00008790 if (!getDerived().AlwaysRebuild() &&
8791 LHS.get() == E->getLHS() &&
8792 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008793 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008794
Lang Hames5de91cc2012-10-02 04:45:10 +00008795 Sema::FPContractStateRAII FPContractState(getSema());
8796 getSema().FPFeatures.fp_contract = E->isFPContractable();
8797
Douglas Gregora16548e2009-08-11 05:31:07 +00008798 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008799 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008800}
8801
Mike Stump11289f42009-09-09 15:08:12 +00008802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008803ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008804TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008805 CompoundAssignOperator *E) {
8806 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008807}
Mike Stump11289f42009-09-09 15:08:12 +00008808
Douglas Gregora16548e2009-08-11 05:31:07 +00008809template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008810ExprResult TreeTransform<Derived>::
8811TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8812 // Just rebuild the common and RHS expressions and see whether we
8813 // get any changes.
8814
8815 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8816 if (commonExpr.isInvalid())
8817 return ExprError();
8818
8819 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8820 if (rhs.isInvalid())
8821 return ExprError();
8822
8823 if (!getDerived().AlwaysRebuild() &&
8824 commonExpr.get() == e->getCommon() &&
8825 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008826 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008827
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008828 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008829 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008830 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008831 e->getColonLoc(),
8832 rhs.get());
8833}
8834
8835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008837TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008838 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008839 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008841
John McCalldadc5752010-08-24 06:29:42 +00008842 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008843 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008845
John McCalldadc5752010-08-24 06:29:42 +00008846 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008847 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008849
Douglas Gregora16548e2009-08-11 05:31:07 +00008850 if (!getDerived().AlwaysRebuild() &&
8851 Cond.get() == E->getCond() &&
8852 LHS.get() == E->getLHS() &&
8853 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008854 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008855
John McCallb268a282010-08-23 23:25:46 +00008856 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008857 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008858 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008859 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008860 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008861}
Mike Stump11289f42009-09-09 15:08:12 +00008862
8863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008865TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008866 // Implicit casts are eliminated during transformation, since they
8867 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008868 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008869}
Mike Stump11289f42009-09-09 15:08:12 +00008870
Douglas Gregora16548e2009-08-11 05:31:07 +00008871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008872ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008873TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008874 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8875 if (!Type)
8876 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008877
John McCalldadc5752010-08-24 06:29:42 +00008878 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008879 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008880 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008882
Douglas Gregora16548e2009-08-11 05:31:07 +00008883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008884 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008885 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008886 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008887
John McCall97513962010-01-15 18:39:57 +00008888 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008889 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008890 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008891 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008892}
Mike Stump11289f42009-09-09 15:08:12 +00008893
Douglas Gregora16548e2009-08-11 05:31:07 +00008894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008896TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008897 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8898 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8899 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008901
John McCalldadc5752010-08-24 06:29:42 +00008902 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008903 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008905
Douglas Gregora16548e2009-08-11 05:31:07 +00008906 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008907 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008908 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008909 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008910
John McCall5d7aa7f2010-01-19 22:33:45 +00008911 // Note: the expression type doesn't necessarily match the
8912 // type-as-written, but that's okay, because it should always be
8913 // derivable from the initializer.
8914
John McCalle15bbff2010-01-18 19:35:47 +00008915 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008916 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008917 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008918}
Mike Stump11289f42009-09-09 15:08:12 +00008919
Douglas Gregora16548e2009-08-11 05:31:07 +00008920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008922TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008923 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008924 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008926
Douglas Gregora16548e2009-08-11 05:31:07 +00008927 if (!getDerived().AlwaysRebuild() &&
8928 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008929 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregora16548e2009-08-11 05:31:07 +00008931 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008932 SourceLocation FakeOperatorLoc =
8933 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008934 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008935 E->getAccessorLoc(),
8936 E->getAccessor());
8937}
Mike Stump11289f42009-09-09 15:08:12 +00008938
Douglas Gregora16548e2009-08-11 05:31:07 +00008939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008941TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008942 if (InitListExpr *Syntactic = E->getSyntacticForm())
8943 E = Syntactic;
8944
Douglas Gregora16548e2009-08-11 05:31:07 +00008945 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008946
Benjamin Kramerf0623432012-08-23 22:51:59 +00008947 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008948 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008949 Inits, &InitChanged))
8950 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008951
Richard Smith520449d2015-02-05 06:15:50 +00008952 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8953 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8954 // in some cases. We can't reuse it in general, because the syntactic and
8955 // semantic forms are linked, and we can't know that semantic form will
8956 // match even if the syntactic form does.
8957 }
Mike Stump11289f42009-09-09 15:08:12 +00008958
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008959 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008960 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008961}
Mike Stump11289f42009-09-09 15:08:12 +00008962
Douglas Gregora16548e2009-08-11 05:31:07 +00008963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008964ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008965TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008966 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008967
Douglas Gregorebe10102009-08-20 07:17:43 +00008968 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008969 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008970 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008972
Douglas Gregorebe10102009-08-20 07:17:43 +00008973 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008974 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008975 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00008976 for (const DesignatedInitExpr::Designator &D : E->designators()) {
8977 if (D.isFieldDesignator()) {
8978 Desig.AddDesignator(Designator::getField(D.getFieldName(),
8979 D.getDotLoc(),
8980 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00008981 if (D.getField()) {
8982 FieldDecl *Field = cast_or_null<FieldDecl>(
8983 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
8984 if (Field != D.getField())
8985 // Rebuild the expression when the transformed FieldDecl is
8986 // different to the already assigned FieldDecl.
8987 ExprChanged = true;
8988 } else {
8989 // Ensure that the designator expression is rebuilt when there isn't
8990 // a resolved FieldDecl in the designator as we don't want to assign
8991 // a FieldDecl to a pattern designator that will be instantiated again.
8992 ExprChanged = true;
8993 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008994 continue;
8995 }
Mike Stump11289f42009-09-09 15:08:12 +00008996
David Majnemerf7e36092016-06-23 00:15:04 +00008997 if (D.isArrayDesignator()) {
8998 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008999 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009001
David Majnemerf7e36092016-06-23 00:15:04 +00009002 Desig.AddDesignator(
9003 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009004
David Majnemerf7e36092016-06-23 00:15:04 +00009005 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009006 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009007 continue;
9008 }
Mike Stump11289f42009-09-09 15:08:12 +00009009
David Majnemerf7e36092016-06-23 00:15:04 +00009010 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009011 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009012 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009013 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009015
David Majnemerf7e36092016-06-23 00:15:04 +00009016 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009017 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009019
9020 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009021 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009022 D.getLBracketLoc(),
9023 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009024
David Majnemerf7e36092016-06-23 00:15:04 +00009025 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9026 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009027
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009028 ArrayExprs.push_back(Start.get());
9029 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009030 }
Mike Stump11289f42009-09-09 15:08:12 +00009031
Douglas Gregora16548e2009-08-11 05:31:07 +00009032 if (!getDerived().AlwaysRebuild() &&
9033 Init.get() == E->getInit() &&
9034 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009035 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009036
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009037 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009038 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009039 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009040}
Mike Stump11289f42009-09-09 15:08:12 +00009041
Yunzhong Gaocb779302015-06-10 00:27:52 +00009042// Seems that if TransformInitListExpr() only works on the syntactic form of an
9043// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9044template<typename Derived>
9045ExprResult
9046TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9047 DesignatedInitUpdateExpr *E) {
9048 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9049 "initializer");
9050 return ExprError();
9051}
9052
9053template<typename Derived>
9054ExprResult
9055TreeTransform<Derived>::TransformNoInitExpr(
9056 NoInitExpr *E) {
9057 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9058 return ExprError();
9059}
9060
Douglas Gregora16548e2009-08-11 05:31:07 +00009061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009062ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009063TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9064 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9065 return ExprError();
9066}
9067
9068template<typename Derived>
9069ExprResult
9070TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9071 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9072 return ExprError();
9073}
9074
9075template<typename Derived>
9076ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009077TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009078 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009079 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009080
Douglas Gregor3da3c062009-10-28 00:29:27 +00009081 // FIXME: Will we ever have proper type location here? Will we actually
9082 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009083 QualType T = getDerived().TransformType(E->getType());
9084 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009086
Douglas Gregora16548e2009-08-11 05:31:07 +00009087 if (!getDerived().AlwaysRebuild() &&
9088 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009089 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009090
Douglas Gregora16548e2009-08-11 05:31:07 +00009091 return getDerived().RebuildImplicitValueInitExpr(T);
9092}
Mike Stump11289f42009-09-09 15:08:12 +00009093
Douglas Gregora16548e2009-08-11 05:31:07 +00009094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009096TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009097 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9098 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009099 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009100
John McCalldadc5752010-08-24 06:29:42 +00009101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009102 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009103 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009104
Douglas Gregora16548e2009-08-11 05:31:07 +00009105 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009106 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009107 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009108 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009109
John McCallb268a282010-08-23 23:25:46 +00009110 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009111 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009112}
9113
9114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009115ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009116TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009117 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009118 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009119 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9120 &ArgumentChanged))
9121 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009122
Douglas Gregora16548e2009-08-11 05:31:07 +00009123 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009124 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009125 E->getRParenLoc());
9126}
Mike Stump11289f42009-09-09 15:08:12 +00009127
Douglas Gregora16548e2009-08-11 05:31:07 +00009128/// \brief Transform an address-of-label expression.
9129///
9130/// By default, the transformation of an address-of-label expression always
9131/// rebuilds the expression, so that the label identifier can be resolved to
9132/// the corresponding label statement by semantic analysis.
9133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009135TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009136 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9137 E->getLabel());
9138 if (!LD)
9139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009140
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009142 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009143}
Mike Stump11289f42009-09-09 15:08:12 +00009144
9145template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009147TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009148 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009149 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009150 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009151 if (SubStmt.isInvalid()) {
9152 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009153 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009154 }
Mike Stump11289f42009-09-09 15:08:12 +00009155
Douglas Gregora16548e2009-08-11 05:31:07 +00009156 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009157 SubStmt.get() == E->getSubStmt()) {
9158 // Calling this an 'error' is unintuitive, but it does the right thing.
9159 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009160 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009161 }
Mike Stump11289f42009-09-09 15:08:12 +00009162
9163 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009164 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009165 E->getRParenLoc());
9166}
Mike Stump11289f42009-09-09 15:08:12 +00009167
Douglas Gregora16548e2009-08-11 05:31:07 +00009168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009170TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009171 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009172 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009174
John McCalldadc5752010-08-24 06:29:42 +00009175 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009176 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009178
John McCalldadc5752010-08-24 06:29:42 +00009179 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009180 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009182
Douglas Gregora16548e2009-08-11 05:31:07 +00009183 if (!getDerived().AlwaysRebuild() &&
9184 Cond.get() == E->getCond() &&
9185 LHS.get() == E->getLHS() &&
9186 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009187 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009188
Douglas Gregora16548e2009-08-11 05:31:07 +00009189 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009190 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009191 E->getRParenLoc());
9192}
Mike Stump11289f42009-09-09 15:08:12 +00009193
Douglas Gregora16548e2009-08-11 05:31:07 +00009194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009196TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009197 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009198}
9199
9200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009202TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009203 switch (E->getOperator()) {
9204 case OO_New:
9205 case OO_Delete:
9206 case OO_Array_New:
9207 case OO_Array_Delete:
9208 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009209
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009210 case OO_Call: {
9211 // This is a call to an object's operator().
9212 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9213
9214 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009215 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009216 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009217 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009218
9219 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009220 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9221 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009222
9223 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009224 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009225 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009226 Args))
9227 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009228
John McCallb268a282010-08-23 23:25:46 +00009229 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009230 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009231 E->getLocEnd());
9232 }
9233
9234#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9235 case OO_##Name:
9236#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9237#include "clang/Basic/OperatorKinds.def"
9238 case OO_Subscript:
9239 // Handled below.
9240 break;
9241
9242 case OO_Conditional:
9243 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009244
9245 case OO_None:
9246 case NUM_OVERLOADED_OPERATORS:
9247 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009248 }
9249
John McCalldadc5752010-08-24 06:29:42 +00009250 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009251 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009252 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009253
Richard Smithdb2630f2012-10-21 03:28:35 +00009254 ExprResult First;
9255 if (E->getOperator() == OO_Amp)
9256 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9257 else
9258 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009259 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009260 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009261
John McCalldadc5752010-08-24 06:29:42 +00009262 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009263 if (E->getNumArgs() == 2) {
9264 Second = getDerived().TransformExpr(E->getArg(1));
9265 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009266 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009267 }
Mike Stump11289f42009-09-09 15:08:12 +00009268
Douglas Gregora16548e2009-08-11 05:31:07 +00009269 if (!getDerived().AlwaysRebuild() &&
9270 Callee.get() == E->getCallee() &&
9271 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009272 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009273 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009274
Lang Hames5de91cc2012-10-02 04:45:10 +00009275 Sema::FPContractStateRAII FPContractState(getSema());
9276 getSema().FPFeatures.fp_contract = E->isFPContractable();
9277
Douglas Gregora16548e2009-08-11 05:31:07 +00009278 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9279 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009280 Callee.get(),
9281 First.get(),
9282 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009283}
Mike Stump11289f42009-09-09 15:08:12 +00009284
Douglas Gregora16548e2009-08-11 05:31:07 +00009285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009287TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9288 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009289}
Mike Stump11289f42009-09-09 15:08:12 +00009290
Douglas Gregora16548e2009-08-11 05:31:07 +00009291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009292ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009293TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9294 // Transform the callee.
9295 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9296 if (Callee.isInvalid())
9297 return ExprError();
9298
9299 // Transform exec config.
9300 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9301 if (EC.isInvalid())
9302 return ExprError();
9303
9304 // Transform arguments.
9305 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009306 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009307 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009308 &ArgChanged))
9309 return ExprError();
9310
9311 if (!getDerived().AlwaysRebuild() &&
9312 Callee.get() == E->getCallee() &&
9313 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009314 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009315
9316 // FIXME: Wrong source location information for the '('.
9317 SourceLocation FakeLParenLoc
9318 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9319 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009320 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009321 E->getRParenLoc(), EC.get());
9322}
9323
9324template<typename Derived>
9325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009326TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009327 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9328 if (!Type)
9329 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009330
John McCalldadc5752010-08-24 06:29:42 +00009331 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009332 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009333 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009334 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009335
Douglas Gregora16548e2009-08-11 05:31:07 +00009336 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009337 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009338 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009339 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009340 return getDerived().RebuildCXXNamedCastExpr(
9341 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9342 Type, E->getAngleBrackets().getEnd(),
9343 // FIXME. this should be '(' location
9344 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009345}
Mike Stump11289f42009-09-09 15:08:12 +00009346
Douglas Gregora16548e2009-08-11 05:31:07 +00009347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009349TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9350 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009351}
Mike Stump11289f42009-09-09 15:08:12 +00009352
9353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009354ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009355TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9356 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009357}
9358
Douglas Gregora16548e2009-08-11 05:31:07 +00009359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009360ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009361TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009362 CXXReinterpretCastExpr *E) {
9363 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009364}
Mike Stump11289f42009-09-09 15:08:12 +00009365
Douglas Gregora16548e2009-08-11 05:31:07 +00009366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009367ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009368TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9369 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009370}
Mike Stump11289f42009-09-09 15:08:12 +00009371
Douglas Gregora16548e2009-08-11 05:31:07 +00009372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009373ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009374TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009375 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009376 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9377 if (!Type)
9378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009379
John McCalldadc5752010-08-24 06:29:42 +00009380 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009381 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009382 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009384
Douglas Gregora16548e2009-08-11 05:31:07 +00009385 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009386 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009387 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009388 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009389
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009390 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009391 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009392 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009393 E->getRParenLoc());
9394}
Mike Stump11289f42009-09-09 15:08:12 +00009395
Douglas Gregora16548e2009-08-11 05:31:07 +00009396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009398TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009399 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009400 TypeSourceInfo *TInfo
9401 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9402 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009404
Douglas Gregora16548e2009-08-11 05:31:07 +00009405 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009406 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009407 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009408
Douglas Gregor9da64192010-04-26 22:37:10 +00009409 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9410 E->getLocStart(),
9411 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009412 E->getLocEnd());
9413 }
Mike Stump11289f42009-09-09 15:08:12 +00009414
Eli Friedman456f0182012-01-20 01:26:23 +00009415 // We don't know whether the subexpression is potentially evaluated until
9416 // after we perform semantic analysis. We speculatively assume it is
9417 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009418 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009419 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9420 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009421
John McCalldadc5752010-08-24 06:29:42 +00009422 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009423 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009424 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009425
Douglas Gregora16548e2009-08-11 05:31:07 +00009426 if (!getDerived().AlwaysRebuild() &&
9427 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009428 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009429
Douglas Gregor9da64192010-04-26 22:37:10 +00009430 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9431 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009432 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 E->getLocEnd());
9434}
9435
9436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009437ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009438TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9439 if (E->isTypeOperand()) {
9440 TypeSourceInfo *TInfo
9441 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9442 if (!TInfo)
9443 return ExprError();
9444
9445 if (!getDerived().AlwaysRebuild() &&
9446 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009447 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009448
Douglas Gregor69735112011-03-06 17:40:41 +00009449 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009450 E->getLocStart(),
9451 TInfo,
9452 E->getLocEnd());
9453 }
9454
Francois Pichet9f4f2072010-09-08 12:20:18 +00009455 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9456
9457 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9458 if (SubExpr.isInvalid())
9459 return ExprError();
9460
9461 if (!getDerived().AlwaysRebuild() &&
9462 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009463 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009464
9465 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9466 E->getLocStart(),
9467 SubExpr.get(),
9468 E->getLocEnd());
9469}
9470
9471template<typename Derived>
9472ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009473TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009474 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009475}
Mike Stump11289f42009-09-09 15:08:12 +00009476
Douglas Gregora16548e2009-08-11 05:31:07 +00009477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009478ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009479TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009480 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009481 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009482}
Mike Stump11289f42009-09-09 15:08:12 +00009483
Douglas Gregora16548e2009-08-11 05:31:07 +00009484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009486TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009487 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009488
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009489 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9490 // Make sure that we capture 'this'.
9491 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009492 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009494
Douglas Gregorb15af892010-01-07 23:12:05 +00009495 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009496}
Mike Stump11289f42009-09-09 15:08:12 +00009497
Douglas Gregora16548e2009-08-11 05:31:07 +00009498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009500TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009501 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009502 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009503 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009504
Douglas Gregora16548e2009-08-11 05:31:07 +00009505 if (!getDerived().AlwaysRebuild() &&
9506 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009507 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009508
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009509 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9510 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009511}
Mike Stump11289f42009-09-09 15:08:12 +00009512
Douglas Gregora16548e2009-08-11 05:31:07 +00009513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009514ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009515TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009516 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009517 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9518 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009519 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009520 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009521
Chandler Carruth794da4c2010-02-08 06:42:49 +00009522 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009523 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009524 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009525
Douglas Gregor033f6752009-12-23 23:03:06 +00009526 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009527}
Mike Stump11289f42009-09-09 15:08:12 +00009528
Douglas Gregora16548e2009-08-11 05:31:07 +00009529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009530ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009531TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9532 FieldDecl *Field
9533 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9534 E->getField()));
9535 if (!Field)
9536 return ExprError();
9537
9538 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009539 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009540
9541 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9542}
9543
9544template<typename Derived>
9545ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009546TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9547 CXXScalarValueInitExpr *E) {
9548 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9549 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009550 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009551
Douglas Gregora16548e2009-08-11 05:31:07 +00009552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009553 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009554 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009555
Chad Rosier1dcde962012-08-08 18:46:20 +00009556 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009557 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009558 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009559}
Mike Stump11289f42009-09-09 15:08:12 +00009560
Douglas Gregora16548e2009-08-11 05:31:07 +00009561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009563TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009564 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00009565 TypeSourceInfo *AllocTypeInfo
9566 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
9567 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009568 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009569
Douglas Gregora16548e2009-08-11 05:31:07 +00009570 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009571 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009572 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009573 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009574
Douglas Gregora16548e2009-08-11 05:31:07 +00009575 // Transform the placement arguments (if any).
9576 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009577 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009578 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009579 E->getNumPlacementArgs(), true,
9580 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009582
Sebastian Redl6047f072012-02-16 12:22:20 +00009583 // Transform the initializer (if any).
9584 Expr *OldInit = E->getInitializer();
9585 ExprResult NewInit;
9586 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009587 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009588 if (NewInit.isInvalid())
9589 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009590
Sebastian Redl6047f072012-02-16 12:22:20 +00009591 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009592 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009593 if (E->getOperatorNew()) {
9594 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009595 getDerived().TransformDecl(E->getLocStart(),
9596 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009597 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009598 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009599 }
9600
Craig Topperc3ec1492014-05-26 06:22:03 +00009601 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009602 if (E->getOperatorDelete()) {
9603 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009604 getDerived().TransformDecl(E->getLocStart(),
9605 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009606 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009607 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009609
Douglas Gregora16548e2009-08-11 05:31:07 +00009610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009611 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009612 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009613 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009614 OperatorNew == E->getOperatorNew() &&
9615 OperatorDelete == E->getOperatorDelete() &&
9616 !ArgumentChanged) {
9617 // Mark any declarations we need as referenced.
9618 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009619 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009620 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009621 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009622 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
Sebastian Redl6047f072012-02-16 12:22:20 +00009624 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009625 QualType ElementType
9626 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9627 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9628 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9629 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009630 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009631 }
9632 }
9633 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009634
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009635 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009636 }
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregor0744ef62010-09-07 21:49:58 +00009638 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009639 if (!ArraySize.get()) {
9640 // If no array size was specified, but the new expression was
9641 // instantiated with an array type (e.g., "new T" where T is
9642 // instantiated with "int[4]"), extract the outer bound from the
9643 // array type as our array size. We do this with constant and
9644 // dependently-sized array types.
9645 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9646 if (!ArrayT) {
9647 // Do nothing
9648 } else if (const ConstantArrayType *ConsArrayT
9649 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009650 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9651 SemaRef.Context.getSizeType(),
9652 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009653 AllocType = ConsArrayT->getElementType();
9654 } else if (const DependentSizedArrayType *DepArrayT
9655 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9656 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009657 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009658 AllocType = DepArrayT->getElementType();
9659 }
9660 }
9661 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009662
Douglas Gregora16548e2009-08-11 05:31:07 +00009663 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9664 E->isGlobalNew(),
9665 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009666 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009668 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009669 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009670 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009671 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009672 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009673 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009674}
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregora16548e2009-08-11 05:31:07 +00009676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009678TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009679 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009680 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009681 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009682
Douglas Gregord2d9da02010-02-26 00:38:10 +00009683 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009684 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009685 if (E->getOperatorDelete()) {
9686 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009687 getDerived().TransformDecl(E->getLocStart(),
9688 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009689 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009690 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009692
Douglas Gregora16548e2009-08-11 05:31:07 +00009693 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009694 Operand.get() == E->getArgument() &&
9695 OperatorDelete == E->getOperatorDelete()) {
9696 // Mark any declarations we need as referenced.
9697 // FIXME: instantiation-specific.
9698 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009699 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009700
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009701 if (!E->getArgument()->isTypeDependent()) {
9702 QualType Destroyed = SemaRef.Context.getBaseElementType(
9703 E->getDestroyedType());
9704 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9705 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009706 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009707 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009708 }
9709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009710
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009711 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009712 }
Mike Stump11289f42009-09-09 15:08:12 +00009713
Douglas Gregora16548e2009-08-11 05:31:07 +00009714 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9715 E->isGlobalDelete(),
9716 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009717 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009718}
Mike Stump11289f42009-09-09 15:08:12 +00009719
Douglas Gregora16548e2009-08-11 05:31:07 +00009720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009721ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009722TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009723 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009724 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009725 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009727
John McCallba7bf592010-08-24 05:47:05 +00009728 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009729 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009730 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009731 E->getOperatorLoc(),
9732 E->isArrow()? tok::arrow : tok::period,
9733 ObjectTypePtr,
9734 MayBePseudoDestructor);
9735 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009736 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009737
John McCallba7bf592010-08-24 05:47:05 +00009738 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009739 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9740 if (QualifierLoc) {
9741 QualifierLoc
9742 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9743 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009744 return ExprError();
9745 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009746 CXXScopeSpec SS;
9747 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009748
Douglas Gregor678f90d2010-02-25 01:56:36 +00009749 PseudoDestructorTypeStorage Destroyed;
9750 if (E->getDestroyedTypeInfo()) {
9751 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009752 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009753 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009754 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009755 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009756 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009757 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009758 // We aren't likely to be able to resolve the identifier down to a type
9759 // now anyway, so just retain the identifier.
9760 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9761 E->getDestroyedTypeLoc());
9762 } else {
9763 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009764 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009765 *E->getDestroyedTypeIdentifier(),
9766 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009767 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009768 SS, ObjectTypePtr,
9769 false);
9770 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009771 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009772
Douglas Gregor678f90d2010-02-25 01:56:36 +00009773 Destroyed
9774 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9775 E->getDestroyedTypeLoc());
9776 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009777
Craig Topperc3ec1492014-05-26 06:22:03 +00009778 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009779 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009780 CXXScopeSpec EmptySS;
9781 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009782 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009783 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009784 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009785 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009786
John McCallb268a282010-08-23 23:25:46 +00009787 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009788 E->getOperatorLoc(),
9789 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009790 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009791 ScopeTypeInfo,
9792 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009793 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009794 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009795}
Mike Stump11289f42009-09-09 15:08:12 +00009796
Douglas Gregorad8a3362009-09-04 17:36:40 +00009797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009798ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009799TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009800 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009801 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9802 Sema::LookupOrdinaryName);
9803
9804 // Transform all the decls.
9805 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9806 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009807 NamedDecl *InstD = static_cast<NamedDecl*>(
9808 getDerived().TransformDecl(Old->getNameLoc(),
9809 *I));
John McCall84d87672009-12-10 09:41:52 +00009810 if (!InstD) {
9811 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9812 // This can happen because of dependent hiding.
9813 if (isa<UsingShadowDecl>(*I))
9814 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009815 else {
9816 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009817 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009818 }
John McCall84d87672009-12-10 09:41:52 +00009819 }
John McCalle66edc12009-11-24 19:00:30 +00009820
9821 // Expand using declarations.
9822 if (isa<UsingDecl>(InstD)) {
9823 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009824 for (auto *I : UD->shadows())
9825 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009826 continue;
9827 }
9828
9829 R.addDecl(InstD);
9830 }
9831
9832 // Resolve a kind, but don't do any further analysis. If it's
9833 // ambiguous, the callee needs to deal with it.
9834 R.resolveKind();
9835
9836 // Rebuild the nested-name qualifier, if present.
9837 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009838 if (Old->getQualifierLoc()) {
9839 NestedNameSpecifierLoc QualifierLoc
9840 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9841 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009842 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009843
Douglas Gregor0da1d432011-02-28 20:01:57 +00009844 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009845 }
9846
Douglas Gregor9262f472010-04-27 18:19:34 +00009847 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009848 CXXRecordDecl *NamingClass
9849 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9850 Old->getNameLoc(),
9851 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009852 if (!NamingClass) {
9853 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009854 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009856
Douglas Gregorda7be082010-04-27 16:10:10 +00009857 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009858 }
9859
Abramo Bagnara7945c982012-01-27 09:46:47 +00009860 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9861
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009862 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009863 // it's a normal declaration name or member reference.
9864 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9865 NamedDecl *D = R.getAsSingle<NamedDecl>();
9866 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9867 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9868 // give a good diagnostic.
9869 if (D && D->isCXXInstanceMember()) {
9870 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9871 /*TemplateArgs=*/nullptr,
9872 /*Scope=*/nullptr);
9873 }
9874
John McCalle66edc12009-11-24 19:00:30 +00009875 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009876 }
John McCalle66edc12009-11-24 19:00:30 +00009877
9878 // If we have template arguments, rebuild them, then rebuild the
9879 // templateid expression.
9880 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009881 if (Old->hasExplicitTemplateArgs() &&
9882 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009883 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009884 TransArgs)) {
9885 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009886 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009887 }
John McCalle66edc12009-11-24 19:00:30 +00009888
Abramo Bagnara7945c982012-01-27 09:46:47 +00009889 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009890 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009891}
Mike Stump11289f42009-09-09 15:08:12 +00009892
Douglas Gregora16548e2009-08-11 05:31:07 +00009893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009894ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009895TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9896 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009897 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009898 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9899 TypeSourceInfo *From = E->getArg(I);
9900 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009901 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009902 TypeLocBuilder TLB;
9903 TLB.reserve(FromTL.getFullDataSize());
9904 QualType To = getDerived().TransformType(TLB, FromTL);
9905 if (To.isNull())
9906 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009907
Douglas Gregor29c42f22012-02-24 07:38:34 +00009908 if (To == From->getType())
9909 Args.push_back(From);
9910 else {
9911 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9912 ArgChanged = true;
9913 }
9914 continue;
9915 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009916
Douglas Gregor29c42f22012-02-24 07:38:34 +00009917 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009918
Douglas Gregor29c42f22012-02-24 07:38:34 +00009919 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009920 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009921 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9922 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9923 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009924
Douglas Gregor29c42f22012-02-24 07:38:34 +00009925 // Determine whether the set of unexpanded parameter packs can and should
9926 // be expanded.
9927 bool Expand = true;
9928 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009929 Optional<unsigned> OrigNumExpansions =
9930 ExpansionTL.getTypePtr()->getNumExpansions();
9931 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009932 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9933 PatternTL.getSourceRange(),
9934 Unexpanded,
9935 Expand, RetainExpansion,
9936 NumExpansions))
9937 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009938
Douglas Gregor29c42f22012-02-24 07:38:34 +00009939 if (!Expand) {
9940 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009941 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009942 // expansion.
9943 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009944
Douglas Gregor29c42f22012-02-24 07:38:34 +00009945 TypeLocBuilder TLB;
9946 TLB.reserve(From->getTypeLoc().getFullDataSize());
9947
9948 QualType To = getDerived().TransformType(TLB, PatternTL);
9949 if (To.isNull())
9950 return ExprError();
9951
Chad Rosier1dcde962012-08-08 18:46:20 +00009952 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009953 PatternTL.getSourceRange(),
9954 ExpansionTL.getEllipsisLoc(),
9955 NumExpansions);
9956 if (To.isNull())
9957 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009958
Douglas Gregor29c42f22012-02-24 07:38:34 +00009959 PackExpansionTypeLoc ToExpansionTL
9960 = TLB.push<PackExpansionTypeLoc>(To);
9961 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9962 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9963 continue;
9964 }
9965
9966 // Expand the pack expansion by substituting for each argument in the
9967 // pack(s).
9968 for (unsigned I = 0; I != *NumExpansions; ++I) {
9969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9970 TypeLocBuilder TLB;
9971 TLB.reserve(PatternTL.getFullDataSize());
9972 QualType To = getDerived().TransformType(TLB, PatternTL);
9973 if (To.isNull())
9974 return ExprError();
9975
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009976 if (To->containsUnexpandedParameterPack()) {
9977 To = getDerived().RebuildPackExpansionType(To,
9978 PatternTL.getSourceRange(),
9979 ExpansionTL.getEllipsisLoc(),
9980 NumExpansions);
9981 if (To.isNull())
9982 return ExprError();
9983
9984 PackExpansionTypeLoc ToExpansionTL
9985 = TLB.push<PackExpansionTypeLoc>(To);
9986 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9987 }
9988
Douglas Gregor29c42f22012-02-24 07:38:34 +00009989 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009991
Douglas Gregor29c42f22012-02-24 07:38:34 +00009992 if (!RetainExpansion)
9993 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009994
Douglas Gregor29c42f22012-02-24 07:38:34 +00009995 // If we're supposed to retain a pack expansion, do so by temporarily
9996 // forgetting the partially-substituted parameter pack.
9997 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9998
9999 TypeLocBuilder TLB;
10000 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010001
Douglas Gregor29c42f22012-02-24 07:38:34 +000010002 QualType To = getDerived().TransformType(TLB, PatternTL);
10003 if (To.isNull())
10004 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010005
10006 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010007 PatternTL.getSourceRange(),
10008 ExpansionTL.getEllipsisLoc(),
10009 NumExpansions);
10010 if (To.isNull())
10011 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010012
Douglas Gregor29c42f22012-02-24 07:38:34 +000010013 PackExpansionTypeLoc ToExpansionTL
10014 = TLB.push<PackExpansionTypeLoc>(To);
10015 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10016 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10017 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010018
Douglas Gregor29c42f22012-02-24 07:38:34 +000010019 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010020 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010021
10022 return getDerived().RebuildTypeTrait(E->getTrait(),
10023 E->getLocStart(),
10024 Args,
10025 E->getLocEnd());
10026}
10027
10028template<typename Derived>
10029ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010030TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10031 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10032 if (!T)
10033 return ExprError();
10034
10035 if (!getDerived().AlwaysRebuild() &&
10036 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010037 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010038
10039 ExprResult SubExpr;
10040 {
10041 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10042 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10043 if (SubExpr.isInvalid())
10044 return ExprError();
10045
10046 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010047 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010048 }
10049
10050 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10051 E->getLocStart(),
10052 T,
10053 SubExpr.get(),
10054 E->getLocEnd());
10055}
10056
10057template<typename Derived>
10058ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010059TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10060 ExprResult SubExpr;
10061 {
10062 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10063 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10064 if (SubExpr.isInvalid())
10065 return ExprError();
10066
10067 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010068 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010069 }
10070
10071 return getDerived().RebuildExpressionTrait(
10072 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10073}
10074
Reid Kleckner32506ed2014-06-12 23:03:48 +000010075template <typename Derived>
10076ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10077 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10078 TypeSourceInfo **RecoveryTSI) {
10079 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10080 DRE, AddrTaken, RecoveryTSI);
10081
10082 // Propagate both errors and recovered types, which return ExprEmpty.
10083 if (!NewDRE.isUsable())
10084 return NewDRE;
10085
10086 // We got an expr, wrap it up in parens.
10087 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10088 return PE;
10089 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10090 PE->getRParen());
10091}
10092
10093template <typename Derived>
10094ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10095 DependentScopeDeclRefExpr *E) {
10096 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10097 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010098}
10099
10100template<typename Derived>
10101ExprResult
10102TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10103 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010104 bool IsAddressOfOperand,
10105 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010106 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010107 NestedNameSpecifierLoc QualifierLoc
10108 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10109 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010110 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010111 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010112
John McCall31f82722010-11-12 08:19:04 +000010113 // TODO: If this is a conversion-function-id, verify that the
10114 // destination type name (if present) resolves the same way after
10115 // instantiation as it did in the local scope.
10116
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010117 DeclarationNameInfo NameInfo
10118 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10119 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010120 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010121
John McCalle66edc12009-11-24 19:00:30 +000010122 if (!E->hasExplicitTemplateArgs()) {
10123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010124 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010125 // Note: it is sufficient to compare the Name component of NameInfo:
10126 // if name has not changed, DNLoc has not changed either.
10127 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010128 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010129
Reid Kleckner32506ed2014-06-12 23:03:48 +000010130 return getDerived().RebuildDependentScopeDeclRefExpr(
10131 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10132 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010133 }
John McCall6b51f282009-11-23 01:53:49 +000010134
10135 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010136 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10137 E->getNumTemplateArgs(),
10138 TransArgs))
10139 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010140
Reid Kleckner32506ed2014-06-12 23:03:48 +000010141 return getDerived().RebuildDependentScopeDeclRefExpr(
10142 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10143 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010144}
10145
10146template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010148TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010149 // CXXConstructExprs other than for list-initialization and
10150 // CXXTemporaryObjectExpr are always implicit, so when we have
10151 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010152 if ((E->getNumArgs() == 1 ||
10153 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010154 (!getDerived().DropCallArgument(E->getArg(0))) &&
10155 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010156 return getDerived().TransformExpr(E->getArg(0));
10157
Douglas Gregora16548e2009-08-11 05:31:07 +000010158 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10159
10160 QualType T = getDerived().TransformType(E->getType());
10161 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010162 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010163
10164 CXXConstructorDecl *Constructor
10165 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010166 getDerived().TransformDecl(E->getLocStart(),
10167 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010168 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010170
Douglas Gregora16548e2009-08-11 05:31:07 +000010171 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010172 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010173 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010174 &ArgumentChanged))
10175 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010176
Douglas Gregora16548e2009-08-11 05:31:07 +000010177 if (!getDerived().AlwaysRebuild() &&
10178 T == E->getType() &&
10179 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010180 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010181 // Mark the constructor as referenced.
10182 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010183 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010184 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010185 }
Mike Stump11289f42009-09-09 15:08:12 +000010186
Douglas Gregordb121ba2009-12-14 16:27:04 +000010187 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010188 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010189 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010190 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010191 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010192 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010193 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010194 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010195 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010196}
Mike Stump11289f42009-09-09 15:08:12 +000010197
Richard Smith5179eb72016-06-28 19:03:57 +000010198template<typename Derived>
10199ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10200 CXXInheritedCtorInitExpr *E) {
10201 QualType T = getDerived().TransformType(E->getType());
10202 if (T.isNull())
10203 return ExprError();
10204
10205 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10206 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10207 if (!Constructor)
10208 return ExprError();
10209
10210 if (!getDerived().AlwaysRebuild() &&
10211 T == E->getType() &&
10212 Constructor == E->getConstructor()) {
10213 // Mark the constructor as referenced.
10214 // FIXME: Instantiation-specific
10215 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10216 return E;
10217 }
10218
10219 return getDerived().RebuildCXXInheritedCtorInitExpr(
10220 T, E->getLocation(), Constructor,
10221 E->constructsVBase(), E->inheritedFromVBase());
10222}
10223
Douglas Gregora16548e2009-08-11 05:31:07 +000010224/// \brief Transform a C++ temporary-binding expression.
10225///
Douglas Gregor363b1512009-12-24 18:51:59 +000010226/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10227/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010230TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010231 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010232}
Mike Stump11289f42009-09-09 15:08:12 +000010233
John McCall5d413782010-12-06 08:20:24 +000010234/// \brief Transform a C++ expression that contains cleanups that should
10235/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010236///
John McCall5d413782010-12-06 08:20:24 +000010237/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010238/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010240ExprResult
John McCall5d413782010-12-06 08:20:24 +000010241TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010242 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010243}
Mike Stump11289f42009-09-09 15:08:12 +000010244
Douglas Gregora16548e2009-08-11 05:31:07 +000010245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010246ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010247TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010248 CXXTemporaryObjectExpr *E) {
10249 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10250 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010252
Douglas Gregora16548e2009-08-11 05:31:07 +000010253 CXXConstructorDecl *Constructor
10254 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010255 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010256 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010257 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010259
Douglas Gregora16548e2009-08-11 05:31:07 +000010260 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010261 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010262 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010263 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010264 &ArgumentChanged))
10265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010266
Douglas Gregora16548e2009-08-11 05:31:07 +000010267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010268 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010269 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010270 !ArgumentChanged) {
10271 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010272 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010273 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010274 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010275
Richard Smithd59b8322012-12-19 01:39:02 +000010276 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010277 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10278 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010279 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010280 E->getLocEnd());
10281}
Mike Stump11289f42009-09-09 15:08:12 +000010282
Douglas Gregora16548e2009-08-11 05:31:07 +000010283template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010284ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010285TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010286 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010287 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010288 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010289 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10290 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010291 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010292 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010293 CEnd = E->capture_end();
10294 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010295 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010296 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010297 EnterExpressionEvaluationContext EEEC(getSema(),
10298 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010299 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10300 C->getCapturedVar()->getInit(),
10301 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010302
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010303 if (NewExprInitResult.isInvalid())
10304 return ExprError();
10305 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010306
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010307 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010308 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010309 getSema().buildLambdaInitCaptureInitialization(
10310 C->getLocation(), OldVD->getType()->isReferenceType(),
10311 OldVD->getIdentifier(),
10312 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010313 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010314 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10315 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010316 }
10317
Faisal Vali2cba1332013-10-23 06:44:28 +000010318 // Transform the template parameters, and add them to the current
10319 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010320 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010321 E->getTemplateParameterList());
10322
Richard Smith01014ce2014-11-20 23:53:14 +000010323 // Transform the type of the original lambda's call operator.
10324 // The transformation MUST be done in the CurrentInstantiationScope since
10325 // it introduces a mapping of the original to the newly created
10326 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010327 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010328 {
10329 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10330 FunctionProtoTypeLoc OldCallOpFPTL =
10331 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010332
10333 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010334 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010335 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010336 QualType NewCallOpType = TransformFunctionProtoType(
10337 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010338 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10339 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10340 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010341 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010342 if (NewCallOpType.isNull())
10343 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010344 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10345 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010346 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010347
Richard Smithc38498f2015-04-27 21:27:54 +000010348 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10349 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10350 LSI->GLTemplateParameterList = TPL;
10351
Eli Friedmand564afb2012-09-19 01:18:11 +000010352 // Create the local class that will describe the lambda.
10353 CXXRecordDecl *Class
10354 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010355 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010356 /*KnownDependent=*/false,
10357 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010358 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10359
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010360 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010361 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10362 Class, E->getIntroducerRange(), NewCallOpTSI,
10363 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010364 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10365 E->getCallOperator()->isConstexpr());
10366
Faisal Vali2cba1332013-10-23 06:44:28 +000010367 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010368
Akira Hatanaka402818462016-12-16 21:16:57 +000010369 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10370 I != NumParams; ++I) {
10371 auto *P = NewCallOperator->getParamDecl(I);
10372 if (P->hasUninstantiatedDefaultArg()) {
10373 EnterExpressionEvaluationContext Eval(
10374 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10375 ExprResult R = getDerived().TransformExpr(
10376 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10377 P->setDefaultArg(R.get());
10378 }
10379 }
10380
Faisal Vali2cba1332013-10-23 06:44:28 +000010381 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010382 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010383
Douglas Gregorb4328232012-02-14 00:00:48 +000010384 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010385 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010386 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010387
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010388 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010389 getSema().buildLambdaScope(LSI, NewCallOperator,
10390 E->getIntroducerRange(),
10391 E->getCaptureDefault(),
10392 E->getCaptureDefaultLoc(),
10393 E->hasExplicitParameters(),
10394 E->hasExplicitResultType(),
10395 E->isMutable());
10396
10397 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010398
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010399 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010400 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010401 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010402 CEnd = E->capture_end();
10403 C != CEnd; ++C) {
10404 // When we hit the first implicit capture, tell Sema that we've finished
10405 // the list of explicit captures.
10406 if (!FinishedExplicitCaptures && C->isImplicit()) {
10407 getSema().finishLambdaExplicitCaptures(LSI);
10408 FinishedExplicitCaptures = true;
10409 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010410
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010411 // Capturing 'this' is trivial.
10412 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010413 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10414 /*BuildAndDiagnose*/ true, nullptr,
10415 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010416 continue;
10417 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010418 // Captured expression will be recaptured during captured variables
10419 // rebuilding.
10420 if (C->capturesVLAType())
10421 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010422
Richard Smithba71c082013-05-16 06:20:58 +000010423 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010424 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010425 InitCaptureInfoTy InitExprTypePair =
10426 InitCaptureExprsAndTypes[C - E->capture_begin()];
10427 ExprResult Init = InitExprTypePair.first;
10428 QualType InitQualType = InitExprTypePair.second;
10429 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010430 Invalid = true;
10431 continue;
10432 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010433 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010434 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010435 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10436 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010437 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010438 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010439 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010440 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010441 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010442 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010443 continue;
10444 }
10445
10446 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10447
Douglas Gregor3e308b12012-02-14 19:27:52 +000010448 // Determine the capture kind for Sema.
10449 Sema::TryCaptureKind Kind
10450 = C->isImplicit()? Sema::TryCapture_Implicit
10451 : C->getCaptureKind() == LCK_ByCopy
10452 ? Sema::TryCapture_ExplicitByVal
10453 : Sema::TryCapture_ExplicitByRef;
10454 SourceLocation EllipsisLoc;
10455 if (C->isPackExpansion()) {
10456 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10457 bool ShouldExpand = false;
10458 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010459 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010460 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10461 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010462 Unexpanded,
10463 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010464 NumExpansions)) {
10465 Invalid = true;
10466 continue;
10467 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010468
Douglas Gregor3e308b12012-02-14 19:27:52 +000010469 if (ShouldExpand) {
10470 // The transform has determined that we should perform an expansion;
10471 // transform and capture each of the arguments.
10472 // expansion of the pattern. Do so.
10473 VarDecl *Pack = C->getCapturedVar();
10474 for (unsigned I = 0; I != *NumExpansions; ++I) {
10475 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10476 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010477 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010478 Pack));
10479 if (!CapturedVar) {
10480 Invalid = true;
10481 continue;
10482 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010483
Douglas Gregor3e308b12012-02-14 19:27:52 +000010484 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010485 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10486 }
Richard Smith9467be42014-06-06 17:33:35 +000010487
10488 // FIXME: Retain a pack expansion if RetainExpansion is true.
10489
Douglas Gregor3e308b12012-02-14 19:27:52 +000010490 continue;
10491 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
Douglas Gregor3e308b12012-02-14 19:27:52 +000010493 EllipsisLoc = C->getEllipsisLoc();
10494 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010495
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010496 // Transform the captured variable.
10497 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010498 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010499 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010500 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010501 Invalid = true;
10502 continue;
10503 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010504
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010505 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010506 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10507 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010508 }
10509 if (!FinishedExplicitCaptures)
10510 getSema().finishLambdaExplicitCaptures(LSI);
10511
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010512 // Enter a new evaluation context to insulate the lambda from any
10513 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010514 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010515
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010516 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010517 StmtResult Body =
10518 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10519
10520 // ActOnLambda* will pop the function scope for us.
10521 FuncScopeCleanup.disable();
10522
Douglas Gregorb4328232012-02-14 00:00:48 +000010523 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010524 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010525 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010526 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010527 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010528 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010529
Richard Smithc38498f2015-04-27 21:27:54 +000010530 // Copy the LSI before ActOnFinishFunctionBody removes it.
10531 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10532 // the call operator.
10533 auto LSICopy = *LSI;
10534 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10535 /*IsInstantiation*/ true);
10536 SavedContext.pop();
10537
10538 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10539 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010540}
10541
10542template<typename Derived>
10543ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010544TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010545 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +000010546 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10547 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010549
Douglas Gregora16548e2009-08-11 05:31:07 +000010550 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010551 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010552 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010553 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010554 &ArgumentChanged))
10555 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010556
Douglas Gregora16548e2009-08-11 05:31:07 +000010557 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010558 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010559 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010560 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010561
Douglas Gregora16548e2009-08-11 05:31:07 +000010562 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010563 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010564 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010565 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010566 E->getRParenLoc());
10567}
Mike Stump11289f42009-09-09 15:08:12 +000010568
Douglas Gregora16548e2009-08-11 05:31:07 +000010569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010570ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010571TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010572 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010573 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010574 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010575 Expr *OldBase;
10576 QualType BaseType;
10577 QualType ObjectType;
10578 if (!E->isImplicitAccess()) {
10579 OldBase = E->getBase();
10580 Base = getDerived().TransformExpr(OldBase);
10581 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010582 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010583
John McCall2d74de92009-12-01 22:10:20 +000010584 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010585 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010586 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010587 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010588 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010589 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010590 ObjectTy,
10591 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010592 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010593 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010594
John McCallba7bf592010-08-24 05:47:05 +000010595 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010596 BaseType = ((Expr*) Base.get())->getType();
10597 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010598 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010599 BaseType = getDerived().TransformType(E->getBaseType());
10600 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10601 }
Mike Stump11289f42009-09-09 15:08:12 +000010602
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010603 // Transform the first part of the nested-name-specifier that qualifies
10604 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010605 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010606 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010607 E->getFirstQualifierFoundInScope(),
10608 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010609
Douglas Gregore16af532011-02-28 18:50:33 +000010610 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010611 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010612 QualifierLoc
10613 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10614 ObjectType,
10615 FirstQualifierInScope);
10616 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010617 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010618 }
Mike Stump11289f42009-09-09 15:08:12 +000010619
Abramo Bagnara7945c982012-01-27 09:46:47 +000010620 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10621
John McCall31f82722010-11-12 08:19:04 +000010622 // TODO: If this is a conversion-function-id, verify that the
10623 // destination type name (if present) resolves the same way after
10624 // instantiation as it did in the local scope.
10625
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010626 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010627 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010628 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010630
John McCall2d74de92009-12-01 22:10:20 +000010631 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010632 // This is a reference to a member without an explicitly-specified
10633 // template argument list. Optimize for this common case.
10634 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010635 Base.get() == OldBase &&
10636 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010637 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010638 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010639 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010640 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010641
John McCallb268a282010-08-23 23:25:46 +000010642 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010643 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010644 E->isArrow(),
10645 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010646 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010647 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010648 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010649 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010650 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010651 }
10652
John McCall6b51f282009-11-23 01:53:49 +000010653 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010654 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10655 E->getNumTemplateArgs(),
10656 TransArgs))
10657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010658
John McCallb268a282010-08-23 23:25:46 +000010659 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010660 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010661 E->isArrow(),
10662 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010663 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010664 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010665 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010666 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010667 &TransArgs);
10668}
10669
10670template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010671ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010672TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010673 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010674 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010675 QualType BaseType;
10676 if (!Old->isImplicitAccess()) {
10677 Base = getDerived().TransformExpr(Old->getBase());
10678 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010679 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010680 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010681 Old->isArrow());
10682 if (Base.isInvalid())
10683 return ExprError();
10684 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010685 } else {
10686 BaseType = getDerived().TransformType(Old->getBaseType());
10687 }
John McCall10eae182009-11-30 22:42:35 +000010688
Douglas Gregor0da1d432011-02-28 20:01:57 +000010689 NestedNameSpecifierLoc QualifierLoc;
10690 if (Old->getQualifierLoc()) {
10691 QualifierLoc
10692 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10693 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010694 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010695 }
10696
Abramo Bagnara7945c982012-01-27 09:46:47 +000010697 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10698
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010699 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010700 Sema::LookupOrdinaryName);
10701
10702 // Transform all the decls.
10703 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
10704 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010705 NamedDecl *InstD = static_cast<NamedDecl*>(
10706 getDerived().TransformDecl(Old->getMemberLoc(),
10707 *I));
John McCall84d87672009-12-10 09:41:52 +000010708 if (!InstD) {
10709 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10710 // This can happen because of dependent hiding.
10711 if (isa<UsingShadowDecl>(*I))
10712 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010713 else {
10714 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010715 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +000010716 }
John McCall84d87672009-12-10 09:41:52 +000010717 }
John McCall10eae182009-11-30 22:42:35 +000010718
10719 // Expand using declarations.
10720 if (isa<UsingDecl>(InstD)) {
10721 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +000010722 for (auto *I : UD->shadows())
10723 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +000010724 continue;
10725 }
10726
10727 R.addDecl(InstD);
10728 }
10729
10730 R.resolveKind();
10731
Douglas Gregor9262f472010-04-27 18:19:34 +000010732 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010733 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010734 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010735 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010736 Old->getMemberLoc(),
10737 Old->getNamingClass()));
10738 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010739 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010740
Douglas Gregorda7be082010-04-27 16:10:10 +000010741 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010742 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010743
John McCall10eae182009-11-30 22:42:35 +000010744 TemplateArgumentListInfo TransArgs;
10745 if (Old->hasExplicitTemplateArgs()) {
10746 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10747 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010748 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10749 Old->getNumTemplateArgs(),
10750 TransArgs))
10751 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010752 }
John McCall38836f02010-01-15 08:34:02 +000010753
10754 // FIXME: to do this check properly, we will need to preserve the
10755 // first-qualifier-in-scope here, just in case we had a dependent
10756 // base (and therefore couldn't do the check) and a
10757 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010758 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010759
John McCallb268a282010-08-23 23:25:46 +000010760 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010761 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010762 Old->getOperatorLoc(),
10763 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010764 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010765 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000010766 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000010767 R,
10768 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000010769 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000010770}
10771
10772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010773ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010774TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000010775 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010776 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
10777 if (SubExpr.isInvalid())
10778 return ExprError();
10779
10780 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010781 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010782
10783 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10784}
10785
10786template<typename Derived>
10787ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010788TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010789 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10790 if (Pattern.isInvalid())
10791 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010792
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010793 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010794 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010795
Douglas Gregorb8840002011-01-14 21:20:45 +000010796 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10797 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010798}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010799
10800template<typename Derived>
10801ExprResult
10802TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10803 // If E is not value-dependent, then nothing will change when we transform it.
10804 // Note: This is an instantiation-centric view.
10805 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010806 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010807
Richard Smithd784e682015-09-23 21:41:42 +000010808 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010809
Richard Smithd784e682015-09-23 21:41:42 +000010810 ArrayRef<TemplateArgument> PackArgs;
10811 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010812
Richard Smithd784e682015-09-23 21:41:42 +000010813 // Find the argument list to transform.
10814 if (E->isPartiallySubstituted()) {
10815 PackArgs = E->getPartialArguments();
10816 } else if (E->isValueDependent()) {
10817 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10818 bool ShouldExpand = false;
10819 bool RetainExpansion = false;
10820 Optional<unsigned> NumExpansions;
10821 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10822 Unexpanded,
10823 ShouldExpand, RetainExpansion,
10824 NumExpansions))
10825 return ExprError();
10826
10827 // If we need to expand the pack, build a template argument from it and
10828 // expand that.
10829 if (ShouldExpand) {
10830 auto *Pack = E->getPack();
10831 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10832 ArgStorage = getSema().Context.getPackExpansionType(
10833 getSema().Context.getTypeDeclType(TTPD), None);
10834 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10835 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10836 } else {
10837 auto *VD = cast<ValueDecl>(Pack);
10838 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10839 VK_RValue, E->getPackLoc());
10840 if (DRE.isInvalid())
10841 return ExprError();
10842 ArgStorage = new (getSema().Context) PackExpansionExpr(
10843 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10844 }
10845 PackArgs = ArgStorage;
10846 }
10847 }
10848
10849 // If we're not expanding the pack, just transform the decl.
10850 if (!PackArgs.size()) {
10851 auto *Pack = cast_or_null<NamedDecl>(
10852 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010853 if (!Pack)
10854 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010855 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10856 E->getPackLoc(),
10857 E->getRParenLoc(), None, None);
10858 }
10859
Richard Smithc5452ed2016-10-19 22:18:42 +000010860 // Try to compute the result without performing a partial substitution.
10861 Optional<unsigned> Result = 0;
10862 for (const TemplateArgument &Arg : PackArgs) {
10863 if (!Arg.isPackExpansion()) {
10864 Result = *Result + 1;
10865 continue;
10866 }
10867
10868 TemplateArgumentLoc ArgLoc;
10869 InventTemplateArgumentLoc(Arg, ArgLoc);
10870
10871 // Find the pattern of the pack expansion.
10872 SourceLocation Ellipsis;
10873 Optional<unsigned> OrigNumExpansions;
10874 TemplateArgumentLoc Pattern =
10875 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
10876 OrigNumExpansions);
10877
10878 // Substitute under the pack expansion. Do not expand the pack (yet).
10879 TemplateArgumentLoc OutPattern;
10880 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10881 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
10882 /*Uneval*/ true))
10883 return true;
10884
10885 // See if we can determine the number of arguments from the result.
10886 Optional<unsigned> NumExpansions =
10887 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
10888 if (!NumExpansions) {
10889 // No: we must be in an alias template expansion, and we're going to need
10890 // to actually expand the packs.
10891 Result = None;
10892 break;
10893 }
10894
10895 Result = *Result + *NumExpansions;
10896 }
10897
10898 // Common case: we could determine the number of expansions without
10899 // substituting.
10900 if (Result)
10901 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10902 E->getPackLoc(),
10903 E->getRParenLoc(), *Result, None);
10904
Richard Smithd784e682015-09-23 21:41:42 +000010905 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10906 E->getPackLoc());
10907 {
10908 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10909 typedef TemplateArgumentLocInventIterator<
10910 Derived, const TemplateArgument*> PackLocIterator;
10911 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10912 PackLocIterator(*this, PackArgs.end()),
10913 TransformedPackArgs, /*Uneval*/true))
10914 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010915 }
10916
Richard Smithc5452ed2016-10-19 22:18:42 +000010917 // Check whether we managed to fully-expand the pack.
10918 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000010919 SmallVector<TemplateArgument, 8> Args;
10920 bool PartialSubstitution = false;
10921 for (auto &Loc : TransformedPackArgs.arguments()) {
10922 Args.push_back(Loc.getArgument());
10923 if (Loc.getArgument().isPackExpansion())
10924 PartialSubstitution = true;
10925 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010926
Richard Smithd784e682015-09-23 21:41:42 +000010927 if (PartialSubstitution)
10928 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10929 E->getPackLoc(),
10930 E->getRParenLoc(), None, Args);
10931
10932 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010933 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010934 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010935}
10936
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010937template<typename Derived>
10938ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010939TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10940 SubstNonTypeTemplateParmPackExpr *E) {
10941 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010942 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010943}
10944
10945template<typename Derived>
10946ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010947TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10948 SubstNonTypeTemplateParmExpr *E) {
10949 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010950 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010951}
10952
10953template<typename Derived>
10954ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010955TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10956 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010957 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010958}
10959
10960template<typename Derived>
10961ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010962TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10963 MaterializeTemporaryExpr *E) {
10964 return getDerived().TransformExpr(E->GetTemporaryExpr());
10965}
Chad Rosier1dcde962012-08-08 18:46:20 +000010966
Douglas Gregorfe314812011-06-21 17:03:29 +000010967template<typename Derived>
10968ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010969TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10970 Expr *Pattern = E->getPattern();
10971
10972 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10973 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10974 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10975
10976 // Determine whether the set of unexpanded parameter packs can and should
10977 // be expanded.
10978 bool Expand = true;
10979 bool RetainExpansion = false;
10980 Optional<unsigned> NumExpansions;
10981 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10982 Pattern->getSourceRange(),
10983 Unexpanded,
10984 Expand, RetainExpansion,
10985 NumExpansions))
10986 return true;
10987
10988 if (!Expand) {
10989 // Do not expand any packs here, just transform and rebuild a fold
10990 // expression.
10991 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10992
10993 ExprResult LHS =
10994 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10995 if (LHS.isInvalid())
10996 return true;
10997
10998 ExprResult RHS =
10999 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11000 if (RHS.isInvalid())
11001 return true;
11002
11003 if (!getDerived().AlwaysRebuild() &&
11004 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11005 return E;
11006
11007 return getDerived().RebuildCXXFoldExpr(
11008 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11009 RHS.get(), E->getLocEnd());
11010 }
11011
11012 // The transform has determined that we should perform an elementwise
11013 // expansion of the pattern. Do so.
11014 ExprResult Result = getDerived().TransformExpr(E->getInit());
11015 if (Result.isInvalid())
11016 return true;
11017 bool LeftFold = E->isLeftFold();
11018
11019 // If we're retaining an expansion for a right fold, it is the innermost
11020 // component and takes the init (if any).
11021 if (!LeftFold && RetainExpansion) {
11022 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11023
11024 ExprResult Out = getDerived().TransformExpr(Pattern);
11025 if (Out.isInvalid())
11026 return true;
11027
11028 Result = getDerived().RebuildCXXFoldExpr(
11029 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11030 Result.get(), E->getLocEnd());
11031 if (Result.isInvalid())
11032 return true;
11033 }
11034
11035 for (unsigned I = 0; I != *NumExpansions; ++I) {
11036 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11037 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11038 ExprResult Out = getDerived().TransformExpr(Pattern);
11039 if (Out.isInvalid())
11040 return true;
11041
11042 if (Out.get()->containsUnexpandedParameterPack()) {
11043 // We still have a pack; retain a pack expansion for this slice.
11044 Result = getDerived().RebuildCXXFoldExpr(
11045 E->getLocStart(),
11046 LeftFold ? Result.get() : Out.get(),
11047 E->getOperator(), E->getEllipsisLoc(),
11048 LeftFold ? Out.get() : Result.get(),
11049 E->getLocEnd());
11050 } else if (Result.isUsable()) {
11051 // We've got down to a single element; build a binary operator.
11052 Result = getDerived().RebuildBinaryOperator(
11053 E->getEllipsisLoc(), E->getOperator(),
11054 LeftFold ? Result.get() : Out.get(),
11055 LeftFold ? Out.get() : Result.get());
11056 } else
11057 Result = Out;
11058
11059 if (Result.isInvalid())
11060 return true;
11061 }
11062
11063 // If we're retaining an expansion for a left fold, it is the outermost
11064 // component and takes the complete expansion so far as its init (if any).
11065 if (LeftFold && RetainExpansion) {
11066 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11067
11068 ExprResult Out = getDerived().TransformExpr(Pattern);
11069 if (Out.isInvalid())
11070 return true;
11071
11072 Result = getDerived().RebuildCXXFoldExpr(
11073 E->getLocStart(), Result.get(),
11074 E->getOperator(), E->getEllipsisLoc(),
11075 Out.get(), E->getLocEnd());
11076 if (Result.isInvalid())
11077 return true;
11078 }
11079
11080 // If we had no init and an empty pack, and we're not retaining an expansion,
11081 // then produce a fallback value or error.
11082 if (Result.isUnset())
11083 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11084 E->getOperator());
11085
11086 return Result;
11087}
11088
11089template<typename Derived>
11090ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011091TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11092 CXXStdInitializerListExpr *E) {
11093 return getDerived().TransformExpr(E->getSubExpr());
11094}
11095
11096template<typename Derived>
11097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011098TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011099 return SemaRef.MaybeBindToTemporary(E);
11100}
11101
11102template<typename Derived>
11103ExprResult
11104TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011105 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011106}
11107
11108template<typename Derived>
11109ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011110TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11111 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11112 if (SubExpr.isInvalid())
11113 return ExprError();
11114
11115 if (!getDerived().AlwaysRebuild() &&
11116 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011117 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011118
11119 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011120}
11121
11122template<typename Derived>
11123ExprResult
11124TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11125 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011126 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011127 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011128 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011129 /*IsCall=*/false, Elements, &ArgChanged))
11130 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011131
Ted Kremeneke65b0862012-03-06 20:05:56 +000011132 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11133 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011134
Ted Kremeneke65b0862012-03-06 20:05:56 +000011135 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11136 Elements.data(),
11137 Elements.size());
11138}
11139
11140template<typename Derived>
11141ExprResult
11142TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011143 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011144 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011145 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011146 bool ArgChanged = false;
11147 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11148 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011149
Ted Kremeneke65b0862012-03-06 20:05:56 +000011150 if (OrigElement.isPackExpansion()) {
11151 // This key/value element is a pack expansion.
11152 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11153 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11154 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11155 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11156
11157 // Determine whether the set of unexpanded parameter packs can
11158 // and should be expanded.
11159 bool Expand = true;
11160 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011161 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11162 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011163 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11164 OrigElement.Value->getLocEnd());
11165 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11166 PatternRange,
11167 Unexpanded,
11168 Expand, RetainExpansion,
11169 NumExpansions))
11170 return ExprError();
11171
11172 if (!Expand) {
11173 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011174 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011175 // expansion.
11176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11177 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11178 if (Key.isInvalid())
11179 return ExprError();
11180
11181 if (Key.get() != OrigElement.Key)
11182 ArgChanged = true;
11183
11184 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11185 if (Value.isInvalid())
11186 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011187
Ted Kremeneke65b0862012-03-06 20:05:56 +000011188 if (Value.get() != OrigElement.Value)
11189 ArgChanged = true;
11190
Chad Rosier1dcde962012-08-08 18:46:20 +000011191 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011192 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11193 };
11194 Elements.push_back(Expansion);
11195 continue;
11196 }
11197
11198 // Record right away that the argument was changed. This needs
11199 // to happen even if the array expands to nothing.
11200 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011201
Ted Kremeneke65b0862012-03-06 20:05:56 +000011202 // The transform has determined that we should perform an elementwise
11203 // expansion of the pattern. Do so.
11204 for (unsigned I = 0; I != *NumExpansions; ++I) {
11205 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11206 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11207 if (Key.isInvalid())
11208 return ExprError();
11209
11210 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11211 if (Value.isInvalid())
11212 return ExprError();
11213
Chad Rosier1dcde962012-08-08 18:46:20 +000011214 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011215 Key.get(), Value.get(), SourceLocation(), NumExpansions
11216 };
11217
11218 // If any unexpanded parameter packs remain, we still have a
11219 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011220 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011221 if (Key.get()->containsUnexpandedParameterPack() ||
11222 Value.get()->containsUnexpandedParameterPack())
11223 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011224
Ted Kremeneke65b0862012-03-06 20:05:56 +000011225 Elements.push_back(Element);
11226 }
11227
Richard Smith9467be42014-06-06 17:33:35 +000011228 // FIXME: Retain a pack expansion if RetainExpansion is true.
11229
Ted Kremeneke65b0862012-03-06 20:05:56 +000011230 // We've finished with this pack expansion.
11231 continue;
11232 }
11233
11234 // Transform and check key.
11235 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11236 if (Key.isInvalid())
11237 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011238
Ted Kremeneke65b0862012-03-06 20:05:56 +000011239 if (Key.get() != OrigElement.Key)
11240 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011241
Ted Kremeneke65b0862012-03-06 20:05:56 +000011242 // Transform and check value.
11243 ExprResult Value
11244 = getDerived().TransformExpr(OrigElement.Value);
11245 if (Value.isInvalid())
11246 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011247
Ted Kremeneke65b0862012-03-06 20:05:56 +000011248 if (Value.get() != OrigElement.Value)
11249 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011250
11251 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011252 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011253 };
11254 Elements.push_back(Element);
11255 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011256
Ted Kremeneke65b0862012-03-06 20:05:56 +000011257 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11258 return SemaRef.MaybeBindToTemporary(E);
11259
11260 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011261 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011262}
11263
Mike Stump11289f42009-09-09 15:08:12 +000011264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011266TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011267 TypeSourceInfo *EncodedTypeInfo
11268 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11269 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011271
Douglas Gregora16548e2009-08-11 05:31:07 +000011272 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011273 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011274 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011275
11276 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011277 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011278 E->getRParenLoc());
11279}
Mike Stump11289f42009-09-09 15:08:12 +000011280
Douglas Gregora16548e2009-08-11 05:31:07 +000011281template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011282ExprResult TreeTransform<Derived>::
11283TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011284 // This is a kind of implicit conversion, and it needs to get dropped
11285 // and recomputed for the same general reasons that ImplicitCastExprs
11286 // do, as well a more specific one: this expression is only valid when
11287 // it appears *immediately* as an argument expression.
11288 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011289}
11290
11291template<typename Derived>
11292ExprResult TreeTransform<Derived>::
11293TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011294 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011295 = getDerived().TransformType(E->getTypeInfoAsWritten());
11296 if (!TSInfo)
11297 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011298
John McCall31168b02011-06-15 23:02:42 +000011299 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011300 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011301 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011302
John McCall31168b02011-06-15 23:02:42 +000011303 if (!getDerived().AlwaysRebuild() &&
11304 TSInfo == E->getTypeInfoAsWritten() &&
11305 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011306 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011307
John McCall31168b02011-06-15 23:02:42 +000011308 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011309 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011310 Result.get());
11311}
11312
Erik Pilkington29099de2016-07-16 00:35:23 +000011313template <typename Derived>
11314ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11315 ObjCAvailabilityCheckExpr *E) {
11316 return E;
11317}
11318
John McCall31168b02011-06-15 23:02:42 +000011319template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011320ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011321TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011322 // Transform arguments.
11323 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011324 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011325 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011326 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011327 &ArgChanged))
11328 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011329
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011330 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11331 // Class message: transform the receiver type.
11332 TypeSourceInfo *ReceiverTypeInfo
11333 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11334 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011335 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011336
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011337 // If nothing changed, just retain the existing message send.
11338 if (!getDerived().AlwaysRebuild() &&
11339 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011340 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011341
11342 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011343 SmallVector<SourceLocation, 16> SelLocs;
11344 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011345 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11346 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011347 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011348 E->getMethodDecl(),
11349 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011350 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011351 E->getRightLoc());
11352 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011353 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11354 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011355 if (!E->getMethodDecl())
11356 return ExprError();
11357
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011358 // Build a new class message send to 'super'.
11359 SmallVector<SourceLocation, 16> SelLocs;
11360 E->getSelectorLocs(SelLocs);
11361 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11362 E->getSelector(),
11363 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011364 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011365 E->getMethodDecl(),
11366 E->getLeftLoc(),
11367 Args,
11368 E->getRightLoc());
11369 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011370
11371 // Instance message: transform the receiver
11372 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11373 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011374 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011375 = getDerived().TransformExpr(E->getInstanceReceiver());
11376 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011377 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011378
11379 // If nothing changed, just retain the existing message send.
11380 if (!getDerived().AlwaysRebuild() &&
11381 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011382 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011383
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011384 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011385 SmallVector<SourceLocation, 16> SelLocs;
11386 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011387 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011388 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011389 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011390 E->getMethodDecl(),
11391 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011392 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011393 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011394}
11395
Mike Stump11289f42009-09-09 15:08:12 +000011396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011398TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011399 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011400}
11401
Mike Stump11289f42009-09-09 15:08:12 +000011402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011403ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011404TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011405 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011406}
11407
Mike Stump11289f42009-09-09 15:08:12 +000011408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011410TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011411 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011412 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011413 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011414 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011415
11416 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011417
Douglas Gregord51d90d2010-04-26 20:11:03 +000011418 // If nothing changed, just retain the existing expression.
11419 if (!getDerived().AlwaysRebuild() &&
11420 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011421 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011422
John McCallb268a282010-08-23 23:25:46 +000011423 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011424 E->getLocation(),
11425 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011426}
11427
Mike Stump11289f42009-09-09 15:08:12 +000011428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011430TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011431 // 'super' and types never change. Property never changes. Just
11432 // retain the existing expression.
11433 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011434 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011435
Douglas Gregor9faee212010-04-26 20:47:02 +000011436 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011437 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011438 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011439 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011440
Douglas Gregor9faee212010-04-26 20:47:02 +000011441 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011442
Douglas Gregor9faee212010-04-26 20:47:02 +000011443 // If nothing changed, just retain the existing expression.
11444 if (!getDerived().AlwaysRebuild() &&
11445 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011446 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011447
John McCallb7bd14f2010-12-02 01:19:52 +000011448 if (E->isExplicitProperty())
11449 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11450 E->getExplicitProperty(),
11451 E->getLocation());
11452
11453 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011454 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011455 E->getImplicitPropertyGetter(),
11456 E->getImplicitPropertySetter(),
11457 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011458}
11459
Mike Stump11289f42009-09-09 15:08:12 +000011460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011461ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011462TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11463 // Transform the base expression.
11464 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11465 if (Base.isInvalid())
11466 return ExprError();
11467
11468 // Transform the key expression.
11469 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11470 if (Key.isInvalid())
11471 return ExprError();
11472
11473 // If nothing changed, just retain the existing expression.
11474 if (!getDerived().AlwaysRebuild() &&
11475 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011476 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011477
Chad Rosier1dcde962012-08-08 18:46:20 +000011478 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011479 Base.get(), Key.get(),
11480 E->getAtIndexMethodDecl(),
11481 E->setAtIndexMethodDecl());
11482}
11483
11484template<typename Derived>
11485ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011486TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011487 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011488 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011489 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011490 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011491
Douglas Gregord51d90d2010-04-26 20:11:03 +000011492 // If nothing changed, just retain the existing expression.
11493 if (!getDerived().AlwaysRebuild() &&
11494 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011495 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011496
John McCallb268a282010-08-23 23:25:46 +000011497 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011498 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011499 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011500}
11501
Mike Stump11289f42009-09-09 15:08:12 +000011502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011504TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011505 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011506 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011507 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011508 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011509 SubExprs, &ArgumentChanged))
11510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011511
Douglas Gregora16548e2009-08-11 05:31:07 +000011512 if (!getDerived().AlwaysRebuild() &&
11513 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011514 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011515
Douglas Gregora16548e2009-08-11 05:31:07 +000011516 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011517 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011518 E->getRParenLoc());
11519}
11520
Mike Stump11289f42009-09-09 15:08:12 +000011521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011522ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011523TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11524 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11525 if (SrcExpr.isInvalid())
11526 return ExprError();
11527
11528 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11529 if (!Type)
11530 return ExprError();
11531
11532 if (!getDerived().AlwaysRebuild() &&
11533 Type == E->getTypeSourceInfo() &&
11534 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011535 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011536
11537 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11538 SrcExpr.get(), Type,
11539 E->getRParenLoc());
11540}
11541
11542template<typename Derived>
11543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011544TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011545 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011546
Craig Topperc3ec1492014-05-26 06:22:03 +000011547 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011548 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11549
11550 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011551 blockScope->TheDecl->setBlockMissingReturnType(
11552 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011553
Chris Lattner01cf8db2011-07-20 06:58:45 +000011554 SmallVector<ParmVarDecl*, 4> params;
11555 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011556
John McCallc8e321d2016-03-01 02:09:25 +000011557 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11558
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011559 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011560 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011561 if (getDerived().TransformFunctionTypeParams(
11562 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11563 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11564 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011565 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011566 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011567 }
John McCall490112f2011-02-04 18:33:18 +000011568
Eli Friedman34b49062012-01-26 03:00:14 +000011569 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011570 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011571
John McCallc8e321d2016-03-01 02:09:25 +000011572 auto epi = exprFunctionType->getExtProtoInfo();
11573 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11574
Jordan Rose5c382722013-03-08 21:51:21 +000011575 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011576 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011577 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011578
11579 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011580 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011581 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011582
11583 if (!oldBlock->blockMissingReturnType()) {
11584 blockScope->HasImplicitReturnType = false;
11585 blockScope->ReturnType = exprResultType;
11586 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011587
John McCall3882ace2011-01-05 12:14:39 +000011588 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011589 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011590 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011591 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011592 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011593 }
John McCall3882ace2011-01-05 12:14:39 +000011594
John McCall490112f2011-02-04 18:33:18 +000011595#ifndef NDEBUG
11596 // In builds with assertions, make sure that we captured everything we
11597 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011598 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011599 for (const auto &I : oldBlock->captures()) {
11600 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011601
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011602 // Ignore parameter packs.
11603 if (isa<ParmVarDecl>(oldCapture) &&
11604 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11605 continue;
John McCall490112f2011-02-04 18:33:18 +000011606
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011607 VarDecl *newCapture =
11608 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11609 oldCapture));
11610 assert(blockScope->CaptureMap.count(newCapture));
11611 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011612 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011613 }
11614#endif
11615
11616 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011617 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011618}
11619
Mike Stump11289f42009-09-09 15:08:12 +000011620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011621ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011622TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011623 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011624}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011625
11626template<typename Derived>
11627ExprResult
11628TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011629 QualType RetTy = getDerived().TransformType(E->getType());
11630 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011631 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011632 SubExprs.reserve(E->getNumSubExprs());
11633 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11634 SubExprs, &ArgumentChanged))
11635 return ExprError();
11636
11637 if (!getDerived().AlwaysRebuild() &&
11638 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011639 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011640
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011641 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011642 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011643}
Chad Rosier1dcde962012-08-08 18:46:20 +000011644
Douglas Gregora16548e2009-08-11 05:31:07 +000011645//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011646// Type reconstruction
11647//===----------------------------------------------------------------------===//
11648
Mike Stump11289f42009-09-09 15:08:12 +000011649template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011650QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11651 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011652 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011653 getDerived().getBaseEntity());
11654}
11655
Mike Stump11289f42009-09-09 15:08:12 +000011656template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011657QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11658 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011659 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011660 getDerived().getBaseEntity());
11661}
11662
Mike Stump11289f42009-09-09 15:08:12 +000011663template<typename Derived>
11664QualType
John McCall70dd5f62009-10-30 00:06:24 +000011665TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11666 bool WrittenAsLValue,
11667 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011668 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011669 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011670}
11671
11672template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011673QualType
John McCall70dd5f62009-10-30 00:06:24 +000011674TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11675 QualType ClassType,
11676 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011677 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11678 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011679}
11680
11681template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011682QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11683 const ObjCTypeParamDecl *Decl,
11684 SourceLocation ProtocolLAngleLoc,
11685 ArrayRef<ObjCProtocolDecl *> Protocols,
11686 ArrayRef<SourceLocation> ProtocolLocs,
11687 SourceLocation ProtocolRAngleLoc) {
11688 return SemaRef.BuildObjCTypeParamType(Decl,
11689 ProtocolLAngleLoc, Protocols,
11690 ProtocolLocs, ProtocolRAngleLoc,
11691 /*FailOnError=*/true);
11692}
11693
11694template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011695QualType TreeTransform<Derived>::RebuildObjCObjectType(
11696 QualType BaseType,
11697 SourceLocation Loc,
11698 SourceLocation TypeArgsLAngleLoc,
11699 ArrayRef<TypeSourceInfo *> TypeArgs,
11700 SourceLocation TypeArgsRAngleLoc,
11701 SourceLocation ProtocolLAngleLoc,
11702 ArrayRef<ObjCProtocolDecl *> Protocols,
11703 ArrayRef<SourceLocation> ProtocolLocs,
11704 SourceLocation ProtocolRAngleLoc) {
11705 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11706 TypeArgs, TypeArgsRAngleLoc,
11707 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11708 ProtocolRAngleLoc,
11709 /*FailOnError=*/true);
11710}
11711
11712template<typename Derived>
11713QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11714 QualType PointeeType,
11715 SourceLocation Star) {
11716 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11717}
11718
11719template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011720QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011721TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11722 ArrayType::ArraySizeModifier SizeMod,
11723 const llvm::APInt *Size,
11724 Expr *SizeExpr,
11725 unsigned IndexTypeQuals,
11726 SourceRange BracketsRange) {
11727 if (SizeExpr || !Size)
11728 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11729 IndexTypeQuals, BracketsRange,
11730 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011731
11732 QualType Types[] = {
11733 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11734 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11735 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011736 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011737 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011738 QualType SizeType;
11739 for (unsigned I = 0; I != NumTypes; ++I)
11740 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11741 SizeType = Types[I];
11742 break;
11743 }
Mike Stump11289f42009-09-09 15:08:12 +000011744
Eli Friedman9562f392012-01-25 23:20:27 +000011745 // Note that we can return a VariableArrayType here in the case where
11746 // the element type was a dependent VariableArrayType.
11747 IntegerLiteral *ArraySize
11748 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11749 /*FIXME*/BracketsRange.getBegin());
11750 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011751 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011752 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011753}
Mike Stump11289f42009-09-09 15:08:12 +000011754
Douglas Gregord6ff3322009-08-04 16:50:30 +000011755template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011756QualType
11757TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011758 ArrayType::ArraySizeModifier SizeMod,
11759 const llvm::APInt &Size,
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, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011763 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011764}
11765
11766template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011767QualType
Mike Stump11289f42009-09-09 15:08:12 +000011768TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011769 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000011770 unsigned IndexTypeQuals,
11771 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011772 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011773 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011774}
Mike Stump11289f42009-09-09 15:08:12 +000011775
Douglas Gregord6ff3322009-08-04 16:50:30 +000011776template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011777QualType
11778TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011779 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011780 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011781 unsigned IndexTypeQuals,
11782 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011783 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011784 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011785 IndexTypeQuals, BracketsRange);
11786}
11787
11788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011789QualType
11790TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011791 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000011792 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011793 unsigned IndexTypeQuals,
11794 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011795 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000011796 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011797 IndexTypeQuals, BracketsRange);
11798}
11799
11800template<typename Derived>
11801QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000011802 unsigned NumElements,
11803 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000011804 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000011805 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011806}
Mike Stump11289f42009-09-09 15:08:12 +000011807
Douglas Gregord6ff3322009-08-04 16:50:30 +000011808template<typename Derived>
11809QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
11810 unsigned NumElements,
11811 SourceLocation AttributeLoc) {
11812 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
11813 NumElements, true);
11814 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000011815 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
11816 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000011817 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011818}
Mike Stump11289f42009-09-09 15:08:12 +000011819
Douglas Gregord6ff3322009-08-04 16:50:30 +000011820template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011821QualType
11822TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000011823 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011824 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000011825 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011826}
Mike Stump11289f42009-09-09 15:08:12 +000011827
Douglas Gregord6ff3322009-08-04 16:50:30 +000011828template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000011829QualType TreeTransform<Derived>::RebuildFunctionProtoType(
11830 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000011831 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000011832 const FunctionProtoType::ExtProtoInfo &EPI) {
11833 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011834 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000011835 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000011836 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011837}
Mike Stump11289f42009-09-09 15:08:12 +000011838
Douglas Gregord6ff3322009-08-04 16:50:30 +000011839template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000011840QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
11841 return SemaRef.Context.getFunctionNoProtoType(T);
11842}
11843
11844template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000011845QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
11846 assert(D && "no decl found");
11847 if (D->isInvalidDecl()) return QualType();
11848
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011849 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011850 TypeDecl *Ty;
11851 if (isa<UsingDecl>(D)) {
11852 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011853 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011854 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11855
11856 // A valid resolved using typename decl points to exactly one type decl.
11857 assert(++Using->shadow_begin() == Using->shadow_end());
11858 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011859
John McCallb96ec562009-12-04 22:46:56 +000011860 } else {
11861 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11862 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11863 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11864 }
11865
11866 return SemaRef.Context.getTypeDeclType(Ty);
11867}
11868
11869template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011870QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11871 SourceLocation Loc) {
11872 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011873}
11874
11875template<typename Derived>
11876QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11877 return SemaRef.Context.getTypeOfType(Underlying);
11878}
11879
11880template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011881QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11882 SourceLocation Loc) {
11883 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011884}
11885
11886template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011887QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11888 UnaryTransformType::UTTKind UKind,
11889 SourceLocation Loc) {
11890 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11891}
11892
11893template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011894QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011895 TemplateName Template,
11896 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011897 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011898 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011899}
Mike Stump11289f42009-09-09 15:08:12 +000011900
Douglas Gregor1135c352009-08-06 05:28:30 +000011901template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011902QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11903 SourceLocation KWLoc) {
11904 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11905}
11906
11907template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000011908QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000011909 SourceLocation KWLoc,
11910 bool isReadPipe) {
11911 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
11912 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000011913}
11914
11915template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011916TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011917TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011918 bool TemplateKW,
11919 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011920 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011921 Template);
11922}
11923
11924template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011925TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011926TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11927 const IdentifierInfo &Name,
11928 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011929 QualType ObjectType,
11930 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011931 UnqualifiedId TemplateName;
11932 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011933 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011934 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011935 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011936 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011937 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011938 /*EnteringContext=*/false,
11939 Template);
John McCall31f82722010-11-12 08:19:04 +000011940 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011941}
Mike Stump11289f42009-09-09 15:08:12 +000011942
Douglas Gregora16548e2009-08-11 05:31:07 +000011943template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011944TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011945TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011946 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011947 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011948 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011949 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011950 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011951 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011952 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011953 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011954 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011955 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011956 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011957 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011958 /*EnteringContext=*/false,
11959 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011960 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011961}
Chad Rosier1dcde962012-08-08 18:46:20 +000011962
Douglas Gregor71395fa2009-11-04 00:56:37 +000011963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011964ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011965TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11966 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011967 Expr *OrigCallee,
11968 Expr *First,
11969 Expr *Second) {
11970 Expr *Callee = OrigCallee->IgnoreParenCasts();
11971 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011972
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011973 if (First->getObjectKind() == OK_ObjCProperty) {
11974 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11975 if (BinaryOperator::isAssignmentOp(Opc))
11976 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11977 First, Second);
11978 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11979 if (Result.isInvalid())
11980 return ExprError();
11981 First = Result.get();
11982 }
11983
11984 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11985 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11986 if (Result.isInvalid())
11987 return ExprError();
11988 Second = Result.get();
11989 }
11990
Douglas Gregora16548e2009-08-11 05:31:07 +000011991 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011992 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011993 if (!First->getType()->isOverloadableType() &&
11994 !Second->getType()->isOverloadableType())
11995 return getSema().CreateBuiltinArraySubscriptExpr(First,
11996 Callee->getLocStart(),
11997 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011998 } else if (Op == OO_Arrow) {
11999 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012000 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12001 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012002 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012003 // The argument is not of overloadable type, so try to create a
12004 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012005 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012006 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012007
John McCallb268a282010-08-23 23:25:46 +000012008 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012009 }
12010 } else {
John McCallb268a282010-08-23 23:25:46 +000012011 if (!First->getType()->isOverloadableType() &&
12012 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012013 // Neither of the arguments is an overloadable type, so try to
12014 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012015 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012016 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012017 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012018 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012020
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012021 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012022 }
12023 }
Mike Stump11289f42009-09-09 15:08:12 +000012024
12025 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012026 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012027 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012028
John McCallb268a282010-08-23 23:25:46 +000012029 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012030 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012031 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012032 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012033 // If we've resolved this to a particular non-member function, just call
12034 // that function. If we resolved it to a member function,
12035 // CreateOverloaded* will find that function for us.
12036 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12037 if (!isa<CXXMethodDecl>(ND))
12038 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012039 }
Mike Stump11289f42009-09-09 15:08:12 +000012040
Douglas Gregora16548e2009-08-11 05:31:07 +000012041 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012042 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012043 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012044
Douglas Gregora16548e2009-08-11 05:31:07 +000012045 // Create the overloaded operator invocation for unary operators.
12046 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012047 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012048 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012049 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012050 }
Mike Stump11289f42009-09-09 15:08:12 +000012051
Douglas Gregore9d62932011-07-15 16:25:15 +000012052 if (Op == OO_Subscript) {
12053 SourceLocation LBrace;
12054 SourceLocation RBrace;
12055
12056 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012057 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012058 LBrace = SourceLocation::getFromRawEncoding(
12059 NameLoc.CXXOperatorName.BeginOpNameLoc);
12060 RBrace = SourceLocation::getFromRawEncoding(
12061 NameLoc.CXXOperatorName.EndOpNameLoc);
12062 } else {
12063 LBrace = Callee->getLocStart();
12064 RBrace = OpLoc;
12065 }
12066
12067 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12068 First, Second);
12069 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012070
Douglas Gregora16548e2009-08-11 05:31:07 +000012071 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012072 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012073 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012074 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12075 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012077
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012078 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012079}
Mike Stump11289f42009-09-09 15:08:12 +000012080
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012081template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012082ExprResult
John McCallb268a282010-08-23 23:25:46 +000012083TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012084 SourceLocation OperatorLoc,
12085 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012086 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012087 TypeSourceInfo *ScopeType,
12088 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012089 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012090 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012091 QualType BaseType = Base->getType();
12092 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012093 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012094 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012095 !BaseType->getAs<PointerType>()->getPointeeType()
12096 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012097 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012098 return SemaRef.BuildPseudoDestructorExpr(
12099 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12100 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012101 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012102
Douglas Gregor678f90d2010-02-25 01:56:36 +000012103 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012104 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12105 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12106 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12107 NameInfo.setNamedTypeInfo(DestroyedType);
12108
Richard Smith8e4a3862012-05-15 06:15:11 +000012109 // The scope type is now known to be a valid nested name specifier
12110 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012111 if (ScopeType) {
12112 if (!ScopeType->getType()->getAs<TagType>()) {
12113 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12114 diag::err_expected_class_or_namespace)
12115 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12116 return ExprError();
12117 }
12118 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12119 CCLoc);
12120 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012121
Abramo Bagnara7945c982012-01-27 09:46:47 +000012122 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012123 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012124 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012125 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012126 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012127 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012128 /*TemplateArgs*/ nullptr,
12129 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012130}
12131
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012132template<typename Derived>
12133StmtResult
12134TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012135 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012136 CapturedDecl *CD = S->getCapturedDecl();
12137 unsigned NumParams = CD->getNumParams();
12138 unsigned ContextParamPos = CD->getContextParamPosition();
12139 SmallVector<Sema::CapturedParamNameType, 4> Params;
12140 for (unsigned I = 0; I < NumParams; ++I) {
12141 if (I != ContextParamPos) {
12142 Params.push_back(
12143 std::make_pair(
12144 CD->getParam(I)->getName(),
12145 getDerived().TransformType(CD->getParam(I)->getType())));
12146 } else {
12147 Params.push_back(std::make_pair(StringRef(), QualType()));
12148 }
12149 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012150 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012151 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012152 StmtResult Body;
12153 {
12154 Sema::CompoundScopeRAII CompoundScope(getSema());
12155 Body = getDerived().TransformStmt(S->getCapturedStmt());
12156 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012157
12158 if (Body.isInvalid()) {
12159 getSema().ActOnCapturedRegionError();
12160 return StmtError();
12161 }
12162
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012163 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012164}
12165
Douglas Gregord6ff3322009-08-04 16:50:30 +000012166} // end namespace clang
12167
Hans Wennborg59dbe862015-09-29 20:56:43 +000012168#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H